Introduction

Websocket client for NodeJS platform. The client works best with the Regoch Websocket Server. Small, optimised and very powerful library made according to RFC6455 Standard for websocket version 13.

Features

  • RFC6455, websocket v.13
  • supported subprotocols: jsonRWS, raw
  • small, medium and large messages (up to 9,007,199,254 gigabytes or ~9 quadrillion bytes)
  • ping & pong
  • questions - send request to server and receive response (simmilar to HTTP request but on the websocket TCP level)
  • rooms - send group message to a subscribed clients
  • small file size, minified (*~7.5kB only*)
  • powerful API which saves your development time
  • easy integration with RxJS

Installation

Install the websocket client in your project via npm:

$ npm install --save regoch-websocket


How to use

A short example how to use NodeJS Websocket Client after installation:

const { RWClientNodejs, lib } = require('regoch-websocket');
const helper = lib.helper;

class TestClient extends RWClientNodejs {
  constructor(wcOpts) {
    super(wcOpts);
  }
}

const main = async () => {
  // connect to websocket server
  const wcOpts = {
    wsURL: 'ws://localhost:3211?authkey=TRTmrt',
    questionTimeout: 3*1000, // wait 3 seconds for answer
    reconnectAttempts: 5, // try to reconnect 5 times
    reconnectDelay: 3000, // delay between reconnections is 3 seconds
    subprotocols: ['jsonRWS', 'raw'], // ask server if it supports "jsonRWS" or "raw" subprotocol
    debug: false // print debug messages (useful for development)
  };
  const testClient = new TestClient(wcOpts);
  await testClient.connect();

  await helper.sleep(1300);

  console.log('message sent');
  await testClient.sendOne(210726155519554340, 'some message');
};


main().catch(err => console.log(err));
  

Exports in the npm package


module.exports = {
  RWServer,
  RWHttpServer,
  RWClientNodejs,
  RWClientBrowser,
  lib
};
  

TCPDUMP

Use tcpdump command to debug the messages sent from the server to the client.
For example sudo tcpdump -i any port 57190 -X -s0 where 57190 is the client port i.e. socket.localPort

License

The software is published under MIT License.
The MIT License

Copyright (C) 2021  Saša Mikodanić http://www.regoch.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.