README
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:
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