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

dual-broadcast

v2.1.0

Published

Broadcast host for dualapi

Downloads

7

Readme

Broadcaster for dual-protocol Build Status

Fan-out dual-protocol messages.

Construct a broadcasting domain

dual-protocol domains may be extended with the dual-broadcast module:

var dual = require('dual-protocol').use(require('dual-broadcast'));

Domains with this extension can create broadcast objects:

var domain = dual();
var broadcaster = domain.broadcast(['b']);

Here we've provided a specific mount point for the broadcaster at ['b']. newListener and removeListener events will be emitted below that endpoint. By default, the broadcaster is mounted at ['broadcast'].

Register a broadcast recipient

To register a mount point ['client', xxxxx] as potential recipient of broadcasts:

broadcaster.register(['client', xxxxx]);

A map of subscriptions is created for each client. The subscriptions will be removed when the ['disconnect', 'client', xxxx] event is emitted on the domain.

Subscribe a registered client to a broadcast channel

To subscribe the registered ['client', xxxxx] to the broadcast point ['bbc', 'eight']:

	broadcaster.subscribe(['client', xxxxx], ['bbc', 'eight']); 

The registered client ['client', xxxxx] would now receive broadcasts from ['bbc', 'eight'].

Broadcasting

Broadcast a message to every subscribed recipient by

broadcaster.send(['bbc', 'eight'], 'hello', { optional: 'metadata' });

All subscribers would receive a message from ['bbc', 'eight'] with body 'hello', and the given dualapi options.

Unsubscribing

Broadcast clients may be unsubscribed from specific subscriptions:

broadcaster.unsubscribe(['client', xxxxx], ['bbc', 'eight']);

Disconnecting

A client is unsubscribed from all subscriptions, and removed as a potential subscription host, when the domain emits a disconnect event:

domain.send(['disconnect', 'client', xxxxx]);

Auto-registering clients

Clients may be automatically registered on ['connect', '**'] events by using the autoregister function.

broadcaster.autoregister(['client', '*']);
domain.send(['connect', 'client', 'zzz']);

At this point, ['client', 'zzz'] would be registered, as would any other client matching ['client', '*'] when they connect.

newListener events

When a subscriber is added to a broadcast channel, the domain emits a newListener event

domain.mount(['b', 'newListener'], function (body, ctxt) {
   console.log(body.join('/'), ' is now a subscriber to ', ctxt.from.join('/'));
});

New subscribers on specific broadcast channels are are emitted below the newListener endpoint:

domain.mount(['b', 'newListener', 'bbc', 'eight'], function (body, ctxt) {
   console.log(body.join('/'), ' is now a subscriber to ', ctxt.from.join('/'));
});

removeListener events

When a subscriber is removed from a broadcast channel, either by unsubscribe or disconnecting, the domain emits a removeListener event

domain.mount(['b', 'removeListener'], function (body, ctxt) {
   console.log(body.join('/'), ' is no longer a subscriber to ', ctxt.from.join('/'));
});

Subscribers leaving a specific broadcast channel are emitted below the removeListener endpoint:

domain.mount(['b', 'removeListener', 'bbc', 'eight'], function (body, ctxt) {
   console.log(body.join('/'), ' is no longer a subscriber to ', ctxt.from.join('/'));
});