resilient-websocket
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

resilient-websocket

A client WebSocket wrapper with support for reconnection and ping/pong with a familiar API. Written in TypeScript

Installing

npm install resilient-websocket --save

API

import ResilientWebSocket, { WebSocketEvent } from 'resilient-websocket';

const opts = {
    autoJsonify: true, // parse json message from server, stringify messages on send,
    pingEnabled: true // send ping / pong messages
};

const rSock = new ResilientWebSocket(url, opts);

rSock.on(WebSocketEvent.CONNECTION, () => {
    rSock.on(WebSocketEvent.MESSAGE, (message) => {
        console.info('received message from the server', message);
        rSock.send({ message: 'Right back at ya, buddy!' });
    });
});

Readme

Keywords

none

Package Sidebar

Install

npm i resilient-websocket

Weekly Downloads

922

Version

1.0.11

License

Apache-2.0

Unpacked Size

30.3 kB

Total Files

13

Last publish

Collaborators

  • marchaos