react-native-websocket
WebSocket API wrapped as a component for React Native
Table of Contents
About
If you're interested in using websockets in React Native generally here is a slightly abbreviated version of the source of this component:
//... thisstatews { thisreconnect = !!thispropsreconnect this } { thisreconnect = false thisstatews } { const ws = thispropsurl ws { thispropsonOpen && thisprops } ws { thispropsonMessage && thisprops } ws { thispropsonError && thisprops } ws thisreconnect ? this : thispropsonClose && thisprops this }
As you can see the component simply wraps the native websocket api. It's also recommended that you implement your own exponential backoff reconnect logic if you plan on using this component in production.
Install
$ npm install --save react-native-websocket# OR $ yarn add react-native-websocket
Usage
import React Component from 'react'import AppRegistry View from 'react-native'import WS from 'react-native-websocket' { return <View => <WS = ="wss://echo.websocket.org/" = = = = // /> </View> }
Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
License
Licensed under the MIT License.