portcast
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

PortCast

A small library that allows multicasting with Channel Messaging API.

Normally, a MessageChannel connects two windows or two workers to each other. Sometimes, one may want to multicast a mesage to a number of workers/iframes. This is where PortCast comes in.

(480 bytes gzipped)

Usage

You create a channel with a specified name using PortCast, and provide the names of all the channels its messages should be multicast to.

In the following example, all messages from channelA will be broadcasted to channelB. All messages from channelC will be broadcasted to Channels A, B, D.

import { PortCast } from 'portcast';
 
const portcast = new PortCast();
const channelA = portcast.addChannel('A', ['B']);
const channelB = portcast.addChannel('B', ['A', 'C']);
const channelC = portcast.addChannel('C', ['A', 'B', 'D']);
const channelD = portcast.addChannel('D', ['A']);

Note: PortCast only deals with multicasting the messages on the channel. You have to do your own work of passing the channel port to the Worker or the iFrame. See Using channel messaging on MDN to get a primer.

Examples

Here are a couple of live examples to see PortCast in action:

PortCast with iFrames

PortCast with Web Workers

Source code for these pages is available in the examples folder.

Install

Download the latest from dist folder

or from npm:

npm install --save portcast

License

MIT License (c) Preet Shihn

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i portcast

    Weekly Downloads

    0

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    18.3 kB

    Total Files

    11

    Last publish

    Collaborators

    • shihn