Transports
For the conceptual explanation of when each transport is used, see the Transports guide. This page documents its exact shape.
ITransport
Section titled “ITransport”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). |
BroadcastTransport
Section titled “BroadcastTransport”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.
MemoryTransport
Section titled “MemoryTransport”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 everyMemoryTransportinstance within the same process. - Only works within the same process/tab — it doesn’t cross real tabs, because without
BroadcastChannelthat concept doesn’t exist. - Unlike
BroadcastTransport, the emitter’s own listener is invoked bysend(); it’sTabus, not the transport, that filters bytabId. - Emits a
console.warnonce per channel name, warning that the fallback kicked in.
__resetMemoryBus()
Section titled “__resetMemoryBus()”function __resetMemoryBus(): voidClears MemoryTransport’s internal module-level registry (the listeners and the record of channels already warned about).
Next step
Section titled “Next step”Exports summarizes what all of this exports publicly from tabus-js.
