stable-socket

A web socket that reconnects.

MIT License

Downloads
3.8K
Stars
125
Committers
8
stable-socket - v1.1.0 Latest Release

Published by keithamus about 3 years ago

What's Changed

Full Changelog: https://github.com/github/stable-socket/compare/v1.0.0...v1.1.0

stable-socket - 1.0.0

Published by dgraham about 4 years ago

A stable release with no changes since 0.1.2.

stable-socket - 0.1.1

Published by dgraham over 4 years ago

StableSocket

A web socket that reconnects.

Installation

$ npm install @github/stable-socket

Usage

import {StableSocket} from '@github/stable-socket'

const delegate = {
  socketDidOpen(socket: Socket) {
    // Socket is ready to write.
    socket.send('Hello')
  },
  socketDidClose(socket: Socket, code?: number, reason?: string) {
    // Socket closed and will retry the connection.
  },
  socketDidFinish(socket: Socket) {
    // Socket closed for good and will not retry.
  },
  socketDidReceiveMessage(socket: Socket, message: string) {
    // Socket read data from the connection.
  }
}

const policy = {
  timeout: 4000,
  attempts: Infinity,
  maxDelay: 60000
}

const socket = new StableSocket('wss://live.example.com', delegate, policy)
socket.open()
Package Rankings
Top 4.14% on Npmjs.org