rtc/rtc_mesh.svelte.ts

A full-mesh call over one room: RtcMesh keeps an RtcPeer to every other member of the room while the caller holds a seat in it, carrying the peers' signals as room payloads (rtc/rtc_signal.ts) and fanning the local tracks out to every peer.

The room is any RtcMeshRoom — RoomClient's RoomState is one. The mesh follows its seat: when a seat is taken it connects to each member the join answered, then to each member who joins after; a member who leaves has its peer closed; when the seat ends (left, lost, or the socket closed) every peer closes, and a seat taken again (a rejoin after a reconnect, with a new member id) connects afresh. The local tracks outlive the seats: each new peer starts with them.

Only the mesh topology is connected: a seat whose join answers another one sets error and connects nothing, since an SFU member needs a different client. A peer that can't be made (new RTCPeerConnection refusing a malformed ICE server, say) sets error too, and the mesh carries on without it.

A connection serving several actors hears each room message once, whoever it is for, so a message addressed to another member is not this mesh's and is dropped.

Sends, one at a time per peer

The server dispatches a socket's requests concurrently, so two room_send requests can relay out of order — a candidate ahead of the offer it belongs to. Each peer's signals therefore go through one chain: a send waits for the previous one's answer. Peers don't wait on each other.

ICE servers

ice_servers is a list, or a function of the seat, so servers the join answer carries in its extra (short-lived TURN credentials, minted per join) can be read there.

view source

Declarations
#

3 declarations

RtcMesh
#

rtc/rtc_mesh.svelte.ts view source

import {RtcMesh} from '@fuzdev/fuz_app/rtc/rtc_mesh.svelte.js';

The peers of a full-mesh call over one room. See the module doc.

slots

type readonly RtcSlot[]

readonly

peers

A peer for each other member while seated, by member id.

type SvelteMap<Branded, RtcPeer>

readonly

local_member_id

The seat's member id while connected, else null.

type Branded | null

$state.raw

error

Why the mesh connects nothing (an unsupported topology), or the last peer that couldn't be made, else null; cleared by the next seat.

type string | null

$state.raw

closed

Whether close was called.

type boolean

$state.raw

constructor

type new (deps: RtcPeerDeps, options: RtcMeshOptions): RtcMesh

deps

options

set_track

Send track in slot to every peer, and to each peer made later; null sends nothing there. No renegotiation: each peer replaces its slot's track.

type (slot: string, track: MediaStreamTrack | null): Promise<void>

slot

the slot's name

type string

track

the track, of the slot's kind, or null

type MediaStreamTrack | null
returns Promise<void>

throws

  • Error - when no slot has that name

close

Close every peer and stop following the room. The local tracks are the caller's and stay live.

type (): void

returns void

mutates

  • this — sets `closed`, empties `peers`

RtcMeshOptions
#

rtc/rtc_mesh.svelte.ts view source

RtcMeshOptions import type {RtcMeshOptions} from '@fuzdev/fuz_app/rtc/rtc_mesh.svelte.js';

Options for RtcMesh.

room

type RtcMeshRoom

slots?

The media slots every peer carries, the same list on every member's end.

type readonly RtcSlot[]

default RTC_VOICE_SLOTS

ice_servers?

The ICE servers, or a function of the seat that reads them (from its extra, say).

type readonly RTCIceServer[] | ((seat: RoomSeat) => readonly RTCIceServer[])

ice_disconnected_restart_ms?

See RtcPeerOptions.ice_disconnected_restart_ms.

type number | null

RtcMeshRoom
#

rtc/rtc_mesh.svelte.ts view source

RtcMeshRoom import type {RtcMeshRoom} from '@fuzdev/fuz_app/rtc/rtc_mesh.svelte.js';

What the mesh needs of a room — RoomState satisfies it.

seat

The caller's seat, null while it holds none.

type RoomSeat | null

readonly

members

The room's members, the caller's own seat included.

type readonly RoomMember[]

readonly

add_listener

Subscribe to the room's events; returns the remover.

type (listener: RoomListener): () => void

listener

returns () => void

send

Relay a payload to one member.

type (to: Branded<string, "Uuid">, payload: string): Promise<RoomRpcResult<null>>

to

type Branded

payload

type string
returns Promise<RoomRpcResult>

Depends on
#