trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
43 lines • 1.61 kB
TypeScript
/**
* Serverless cross-tab realtime transport using the browser BroadcastChannel
* API. All tabs/windows of the same origin that open a channel with the same
* name form a broadcast mesh — no server required.
*
* BroadcastChannel does not deliver a message back to the posting channel
* object, so the mesh semantics (no self-echo) hold naturally.
*/
import type { RealtimeMessage, RealtimeTransport } from './types.js';
interface BroadcastChannelLike {
postMessage(message: unknown): void;
close(): void;
onmessage: ((event: {
data: unknown;
}) => void) | null;
addEventListener?(type: 'message', listener: (event: {
data: unknown;
}) => void): void;
removeEventListener?(type: 'message', listener: (event: {
data: unknown;
}) => void): void;
}
type BroadcastChannelCtor = new (name: string) => BroadcastChannelLike;
export interface BroadcastChannelTransportOptions {
/** Local peer identity. */
id: string;
/** Channel name — all peers in the room share this. */
channel: string;
/** Injectable implementation for tests / non-browser hosts. */
BroadcastChannelImpl?: BroadcastChannelCtor;
}
export declare class BroadcastChannelTransport implements RealtimeTransport {
readonly id: string;
private bc;
private handlers;
private closed;
constructor(opts: BroadcastChannelTransportOptions);
send(message: RealtimeMessage): void;
onMessage(handler: (message: RealtimeMessage) => void): () => void;
close(): void;
}
export {};
//# sourceMappingURL=broadcast-channel-transport.d.ts.map