BridgeChannel
@zylem/game-lib / bridge / BridgeChannel
Interface: BridgeChannel
Defined in: packages/bridge/src/channel.ts:127
Typed message channel shared by the game and editor bridge adapters.
senddispatches immediately.queuecoalesces repeated payloads for the same type and flushes once per animation frame, so high-frequency updates (entity transforms, thumbnails streaming in) cost at most one message per rendered frame.getStatereturns the last delivered payload per type so a late-mounting consumer (editor opened mid-game) can hydrate without waiting for the next publish.
Extends
EventTarget
Methods
addEventListener()
addEventListener(
type,callback,options?):void
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | AddEventListenerOptions
Returns
void
Inherited from
EventTarget.addEventListener
dispatchEvent()
dispatchEvent(
event):boolean
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386
The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().
Parameters
event
Event
Returns
boolean
Inherited from
EventTarget.dispatchEvent
flush()
flush():
void
Defined in: packages/bridge/src/channel.ts:184
Flush all queued messages now (also runs automatically per frame).
Returns
void
getState()
getState<
K>(type):BridgeMessages[K] |undefined
Defined in: packages/bridge/src/channel.ts:283
Last delivered payload for a message type, if any.
Type Parameters
K
K extends keyof GameToEditorMessages | keyof EditorToGameMessages
Parameters
type
K
Returns
BridgeMessages[K] | undefined
hasSubscribers()
hasSubscribers(
type):boolean
Defined in: packages/bridge/src/channel.ts:260
Whether anyone is listening for a message type. Publishers use this to skip expensive work (thumbnail renders, entity summaries) when no editor is attached.
Parameters
type
keyof GameToEditorMessages | keyof EditorToGameMessages
Returns
boolean
on()
on<
K>(type,handler): () =>void
Defined in: packages/bridge/src/channel.ts:202
Subscribe to a message type. Returns an unsubscribe function.
Type Parameters
K
K extends keyof GameToEditorMessages | keyof EditorToGameMessages
Parameters
type
K
handler
Returns
() => void
onSubscriberAdded()
onSubscriberAdded(
listener): () =>void
Defined in: packages/bridge/src/channel.ts:275
Observe types gaining their first subscriber, so a publisher that went idle can backfill state for a late-connecting consumer.
Parameters
listener
(type) => void
Returns
An unsubscribe function.
() => void
queue()
queue<
K>(type,payload):void
Defined in: packages/bridge/src/channel.ts:164
Queue a message for the next animation frame, merging with any payload already queued for the same type.
Type Parameters
K
K extends keyof GameToEditorMessages | keyof EditorToGameMessages
Parameters
type
K
payload
Returns
void
removeEventListener()
removeEventListener(
type,callback,options?):void
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | EventListenerOptions
Returns
void
Inherited from
EventTarget.removeEventListener
reset()
reset():
void
Defined in: packages/bridge/src/channel.ts:300
Drop all retained state and queued messages.
Returns
void
retainedSize()
retainedSize(
type):number
Defined in: packages/bridge/src/channel.ts:306
Number of retained entries for a type (array length, or 1 for objects).
Parameters
type
keyof GameToEditorMessages | keyof EditorToGameMessages
Returns
number
send()
send<
K>(type,payload):void
Defined in: packages/bridge/src/channel.ts:138
Dispatch a message immediately.
Type Parameters
K
K extends keyof GameToEditorMessages | keyof EditorToGameMessages
Parameters
type
K
payload
Returns
void
setState()
setState<
K>(type,payload):void
Defined in: packages/bridge/src/channel.ts:288
Overwrite the retained state for a type (used for pruning).
Type Parameters
K
K extends keyof GameToEditorMessages | keyof EditorToGameMessages
Parameters
type
K
payload
BridgeMessages[K] | undefined
Returns
void
subscriberCount()
subscriberCount(
type):number
Defined in: packages/bridge/src/channel.ts:265
Current subscriber count for a message type.
Parameters
type
keyof GameToEditorMessages | keyof EditorToGameMessages
Returns
number