Selkies

lib/mode-switch

The transport switch the dashboard runs, from its mode menu and from the notice the WebRTC core raises when its media path keeps failing.

Functions

switchStreamMode()

function switchStreamMode(mode): Promise<boolean>;

Defined in: lib/mode-switch.js:34

Asks the server to swap transports through /api/switch, then posts mode so the core reloads into it.

window.__selkiesModeSwitching is set before the request, because the server tears the old peer down before it answers and the core would otherwise start recovering the connection the switch replaces. The request carries this client's own session token, which a controller's is enough for; a stored master token overrides it, and where neither is accepted a 401 prompts for the master token once, keeps it in sessionStorage and retries, dropping one the server rejects so the next attempt re-prompts. A viewer is refused 403 and is asked nothing. A failed switch clears the flag again, since no reload follows and a kept flag would hide a real disconnect.

Parameters

ParameterTypeDescription
modestringwebrtc or websockets.

Returns

Promise<boolean>

Whether the server switched.