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

fruster-web-bus-client

v0.0.8

Published

client for using the fruster web bus

Downloads

5

Readme

Fruster web bus client

The fruster bus client looks at the subject of incoming messages from the server and redirects them to the corresponding handlers. All handlers for a specific subject will be triggered by an incoming message. By default, the subscribe function registers a handler on the specific subject with an id of that subject to prevent stock up in a reactive application. If a specific subject needs several things to happen in different places in the application, unique ids can be given to make sure they don´t overwrite each other.

Subjects are defined by the backend services in similar fashion to ws.out.:userId.*.

Example subject: ws.out.d5d20597.video-session.start

Instantiate the bus:

var bus = new FrusterWebBusClient("ws://localhost:3000");

Register a handler for a specific subject. Every new subscribe will overwrite any previous handler (without id) for that subject.

bus.subscribe("ws.out.d5d20597.new-message", (msg) => {
    console.log("Subscribed to subject ws.out.d5d20597.new-message");
});

Register a handler for a specific subject without overwriting previous handlers using ids (id = VIDEO_SESSION_HANDLER_ID):

bus.subscribe("ws.out.d5d20597.video-session.start", "VIDEO_SESSION_HANDLER_ID", (msg) => {
    console.log("Subscribed to subject ws.out.d5d20597.video-session.start with id VIDEO_SESSION_HANDLER_ID");
});

Register a handler for a specific subject overwriting previous handler using a specific id (id = VIDEO_SESSION_HANDLER_ID):

bus.subscribe("ws.out.d5d20597.video-session.start", "VIDEO_SESSION_HANDLER_ID", (msg) => {
    console.log("overrides the previous handler for subject ws.out.d5d20597.video-session.start with id VIDEO_SESSION_HANDLER_ID");
});

Remove a handler for a specific subject and id (id = VIDEO_SESSION_HANDLER_ID):

bus.unsubscribe("ws.out.d5d20597.video-session.start", "VIDEO_SESSION_HANDLER_ID");

Remove all handlers for a specific subject:

bus.unsubscribe("ws.out.d5d20597.video-session.start");

Register bus error handler:

bus.onError(() => {
    console.error("ERROR");
});

Register bus open handler:

bus.onOpen(() => {
    console.error("OPENED");
});

Register bus close handler:

bus.onClose(() => {
    console.error("CLOSED");
});

Requests

Requests can be made to specific fruster websocket endpoints. The endpoints uses the same methods as http, e.g. POST, GET etc. Example endpoint ws.get.user.:userId which can be called as ws.get.user.4b2a50c5-f8fc-465c-a8e1-bfa978767396 to get the user with the id 4b2a50c5-f8fc-465c-a8e1-bfa978767396.

const response = await bus.request({
    subject: `ws.post.chat`, // endpoint 
    message: { // request body
        data: {
            message: $("#message").val()
        }
    }
});

Response is returned in the same fashion as http endpoints in fruster.

For more examples, see FrostDigital/fruster-web-bus-client examples

Development

To start webpack in watch mode:

npm start

To build project using webpack and generate typings:

npm run build