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

websocket-method

v0.0.4

Published

Websocket server/client with methods protocol

Downloads

2

Readme

Websocket-method

Json websocket server/client.

install: npm i websocket-method

Example

const { WebsocketMethodServerClass, WebsocketMethodClientClass } = require("websocket-method");

const client_config = {
    url: "ws://localhost:5005/websocket"
};
const server_config = {
    port: 5005,
    prefix: "/websocket"
};

const server = new WebsocketMethodServerClass(server_config);
const client = new WebsocketMethodClientClass(client_config);

server.listen().then( () => {

    console.log("Server open on port 5005");

    client.connect().then( () => {
        console.log("Client connected");
    });

});

Server

new ServerClass(options) -> Server;

Create WebsocketMethodServerClass instance.

options:

  • host: "*" -> listening host
  • port: 8080 -> listening port
  • prefix: "/" -> listening prefix
  • protocol: "ws" -> server protocol (ws or wss)
  • heartbeat: 30 -> heartbeat connection in seconds
  • ttl: 90 -> ttl connection in seconds
  • max_payload: "100kb" -> maxPayload connection (kb,b or mb)
  • cert: "cert.pem" - path to cert
  • key: "key.pem" - path to key
  • auth: false - enable authorization

Server.info -> Object

Object with server information.

Server.listen() → Promise

Start server.

Server.close() → Promise

Close server.

Server.getConnectionsList (): string[]

Return list of Id connections.

Server.getConnection (connection_id: string) -> Connection

Return connection instance.

Server.send (method: string, message: any, headers: object = {}, connection_id?: string) -> Promise

Send message to all clients. If set connection_id, send message only to id client.

Server.on("close", (Connection) => {})

Emitted when close connection.

Server.on("error", (error) => {})

Emitted when error.

Server.on("open", (Connection) => {})

Emitted when open connection.

Server.on("authorization", (type_auth: string, auth_string: string, callback) => {})

Emitted when authorization request is being.

arguments:

  • auth_type -> authorization type (Basic or Bearer)
  • auth_string -> authorization string
  • callback -> response function (true or false)

Server.on([method], (body, headers, Connection) => {})

Emitted when received message with method.

arguments:

  • body -> body of message
  • headers -> headers object
  • Connection -> connection instance.

Connection

Connection.id -> string

Get ID connection.

Connection.protocol (): string

Get Connection.protocol connection.

Connection.status (): string

Get status connection.

Connection.close() -> Promise

Close connection.

Connection.send (method: string, message: any, headers: object = {}) -> Promise

Send message to client.

Client

new ClientClass(options) -> Client;

Create WebsocketMethodServerClass instance.

options:

  • url: "ws://localhost:8080/websocket" -> url to server
  • reconnect_interval: 10 -> reconnect interval connection in seconds
  • heartbeat: 30 -> heartbeat connection in seconds
  • ttl: 90 -> ttl connection in seconds
  • max_payload: "100kb" -> maxPayload connection (kb,b or mb)
  • headers: {} -> http headers object
  • auth: {} -> authorization object
    • login -> login to server (Basic)
    • password -> password to server (Basic)
    • token -> token to server (Bearer)
  • reject_unauthorized: true -> reject unauthorized equest (true/false)

Client.status -> string

Get status connection.

Client.info -> Object

Object with client information.

Client.connect() -> Promise

Connecting to server.

Client.close() -> Promise

Close connection.

Client.send(method: string, message: any, headers: object = {}) -> Promise

Send message to server.

Client.terminate()

Terminate client connection.

Client.on("open", () => {})

Emitted when open connection.

Client.on("close", () => {})

Emitted when close connection.

Client.on("reconnecting", () => {})

Emitted when enabled reconnecting.

Client.on("error", (error) => {})

Emitted when error.

Client.on([method], (body, headers) => {})

Emitted when received message with method.

arguments:

  • body -> body of message
  • headers -> headers object