Skip to content

Transports

For the conceptual explanation of when each transport is used, see the Transports guide. This page documents its exact shape.

interface ITransport {
send(msg: TabusMessage): void;
onMessage(listener: (msg: TabusMessage) => void): void;
destroy(): void;
}
Member Description
send(msg) Sends a TabusMessage through the transport.
onMessage(listener) Registers a listener that’s invoked with every TabusMessage received.
destroy() Releases the transport’s resources (closes the underlying channel).

A thin wrapper around the native BroadcastChannel API.

Method Implementation
send(msg) bc.postMessage(msg)
onMessage(listener) bc.addEventListener("message", ...)
destroy() bc.close()

It’s the default transport used in any browser that supports BroadcastChannel, and it communicates real tabs, windows, and workers of the same origin.

In-memory fallback, active when BroadcastChannel doesn’t exist (Node, SSR, very old browsers).

  • Keeps a module-level registry: Map<string, Set<listener>>, shared by every MemoryTransport instance within the same process.
  • Only works within the same process/tab — it doesn’t cross real tabs, because without BroadcastChannel that concept doesn’t exist.
  • Unlike BroadcastTransport, the emitter’s own listener is invoked by send(); it’s Tabus, not the transport, that filters by tabId.
  • Emits a console.warn once per channel name, warning that the fallback kicked in.
function __resetMemoryBus(): void

Clears MemoryTransport’s internal module-level registry (the listeners and the record of channels already warned about).

Exports summarizes what all of this exports publicly from tabus-js.