Selkies

lib/signaling

Signaling client for the WebRTC transport.

Speaks the line protocol of the server's signaling WebSocket. HELLO <peer type> <json> registers the client, the JSON carrying its type, slot, strict-viewer flag, secure-mode token, display id, display position, tab, the start rate congestion control last held its display at, and the session's resume key; SESSION server asks for the server peer and is answered with SESSION_OK <peer id>; from then on the SDP and the ICE candidates travel as <peer id> {"sdp": ...} and <peer id> {"ice": ...} lines, and ERROR ... lines report server-side failures. The server always offers and the client answers.

A socket cut while the app's media still runs (resumable) reopens at once with the same resume key: the server, which holds a cut client's session for a few seconds, answers RESUMED <peer id> and the session carries on, the peer connection untouched (onresumed); a plain HELLO (the hold ran out, or a server that holds none) starts a new session as after any drop.

A failed or dropped connection retries RETRY_FIRST_MS later, each further failure twice as far out up to RETRY_MAX_MS; the fourth consecutive failure hands over to onfatalretry (or reloads the page) so the browser re-runs HTTP authentication.

Classes

WebRTCSignaling

Defined in: lib/signaling.js:72

Connection to the signaling server, delivering SDP and ICE to callbacks.

Callbacks are assigned as properties: onstatus, ondebug, and onerror receive messages, onsdp an RTCSessionDescription, onice an RTCIceCandidate, ondisconnect whether the app should reconnect, onshowalert a reason to show the user, onfatalretry replaces the page reload after repeated failures, resumable says whether a cut socket's session is worth resuming, and onresumed follows a resume.

Constructors

Constructor
new WebRTCSignaling(
   server, 
   client_type, 
   client_slot, 
   client_strict_viewer, 
   client_token, 
   display_id, 
   display_position
): WebRTCSignaling;

Defined in: lib/signaling.js:87

Parameters
ParameterTypeDescription
serverURLSignaling WebSocket URL.
client_typestring'controller' or 'viewer'.
client_slotnumberClient slot the server assigns per display.
client_strict_viewerbooleanWhether a viewer may never gain control.
client_tokenstringSecure-mode session token; the server matches it against the active mouse+keyboard token to grant a viewer read-write collaboration.
display_idstringDisplay this client drives, 'primary' by default; the server scopes controller and slot uniqueness per display so a secondary display never evicts the primary.
display_positionstringWhere a secondary display sits relative to the primary in the extended desktop, 'right' by default.
Returns

WebRTCSignaling

Properties

capabilities
capabilities: () => Promise<string[]>;

Defined in: lib/signaling.js:98

Answers, before the hello, which codec names this engine decodes at 4:4:4, so the server offers 4:2:0 to a client without them rather than a profile it paints nothing of; unset, the hello says nothing and the server takes the client at its word.

Returns

Promise<string[]>

tenBitCapabilities
tenBitCapabilities: () => Promise<string[]>;

Defined in: lib/signaling.js:107

Answers, before the hello, which formats this engine decodes at 10 bits, a codec name for 4:2:0 and the name with 444 after it for 4:4:4, so the server offers 8 bits to a client without them; unset, the hello says nothing.

Returns

Promise<string[]>

pageSize
pageSize: () => number[];

Defined in: lib/signaling.js:114

Returns the [width, height] the page's first resize will ask for, which the server starts the primary's capture at, or null where the page sends none; unset, the hello says nothing.

Returns

number[]

peer_id
peer_id: number;

Defined in: lib/signaling.js:117

Local peer id, set by the WebRTC client before connect.

onstatus
onstatus: (arg0) => void;

Defined in: lib/signaling.js:123

Parameters
ParameterType
arg0string
Returns

void

onfatalretry
onfatalretry: () => void;

Defined in: lib/signaling.js:130

Called instead of the page reload after repeated connect failures, so the app may inspect the endpoint before reloading.

Returns

void

onerror
onerror: (arg0) => void;

Defined in: lib/signaling.js:133

Parameters
ParameterType
arg0string
Returns

void

ondebug
ondebug: (arg0) => void;

Defined in: lib/signaling.js:136

Parameters
ParameterType
arg0string
Returns

void

onice
onice: (arg0) => void;

Defined in: lib/signaling.js:139

Parameters
ParameterType
arg0RTCIceCandidate
Returns

void

onsdp
onsdp: (arg0) => void;

Defined in: lib/signaling.js:142

Parameters
ParameterType
arg0RTCSessionDescription
Returns

void

ondisconnect
ondisconnect: (arg0) => void;

Defined in: lib/signaling.js:145

Called with whether the app should reconnect.

Parameters
ParameterType
arg0boolean
Returns

void

resumable
resumable: () => boolean;

Defined in: lib/signaling.js:148

Whether the session of a cut socket is worth resuming (its media runs on).

Returns

boolean

onresumed
onresumed: () => void;

Defined in: lib/signaling.js:151

Called once the session of a cut socket carries on over a new one.

Returns

void

resume_key
resume_key: string;

Defined in: lib/signaling.js:154

The key the hello names; a new session gets a new one.

state
state: string;

Defined in: lib/signaling.js:161

'disconnected', 'connecting', or 'connected'.

retry_count
retry_count: number;

Defined in: lib/signaling.js:164

currRes
currRes: number[];

Defined in: lib/signaling.js:195

peer_type
peer_type: string;

Defined in: lib/signaling.js:198

client_type
client_type: string;

Defined in: lib/signaling.js:201

'viewer' or 'controller'.

server_peer_id
server_peer_id: string;

Defined in: lib/signaling.js:204

client_slot
client_slot: number;

Defined in: lib/signaling.js:207

client_strict_viewer
client_strict_viewer: boolean;

Defined in: lib/signaling.js:210

client_token
client_token: string;

Defined in: lib/signaling.js:213

display_id
display_id: string;

Defined in: lib/signaling.js:216

display_position
display_position: string;

Defined in: lib/signaling.js:219

onshowalert
onshowalert: (arg0) => void;

Defined in: lib/signaling.js:222

Parameters
ParameterType
arg0string
Returns

void

Methods

retry()
retry(): void;

Defined in: lib/signaling.js:331

Starts the retry cycle over, for an app whose onfatalretry found the server not answering: the next connect on the delay the failures so far set, and the next cycle ending in onfatalretry again.

Returns

void

connect()
connect(): void;

Defined in: lib/signaling.js:472

Opens the signaling socket; registration, the session request, and the SDP and ICE exchange follow from the socket events.

Returns

void

reconnect()
reconnect(): void;

Defined in: lib/signaling.js:496

Starts a new session, under a new resume key, in place of one whose media path failed while this socket stayed up, or one whose hold on the server ran out before a resume: the socket is closed without waiting for its close (which a dead path can hold back for a long time), whatever it still reports is ignored, among it the 4001 the server's newest-wins sends a holder it had not reaped yet, and ondisconnect(true) has the app reconnect as after a server-side drop.

Returns

void

disconnect()
disconnect(): void;

Defined in: lib/signaling.js:511

Closes the socket; the close is reported as ondisconnect(false), not as a drop.

Returns

void

sendICE()
sendICE(ice): void;

Defined in: lib/signaling.js:520

Sends a local ICE candidate to the server peer.

Parameters
ParameterTypeDescription
iceRTCIceCandidate-
Returns

void

sendSDP()
sendSDP(sdp): void;

Defined in: lib/signaling.js:529

Sends the local description (the answer) to the server peer.

Parameters
ParameterTypeDescription
sdpRTCSessionDescription-
Returns

void

Functions

newResumeKey()

function newResumeKey(): string;

Defined in: lib/signaling.js:54

A secret naming the page's session to the server, which resumes it after a cut.

Returns

string