react-stompjs
React websocket High Order Component with @stomp/stompjs (V5) over SockJS
Introduction
I need an updated STOMP client to work with latest version of React Native, it probably works in Browser as well.
It exposed the global STOMP client to the react components with HOC
It makes use of the great @stomp/stompjs for STOMP, check it's doc on how to use the Client
Installation
npm install react-stompjs --save
Usage
Import
Connect your component withStomp(), it'll add stompContext into your component properties
Now you can listen / remove the Stomp Events, ( check EventEmitter3 for emitted, context )
const StompEventTypes = Connect: 0 Disconnect: 1 Error: 2 WebSocketClose: 3 WebSocketError: 4 thispropsstompContext
And create/destroy the client
thispropsstompContextthispropsstompContext
You could access the Client directly ( Subscribe and unsubscribe etc )
let rootSubscribed = thispropsstompContextrootSubscribed
Example ( React-Native )
{ superprops thisstate = status: 'Not Connected' } : void thispropsstompContext thispropsstompContext thispropsstompContext thispropsstompContext // it's '/' most likely { return <View style=flex: 1 justifyContent: 'center' alignItems: 'center' backgroundColor: '#ffffff'> <View><Text>Status: thisstatestatus</Text></View> </View> } App