Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
broadcast-channel
Advanced tools
A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers, NodeJs, Deno and iframes
The broadcast-channel npm package allows different browser tabs, iframes, web workers, and node.js processes to communicate with each other. It uses various methods like IndexedDB, local storage, or native events to create a channel that can be used to broadcast messages across different contexts running on the same machine.
Creating a Broadcast Channel
This code sample demonstrates how to import the BroadcastChannel class from the package and create a new channel named 'my-channel'.
const { BroadcastChannel } = require('broadcast-channel');
const channel = new BroadcastChannel('my-channel');
Sending a Message
This code sample shows how to send a message ('Hello World') through the channel to other listening contexts.
channel.postMessage('Hello World');
Receiving Messages
This code sample sets up an event listener to receive messages sent to the channel and logs them to the console.
channel.onmessage = (message) => console.log('Received:', message);
Closing a Channel
This code sample demonstrates how to close the channel when it is no longer needed to free up resources.
channel.close();
PubSubJS is a topic-based publish/subscribe library that's similar to broadcast-channel but does not support communication between different browser tabs or node processes.
While primarily a local storage library, localForage can be used to store and retrieve messages across sessions, which can be a form of communication similar to broadcast-channel, but it's not designed specifically for message broadcasting.
A BroadcastChannel that works in old browsers, new browsers, WebWorkers and NodeJs and Deno
+ LeaderElection over the channels
A BroadcastChannel that allows you to send data between different browser-tabs or nodejs-processes. And a LeaderElection over the channels.
7.0.0 (27 November 2023)
FAQs
A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers, NodeJs, Deno and iframes
The npm package broadcast-channel receives a total of 1,525,819 weekly downloads. As such, broadcast-channel popularity was classified as popular.
We found that broadcast-channel demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.