Skip to content

DFocusGroup/socket.io.client.biz

Repository files navigation

socket.io.client.biz

NPM version

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

Install

Currently, you can only use socket.io.client.biz from the source, just copy dist folder into your repo.

Import

ES2015

import { SocketIoClientBiz } from 'socket.io.client.biz'

CommonJS

const { SocketIoClientBiz } = require('socket.io.client.biz')

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 => {
  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)
  }
})

LICENSE

MIT License

About

A javascript client-side implementation for DFocus wanted business usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published