Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/websocket_broadcastchannel/src/web-socket-broadcast-channel.ts>WebSocketBroadcastChannel

Host-wide BroadcastChannel for Deno CLI, backed by WebSockets.
Latest
class WebSocketBroadcastChannel
import { WebSocketBroadcastChannel } from "https://deno.land/x/websocket_broadcastchannel@0.8.0/src/web-socket-broadcast-channel.ts";

Use this the same way you would use BroadcastChannel on Deno Deploy, it has the same API, but on a host that is not Deno Deploy.

Instead of connecting all instances of the same app together like on Deno Deploy, this implementation uses a WebSocket to communicate with other instances of this class in the same or other processes, on the same host.

Will try to act as a WebSocket server, if no other instance of this class is running on the same host yet. Otherwise, will act as a WebSocket client and connect to the server. Will reconnect and switch roles as needed, if the instance that happens to be the server goes down.

When no instances of this class are running in this process (none created yet, or all closed), it stays disconnected. When at least one instance is created, it will keep doing its best to stay connected.

Constructors

new
WebSocketBroadcastChannel(name: string, url?: string | URL)

Properties

private
closeFuse: OneTimeFuse
private
readonly
idUrlChannel: IdUrlChannel
private
readonly
log: Logger
readonly
name: string
onmessage: ((ev: Event) => void) | null
onmessageerror: ((ev: Event) => void) | null
readonly
url: string
readonly
uuid: string

Methods

close(): void
postMessage(message: string): void