ReactNativeMultithreadSocket
ReactNativeMultithreadSocket is a module that provides a multithreaded WebSocket for React Native applications. It allows you to connect, disconnect, send messages, and listen for messages on a WebSocket in a separate thread.
Still in development, not ready for production use. it will be live soon
Installation
To install the module, you can use npm or yarn:
npm install react-native-multithread-socket
or
yarn add react-native-multithread-socket
Usage
Here is a basic example of how to use the module:
import MultithreadSocket from 'react-native-multithread-socket';
MultithreadSocket.connect(url, delayDuration, mode)
.then(response => console.log(response))
.catch(error => console.error(error));
MultithreadSocket.disconnect()
.then(response => console.log(response))
.catch(error => console.error(error));
MultithreadSocket.send(message)
.then(response => console.log(response))
.catch(error => console.error(error));
MultithreadSocket.onOpen(event => {
console.log('WebSocket connection opened:', event);
});
MultithreadSocket.onMessage(event => {
console.log('Message received:', event);
});
// To remove event listener
MultithreadSocket.removeOnOpen(callback);
MultithreadSocket.removeOnMessage(callback);
for ios please add this code in your podfile
# Podfile
target 'YourApp' do
# Other dependencies...
pod 'SocketRocket'
# Rest of your dependencies...
end
For more detailed usage, please refer to the example project in the repository.