rtc/rtc_signal.ts

The WebRTC signal envelope: what RtcPeer sends its far end, carried by RtcMesh as a room payload (room_send's payload, a string the server relays without reading).

A signal is one of two things, the two that perfect negotiation exchanges: a session description (an offer or an answer) or a trickled ICE candidate. On the wire it is the JSON text of one object whose rtc key is the envelope's version, RTC_SIGNAL_VERSION, beside exactly one of description or candidate:

{"rtc":1,"description":{"type":"offer","sdp":"v=0\r\n…"}} {"rtc":1,"candidate":{"candidate":"candidate:…","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"…"}}

candidate is RTCIceCandidate.toJSON(). The end of candidates is never sent: trickle works without it. The rtc key also tells a signal apart from the room's other payloads (a room's text, say): decode_rtc_signal answers not_rtc_signal for any payload without it, so a room's other listeners can read their own. A newer envelope bumps the version, and an older client refuses it as unsupported_version rather than misreading it.

view source

Declarations
#

7 declarations

decode_rtc_signal
#

rtc/rtc_signal.ts view source

(payload: string): Result<{ value: RtcSignal; }, { reason: RtcSignalDecodeError; }> import {decode_rtc_signal} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

Decode a room payload as a signal.

payload

a room_message payload

type string

returns

Result

the signal, or why the payload is none

encode_rtc_signal
#

rtc/rtc_signal.ts view source

(signal: RtcSignal): string import {encode_rtc_signal} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

Encode a signal as a room payload.

signal

the signal

returns

string

its envelope's JSON text

RTC_SIGNAL_VERSION
#

RtcIceCandidate
#

rtc/rtc_signal.ts view source

value + type

{ candidate: string; sdpMid?: string | null | undefined; sdpMLineIndex?: number | null | undefined; usernameFragment?: string | null | undefined; } import {RtcIceCandidate} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

A trickled ICE candidate as a signal carries it: RTCIceCandidate.toJSON().

candidate

type string

sdpMid?

type string | null

sdpMLineIndex?

type number | null

usernameFragment?

type string | null

RtcSessionDescription
#

rtc/rtc_signal.ts view source

value + type

{ type: "offer" | "answer"; sdp: string; } import {RtcSessionDescription} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

A session description as a signal carries it: an offer or an answer.

type

type "offer" | "answer"

sdp

type string

RtcSignal
#

rtc/rtc_signal.ts view source

RtcSignal

type { description: { type: "offer" | "answer"; sdp: string; }; } | { candidate: { candidate: string; sdpMid?: string | null | undefined; sdpMLineIndex?: number | null | undefined; usernameFragment?: string | null | undefined; }; }

import type {RtcSignal} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

One signal between two peers: a session description, or an ICE candidate.

RtcSignalDecodeError
#

rtc/rtc_signal.ts view source

RtcSignalDecodeError

type "not_rtc_signal" | "unsupported_version" | "invalid"

import type {RtcSignalDecodeError} from '@fuzdev/fuz_app/rtc/rtc_signal.js';

Why a payload is no signal: not_rtc_signal (no rtc key, or not JSON — a payload for some other reader), unsupported_version (another envelope version), invalid (an rtc envelope that doesn't parse).

Imported by
#