Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

broadcast-channel

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

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

  • 7.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9M
decreased by-2.02%
Maintainers
1
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 27 Nov 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc