DFocus wanted ssp solution - javascript-client.
socket.io.client.biz
is made for domain specific business scenarios. It consists of following features:
- re-connect
- authentication via token
- project based, let's say you are working on a SaaS platform, several projects may subscribe topics individually
- easy to distinguish events from topics
- no need to worry about re-subscribe process whenever re-connect triggered
Currently, you can only use socket.io.client.biz
from the source, just copy dist
folder into your repo.
import { SocketIoClientBiz } from 'socket.io.client.biz'
const { SocketIoClientBiz } = require('socket.io.client.biz')
import { SocketIoClientBiz } from 'socket.io.client.biz'
const bizClient = new SocketIoClientBiz({
base: 'http://demo.ssp.com',
token: 'your token for authentication',
projectId: 'project you are going to watch',
// set to false to disable reconnect feature
reconnect: {
reconnection: true,
reconnectionDelay: 20000
}
})
// watch every connection state change
bizClient.onStateChange(state => {
console.log('state changed to', state)
})
// watch for specific event along with its topic
bizClient.subscribe('spaces', 'SPACE_ADDED', (message: EventMessage) => {
console.log(message)
})
// connect
bizClient.connect(err => {
if (err) {
console.log(`Failed to connect`, err)
}
})