Skip to content

relay()

relay(transportA, transportB) is a pure wire between two transports: every osra envelope received on one side is forwarded verbatim (with its transferables re-collected) to the other, in both directions where the transports allow it. The relay never establishes a connection of its own; the endpoints handshake with each other through it.

const relay: (transportA: Transport, transportB: Transport, options?: RelayOptions) => void

Typical use: bridging two workers, or an iframe to a worker, through a page that owns both transports.

import {
const relay: (transportA: Transport, transportB: Transport, { key, origin, originA, originB, nameA, nameB, unregisterSignal, }?: RelayOptions) => void
relay
} from 'osra'
function relay(transportA: Transport, transportB: Transport, { key, origin, originA, originB, nameA, nameB, unregisterSignal, }?: RelayOptions): void
relay
(
const workerA: Worker
workerA
,
const workerB: Worker
workerB
, {
unregisterSignal?: AbortSignal | undefined
unregisterSignal
:
const controller: AbortController
controller
.
AbortController.signal: AbortSignal

The signal read-only property of the AbortController interface returns an AbortSignal object instance, which can be used to communicate with/abort an asynchronous operation as desired.

MDN Reference

signal
})

The relay is built on exactly the low-level messaging primitives: it filters and forwards raw envelopes, nothing more. The endpoints on either side run their normal handshake through it.

Option Type Default Semantics
key string OSRA_DEFAULT_KEY Only envelopes with this key are forwarded.
origin string '*' Default for both directions.
originA / originB string origin Per-side origin (inbound filter from that side + outbound targetOrigin toward it).
nameA / nameB string - Only forward envelopes from that side whose name matches.
unregisterSignal AbortSignal - Stops forwarding in both directions.

A direction is only wired when the source can receive and the destination can emit; emit-only/receive-only pairs degrade to one-way forwarding.

See JSON vs clone transports for what distinguishes the two classes.