Do not use it any more. Please refer to socket.io.client.biz instead
Project based high level abstraction of SSP.
sock-client-stomp
is made for domain specific business scenarios. It consists of following features:
- re-connect
- authentication by token
- project based, let's say you are working on a SaaS platform, several projects may watch for SSP individually
- easy to subscribe messages for current user
- easy to subscribe broadcast messages
- no need to worry about re-subscribe process whenever re-connect triggered
yarn add sock-client-stomp
npm install --save sock-client-stomp
import { SockClient } from 'sock-client-stomp'
const { SockClient } = require('sock-client-stomp')
import { SockClient } from 'sock-client-stomp'
const socket = new SockClient({
base: 'http://demo.ssp.com/msg-center/websocket',
token: 'your token for authentication',
projectId: 'project you are going to watch',
// set to false to disable reconnect feature
reconnect: {
timeout: 30 * 1000
}
})
// watch every connection state change
socket.onStateChange(state => {
console.log('state changed to', state)
})
// subscribe broadcast info
socket.subscribeBroadcast('topic your are going to watch', arg => {
console.log(arg)
})
// connect
socket.connect()