npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mikosoft/ws-client-nodejs

v1.3.2

Published

Websocket client for NodeJS.

Downloads

7

Readme

@mikosoft/ws-client-nodejs

Websocket Client for nodeJS which works best with the Mikosoft Websocket Server @mikosoft/ws-server.

Optimised, high speed, reliable and very powerful library made according to RFC6455 Standard for websocket version 13.

Installation

npm install --save @mikosoft/ws-client-nodejs

Website Documentation

http://libs.mikosoft.info/websocket/ws-client-nodejs

Websocket Client Features

  • RFC6455, websocket v.13
  • supported subprotocols: jsonRWS, raw
  • automatic reconnect
  • ping & pong
  • questions - send request to server and receive answer (simmilar to HTTP request but on the websocket TCP level)
  • rooms - send group message to a subscribed clients
  • small file size, minified (~9.8kB only)
  • powerful API which saves your development time
  • easy integration with RxJS

API

  • connect(wsURL) - connect to the websocket server via websocket URL (wsURL) -- ws:// or wss:// protocols

  • disconnect() - disconnect from the websocket server

  • sendOne(to:string, payload:any) - send message to one websocket socket/client (parameter to is the socket ID)

  • send(to:string[], payload:any) - send message to one or more clients

  • broadcast(payload:any) - send message to all clients except the sender

  • sendAll(payload:any) - send message to all clients and the sender

  • sendRaw(payload:string) - send raw string message to server for test purposes

  • sendServer(payload:any) - send message to server only (no sending to other clients)

  • ping(ms:number, n:number) - send PING to server n times, every ms miliseconds

  • pong() - when PING is received from the server send PONG back.

  • questionSocketId() - receive the client's socket id

  • questionSocketList() - receive the list of sockets connected on the server

  • questionRoomList() - receive the list of all rooms

  • questionRoomListmy() - receive the list of subscribed rooms

  • roomEnter(roomName:string) - enter the room and start to listen the room's messages

  • roomExit(roomName:string) - exit from the room and stop to listen the room's messages

  • roomExitAll() - exit from the all rooms

  • roomSend(roomName:string, payload:any) - exit from the room and stop to listen the room's messages

  • setNick(nickname:string) - set the client's nickname

  • route(uri:string, body?:any) - send route to the server, for example: {uri: '/login', body: {username: 'john', password: 'trtmrt'}}

  • on(eventName:string, listener:Function) - listen events: 'connected', 'disconnected', 'closed-by-server', 'ping', 'pong', 'message', 'message-error', 'question', 'route', 'server-error'

  • once(eventName:string, listener:Function) - listen event only once: 'connected', 'disconnected', 'closed-by-server', 'ping', 'pong', 'message', 'message-error', 'question', 'route', 'server-error'

  • off(eventName:string, listener:Function) - stop listening the event for specific listener

Notice

The 'message-error' event is error in the recived message. In most cases this error is generated when message doesn't satisfy jsonRWS subprotocol rules.

Example

const { WsClientNodejs } = require('@mikosoft/ws-client-nodejs');

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

const main = async () => {
  // connect to websocket server
  const wcOpts = {
    connectTimeout: 8000,
    reconnectAttempts: 6, // try to reconnect n times
    reconnectDelay: 5000, // delay between reconnections
    questionTimeout: 13000, // wait for answer
    subprotocols: ['jsonRWS', 'raw'],
    autodelayFactor: 500,
    debug: false,
    debug_DataParser: false
  };
  const testClient = new TestClient(wcOpts);
  const socket = await testClient.connect('ws://localhost:3211?authkey=TRTmrt');
  console.log('---SOCKET---');
  console.log('readyState::', socket.readyState);
  console.log('writable::', socket.writable);
  console.log('readable::', socket.readable);

  testClient.on('message', (msg, msgSTR, msgBUF) => {
    console.log('received message::', msgSTR);
  });

  await testClient.sendAll(to, 'ABC of the websocket');
};

main();

Development

To develop the library:

// start the websocket server (look at @mikosoft/ws-server)
$ nodemon examples/001internal.js

// run the example script
$ nodemon examples/001connect.js

Licence

Copyright (c) 2021- Mikosoft licensed under MIT .