socket.io.client.biz
DFocus wanted ssp solution - javascript-client
DFocus wanted ssp solution - javascript-client. It must be work with the specific Backend(TBD)
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
Install
Currently, you can only use socket.io.client.biz
from the source, just copy dist
folder into your repo.
Usage
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 => {
if (err) {
console.log(`Failed to connect`, err)
}
})
// 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)
}
})