Socket
Socket
Sign inDemoInstall

broadcast-channel

Package Overview
Dependencies
8
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

broadcast-channel

A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers, NodeJs, Deno and iframes


Version published
Maintainers
1
Weekly downloads
1,453,998
decreased by-24.74%

Weekly downloads

Package description

What is broadcast-channel?

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.

What are broadcast-channel's main functionalities?

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();

Other packages similar to broadcast-channel

Readme

Source

BroadcastChannel

A BroadcastChannel that works in old browsers, new browsers, WebWorkers and NodeJs and Deno
+ LeaderElection over the channels

follow on Twitter

demo.gif


A BroadcastChannel that allows you to send data between different browser-tabs or nodejs-processes. And a LeaderElection over the channels.

Read the full documentation on github

Sponsored by

JavaScript Database

The JavaScript Database

Keywords

FAQs

Last updated on 27 Nov 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc