Optionaloptions: boolean | AddEventListenerOptionsDispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Check if there are pending repair requests that need to be sent. Useful for adaptive sync intervals - increase frequency when repairs pending.
Processes all queued tasks sequentially to ensure proper message ordering.
This method should be called periodically by the library consumer to execute queued send/receive operations in the correct sequence.
Queues a received message for processing.
The message will be processed when processTasks() is called, ensuring proper dependency resolution and causal ordering.
The message to receive and process
The retrieval hint for the message, provided by the transport layer
Sends a short-lived message without synchronization or reliability requirements.
Sends a message without a timestamp, causal history, or bloom filter. Ephemeral messages are not added to the outgoing buffer. Upon reception, ephemeral messages are delivered immediately without checking for causal dependencies or including in the local log.
The payload to send.
Optionalcallback: (processedMessage: Message) => Promise<boolean>A callback function that returns a boolean indicating whether the message was sent successfully.
Queues a message to be sent on this channel.
The message will be processed sequentially when processTasks() is called. This ensures proper lamport timestamp ordering and causal history tracking.
The message content as a byte array
Optionalcallback: (callback function that should propagate the message
on the routing layer; success should be false if sending irremediably fails,
when set to true, the message is finalized into the channel locally.
Promise that resolves when the message is queued (not sent)
const channel = new MessageChannel("chat-room");
const message = new TextEncoder().encode("Hello, world!");
await channel.pushOutgoingMessage(message, async (processedMessage) => {
console.log("Message processed:", processedMessage.messageId);
return { success: true };
});
// Actually send the message
await channel.processTasks();
Send a sync message to the SDS channel.
Increments the lamport timestamp, constructs a Message object
with an empty load. Skips outgoing buffer, filter, and local log.
Optionalcallback: (message: SyncMessage) => Promise<boolean>A callback function that returns a boolean indicating whether the message was sent successfully.
Removes the event listener in target's event listener list with the same type, callback, and options.
Optionallistener: null | EventHandler<MessageChannelEvents[K]>Optionaloptions: boolean | EventListenerOptionsOptionaldetail: CustomEventInit<Detail>Processes messages in the incoming buffer, delivering those with satisfied dependencies.
The missing dependencies
Sweep repair incoming buffer and rebroadcast messages ready for repair. Per SDS-R spec: periodically check for repair responses that are due.
Optionalcallback: (message: Message) => Promise<boolean>callback to rebroadcast the message
Promise that resolves when all ready repairs have been sent
Staticget
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
MDN Reference