ReasonML bindings for Broadcast Channel
npm
npm i --save bs-broadcast-channel
yarn
yarn add bs-broadcast-channel
After installing, add it to the dependencies
bsconfig.json
{
"bs-dependencies": [
"bs-broadcast-channel",
],
}
open BsBroadcastChannel;
/**
* Create a channel
*/
let channel = BroadcastChannel.make("My app");
/**
* Listen to messages
*/
channel->BroadcastChannel.addEventListener("message", (data: MessageEvent.t) => {
/**
* get our data
*/
Js.log(data->MessageEvent.data);
});
/**
* Post message
*/
channel->BroadcastChannel.postMessage("Hello World");
/**
* Close our channel
*/
channel->BroadcastChannel.close();
MIT © lxsmnsyc