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

@js-cloud/mailman

v1.0.0

Published

A superfast and light-weight message broker for pub/sub communication over network. Suitable for realtime low latency applications

Downloads

2

Readme

MailMan: a javascript Pub/Sub library

npm CI npm GitHub issues GitHub

A superfast and light-weight message broker for pub/sub communication over network. Suitable for realtime low latency applications and intra-service communication.

Table of Contents

About

JS Cloud Suite is an open source project developed with an aim to simplify the effort of creating scalable and performance oriented cloud applications. This suite hosts a series of libraries, which can be integrated into any projects to enable cloud capabilities. We currently do not support in house hosted solutions, but with our tools and libraries, you can build customized solutions your own. All you need to have is a simple server setup (in old PCs, laptops, raspberry Pis, AWS EC2, etc).

You can also contribute to this project. Navigate to contribute section to know how.

This library is developed using Node.js and do not support any other frameworks yet. In order to install and use this library you are required to have a working installation of node.js (preferrably latest version).

Installation

Open up a terminal and install this library like this,

npm install @js-cloud/mailman

Modules

MMServer

import { MMServer } from '@js-cloud/mailman'

MMServer.init(4000);

Customize server


const sslconfig: SSLConfig = {
    cert: 'path to cert',
    key: 'path to key'
}
//custom handler for new connection request
const verifyClientCallback: VerifyClientCallback = (req, done) => {
    const newId = uuid();
    //if verified successfully
    done(null /*Error object is null for success*/, newId /*New generated Id for client*/);
    //if not verified
    const error=new ApiError('some error message')/*Define Api error customized for your application*/
    done(error,null);
}

//Initialize Server at PORT 4000
MMServer.init(4000, sslconfig, undefined, verifyClientCallback);

MMClient


import { MMClient } from '@js-cloud/mailman';

//create a new Instance of Client
const client = new MMClient('ws://localhost:4000'/*URL of MM Server*/);

Customize Client


//define options for client
const options: ClientOptions = {
    alias: 'mm_client',                         //nickname/alias for client, easy for identifying clients
    reconnectStrategy: 'INCREMENTAL_INTERVAL',  //Strategy for reconnection -> 'INCREMENTAL_INTERVAL' | 'FIXED_INTERVAL'
    autoReconnect: true,                        //Connect automatically after reconnection. Not on manual disconenction
    reconnectLimit: 5,                          //Max reconnect tries  
    reconnectTimeoutMs: 1000,                   //Reconect interval
    logEnabled: true,                           //Enable Pretty logging for client events
}

//create a new Instance of Client
const client = new MMClient('ws://localhost:4000'/*URL of MM Server*/,options);

//connect to server
client.connect();

Detect client status change

It is often necessary to detect state change of the client when building resilient applications. MM provides a callback mechanism to be aware of the state changes of the client. There can possibly be 4 states of the client.

OPEN : The Websocket conenction is open, but server acknowledgement is pending (Handshake and Id assignment). All the messages published in this state will be queued and starts sending them once the connection is ACTIVE.

ACTIVE: The client has been assigned an Id and is ready to send and recieve messages from the server.

INACTIVE: The client is disable and hence transfer of messages is not possible. This state may occur once the client has started disconnection sequence or have manually paused the connection by the user.

CLOSED : The client has closed connection, either manually, or remotely initiated by the host server.


//callback invoked whenever a change in connection state is detected
client.onStatusChanged((status, mClient) => {
    console.log('Current status :',status);
})

Subcribe to Topics


//callback invoked whenever a change in connection state is detected
client.subscribe('my_topic',(data)=>console.log('message recieved ',data));

client.subscribe() is a promise. So, we can acknowledge subscription to a topic by consuming this promise


//using async/await 
try{
  const callback=(data)=>console.log('message recieved ',data);

  const result=await client.subscribe('my_topic',callback);
  console.log('subscribed to topic');

}catch(er){
  console.log(er);
}

//using then
 const callback=(data)=>console.log('message recieved ',data);

 client.subscribe('my_topic',callback)
 .then(()=>console.info('subscribed to topic'))
 .catch(console.error);

Publish messages to topics

client.publish('my_topic',payload /*Can be any object, string, number or any primitive types*/)

Broadcast messages to all clients

client.broadcast('my_topic',payload /*Can be any object, string, number or any primitive types*/)

Contribute

We welcome feedback, bug reports, and pull requests!

For pull requests, please stick to the following guidelines:

  • Add tests for any new features and bug fixes. Ideally, each PR should increase the test coverage.
  • Follow the existing code style. (Run npm run format and npm run lint before checking in your code).
  • Put a reasonable amount of comments into the code.
  • Fork this repo on your GitHub user account, do your changes there and then create a PR against main repository.
  • Separate unrelated changes into multiple pull requests.

Please note that by contributing any code or documentation to this repository (by raising pull requests, or otherwise) you explicitly agree to the.