Selkies

selkies-wr-core

The WebRTC streaming core: one bundled peer connection carrying the video and audio the server encodes, the webcam and microphone uplinks on sendonly transceivers, and a data channel for everything else.

Client to server on the data channel, as text: SETTINGS,{json} (the persisted settings on connect and the passthrough settings later), r,WxH (stream resolution), s,DPI, vb,kbps, ab,bps, _arg_fps,N, _crf,N, _rc,mode, _ebc,bool, cmd,command, kr (release every key), cr (cache-only clipboard fetch), REQUEST_CLIPBOARD, START_VIDEO / STOP_VIDEO (this peer's feed), SET_NATIVE_CURSOR_RENDERING,0|1, vp,originX,originY,scaleX,scaleY (this page's stream box on the user's desktop, relayed to the other displays), the _f,fps and _l,ms client metrics, _stats_video,{json} when the server asked for raw reports, and the chunked clipboard transfer of lib/clipboard-worker-bridge.js. Server to client arrives through the WebRTCClient callbacks: the settings payload, clipboard-msg* messages, cursor and display-config updates, stats, and system actions (reload, mk_access,0|1, command_error,text, auth_success,{json} / role_update,{json}, resolution,WxH, video_declined,mime, capture_demand,<subject>,0|1, and the pointer, echo trackpad mode asks for with _pointer_echo,0|1, lib/input.js).

The page hash selects the role: none is the controller, #shared a strict viewer, #playerN a viewer with gamepad slot N, and #display2-<position> the secondary display page, which streams its own region of the extended desktop and keeps its per-display settings under _display2 keys. Signaling scopes controller and slot uniqueness per display id, the server runs one pipeline per display, and the position rides the connect metadata.

Contract with the dashboards. Globals published on window: selkiesLogs (capped log ring buffers), fps, displayRefreshRate (the display's measured refresh, lib/display-refresh.js; null until measured), stream_info, stream_client, and stream_stats (lib/stream-stats.js), currentAudioBufferSize, manualResolution, enable_resize, streamResolutionDiverged, webrtcInput, and every server setting as window[key]. Window messages handled (same origin): setScaleLocally, resetResolutionToWindow, setManualResolution, setUseCssScaling, settings, command, pipelineControl, gamepadControl, clipboardUpdateFromUI, clipboardImageUpdate, clipboardCopySecret, audioDeviceSelected, requestFullscreen, setSynth, showVirtualKeyboard, setAntiAliasing, setUseBrowserCursors, setRawPointerMotion, setTrackpadSpeed, setGamepadRumble, touchinput:trackpad, touchinput:touch, statsOpen, plus the requestFileUpload DOM event. Window messages posted: sidebarButtonStatusUpdate, pipelineStatusUpdate, effectiveCursorState, scalingDpiFollowed, serverSettings, clipboardContentUpdate, fileUpload warnings, trackpadModeUpdate, clientRoleUpdate, displayRefresh (the same refresh), toggleDashboard, toggleTouchGamepad, transportAdvice. The frame rate asked for follows the display's refresh where the stored choice is display or where there is none (requestedStreamFramerate). Flags read: window.__selkiesModeSwitching (a mode switch in progress suppresses the recovery reconnects), window.__selkiesAuthProbe (re-presents the login after an auth drop), window.clipboard_enabled.

Functions

InitUI()

function InitUI(): void;

Defined in: selkies-wr-core.js:139

Injects the stylesheet for the video container, overlay, and status bar. Resolution handlers size and center the video, including an exact-size box larger than the viewport. The container clips it without clamping its size.

Returns

void


webrtc()

function webrtc(): object;

Defined in: selkies-wr-core.js:248

Builds the WebRTC core.

Returns

object

initialize builds the DOM, connects signaling, and opens the peer connection; cleanup tears the session down and resets every session-scoped value.

initialize
initialize: () => void;
Returns

void

cleanup
cleanup: () => void;
Returns

void


dcMessageBudget()

function dcMessageBudget(): number;

Defined in: selkies-wr-core.js:453

Per-message budget on the data channel: the negotiated SCTP maximum message size (the minimum of both ends) where the browser exposes it, else the 256 KiB pre-negotiation standard, capped at 1 MiB to bound per-message buffering, less 512 bytes for the message prefix.

Returns

number


reencodePngOffThread()

function reencodePngOffThread(blob): Promise<Blob>;

Defined in: selkies-wr-core.js:516

PNG-normalizes an image on the worker, which is where the decode and re-encode of a large one belong; the page's own canvas covers a worker that cannot do it.

Parameters

ParameterType
blobany

Returns

Promise<Blob>


safeSetItem()

function safeSetItem(key, value): void;

Defined in: selkies-wr-core.js:599

Writes a key, degrading a full or unavailable store to a warning.

Parameters

ParameterType
keyany
valueany

Returns

void


streamDensity()

function streamDensity(): number;

Defined in: selkies-wr-core.js:620

Stream pixels per CSS pixel this page requests and draws at (lib/stream-density.js).

Returns

number


followStreamDensity()

function followStreamDensity(): void;

Defined in: selkies-wr-core.js:636

Hands the density to the input layer and, on a secondary whose density moved (a HiDPI or UI-scaling change, or on X11 the primary's scale), requests the stream at it again.

Returns

void


getFloatParam()

function getFloatParam(key, default_value): any;

Defined in: selkies-wr-core.js:670

Like getIntParam but keeps fractions: range-bounded settings can be floats.

Parameters

ParameterType
keyany
default_valueany

Returns

any


applyTimestamp()

function applyTimestamp(msg): string;

Defined in: selkies-wr-core.js:715

Prefixes a log line with the wall-clock time.

Parameters

ParameterType
msgany

Returns

string


alignResolution()

function alignResolution(num): number;

Defined in: selkies-wr-core.js:722

Rounds a dimension down to the encoder alignment: 2 (YUV 4:2:0 chroma), or 16 when forced.

Parameters

ParameterType
numany

Returns

number


applyEffectiveCursorSetting()

function applyEffectiveCursorSetting(): void;

Defined in: selkies-wr-core.js:734

Applies the effective cursor-rendering setting: the user preference, or browser cursors forced on when this page is a secondary display or the primary while a secondary is connected, since the server-drawn overlay tracks only one capture region. The dashboard is told the value in force, so its toggle reflects the override.

Returns

void


applyRawPointerMotion()

function applyRawPointerMotion(): void;

Defined in: selkies-wr-core.js:749

Applies the raw pointer motion setting to the input handler.

Returns

void


applyTrackpadSpeed()

function applyTrackpadSpeed(): void;

Defined in: selkies-wr-core.js:758

Applies the trackpad speed to the input handler.

Returns

void


applyGamepadRumble()

function applyGamepadRumble(): void;

Defined in: selkies-wr-core.js:767

Applies the rumble toggle to the input handler.

Returns

void


applyMacCmdAsCtrl()

function applyMacCmdAsCtrl(): void;

Defined in: selkies-wr-core.js:780

Applies the Command-as-Control setting to the input handler.

Returns

void


applyKeyboardShortcuts()

function applyKeyboardShortcuts(): void;

Defined in: selkies-wr-core.js:789

Applies the chord setting to the input handler.

Returns

void


resolvedRawPointerMotion()

function resolvedRawPointerMotion(serverSettings): boolean;

Defined in: selkies-wr-core.js:803

The raw_pointer_motion the deployment implies, off the shared ladder: a locked or operator value, else the client's stored pick, else the platform default (off on macOS). Resolved here because pointer lock is taken from the stream, whether or not a settings panel ever mounts.

Parameters

ParameterTypeDescription
serverSettings{ }The server_settings payload.

Returns

boolean


resolvedMacCmdAsCtrl()

function resolvedMacCmdAsCtrl(serverSettings): boolean;

Defined in: selkies-wr-core.js:815

The mac_cmd_as_ctrl the deployment implies, off the shared ladder. Resolved here for the reason raw pointer motion is: the keyboard is taken from the stream, whether or not a settings panel ever mounts.

Parameters

ParameterTypeDescription
serverSettings{ }The server_settings payload.

Returns

boolean


resolvedCssScaling()

function resolvedCssScaling(serverSettings): boolean;

Defined in: selkies-wr-core.js:831

The use_css_scaling the deployment implies, off the shared ladder: a locked or operator value, else the client's explicit pick, else CSS scaling whenever a resolution is configured (the sanitized payload has just published the server's manual mode and width on window). Resolved here rather than left to a settings panel, which a dashboard may mount only when it is opened; until then the session would stream pixel-perfect against a configuration that says otherwise, on every load.

Parameters

ParameterTypeDescription
serverSettings{ }The server_settings payload.

Returns

boolean


playStream()

function playStream(): void;

Defined in: selkies-wr-core.js:841

Starts playback after the user's gesture and takes the wake lock.

Returns

void


requestWakeLock()

function requestWakeLock(): Promise<void>;

Defined in: selkies-wr-core.js:849

Keeps the screen awake while streaming; a no-op when held or where the API is absent.

Returns

Promise<void>


releaseWakeLock()

function releaseWakeLock(): Promise<void>;

Defined in: selkies-wr-core.js:868

Releases the wake lock if held.

Returns

Promise<void>


reportPageVisibility()

function reportPageVisibility(): void;

Defined in: selkies-wr-core.js:884

Tells the server whether this page's tab shows, once it asked: when its display's owner stays hidden, a visible page beside it owns the display. The hide goes at once too; the server waits out a reloading page's.

Returns

void


clearResumeWatchdog()

function clearResumeWatchdog(): void;

Defined in: selkies-wr-core.js:894

Cancels the resume watchdog.

Returns

void


armResumeWatchdog()

function armResumeWatchdog(): void;

Defined in: selkies-wr-core.js:912

Verifies that frames follow a START_VIDEO or a connect. The resume is one message on a data channel that can close at that very moment, and a lost one is answered with nothing: the peer would stay subscribed to a feed nobody encodes. A player can also miss a session's only key frame (WebKit's GStreamer player sometimes never prerolls on it), and a still screen sends no other: the resend's IDR is one. The element's playback clock is the signal WebRTC has, so the check is whether it advanced past the mark taken here with a picture to show: WebKit's player runs its clock with none.

Returns

void


checkResumed()

function checkResumed(mark): void;

Defined in: selkies-wr-core.js:930

Watchdog tick: resends START_VIDEO while the playback clock has not moved past mark, up to RESUME_WATCHDOG_MAX_ATTEMPTS, then reconnects in place unless a fatal verdict or a mode switch forbids it. A tab hidden again stands the watchdog down, the visibility path owning that state, and so does a stream the server declined, which no resend brings back, a play button waiting on the user's gesture, or video the page has off (its video_on_start setting, or the user's toggle). Each attempt also replays the element, since one the browser paused while the tab was away plays nothing however much RTP arrives.

Parameters

ParameterTypeDescription
marknumberPlayback time when the watchdog was armed.

Returns

void


handleVisibilityChange()

function handleVisibilityChange(): Promise<void>;

Defined in: selkies-wr-core.js:969

Pauses this peer's video feed while the tab is hidden and resumes it on show, re-acquiring the wake lock the browser dropped.

A hidden tab's rendering is throttled anyway, so its encode and bandwidth are waste. STOP_VIDEO and START_VIDEO gate only this peer's RTP sender, and the shared capture stops once every consumer is paused, so viewer pages send them too. The pause is deferred because a navigating document reports hidden just before it unloads and timers never fire in an unloading document, so only a genuine tab-hide sends it. Recovery on resume is the server's IDR (plus PLI); the client sends no keyframe requests, and the resume watchdog verifies frames follow.

Returns

Promise<void>


applyOutputDevice()

function applyOutputDevice(): Promise<void>;

Defined in: selkies-wr-core.js:1010

Routes audio to the preferred output device: the video element carries the bundled audio track, so setSinkId on it moves the audio sink.

Returns

Promise<void>


updateStatusDisplay()

function updateStatusDisplay(): void;

Defined in: selkies-wr-core.js:1032

Shows the sentence-cased status (the internal value stays lower-case for comparisons); once connected, hides it and shows the play button if playback still needs a gesture, unless the page was told its video is declined, whose notice stays.

Returns

void


updateVideoImageRendering()

function updateVideoImageRendering(): void;

Defined in: selkies-wr-core.js:1054

Picks the video's image-rendering: pixelated with anti-aliasing off or at 1:1, auto (smoothed) when scaled. 1:1 is the stream's own size matching the box in device pixels to within the resize alignment (a mode's cell, the 16-pixel aligned request), so a pinned resolution, one not yet realized, or a manual one scaled to fit stays smoothed. Only Chromium takes it: its compositor resamples a smoothed video every frame, which costs a software compositor a frame of latency, while Firefox's draws a nearest-sampled video slower than a smoothed one.

Returns

void


sanitizeAndStoreSettings()

function sanitizeAndStoreSettings(serverSettings): object;

Defined in: selkies-wr-core.js:1099

Applies the server's settings payload to the runtime and reconciles the user's stored overrides against it.

Every value is applied to window[key]; only a genuine user override is persisted. A server value with no stored override is not written to localStorage, so a later server-side change can still be re-pushed, and a locked value is never written into the user's key, where it would masquerade as their pick after an unlock. The override is read under the key the dashboard writes (HiDPI stores as useCssScaling), or an unlocked operator value would win forever. An unlocked operator override with no stored pick is reported back as a change, so it is applied for real: window state alone leaves runtime consumers on their defaults. Ranged settings are parsed as floats: "0.5" read as an int is 0, out of range, and wiped on every connect. Plain values (audio_channels) configure pipelines rather than preferences and stay runtime-only.

Parameters

ParameterTypeDescription
serverSettings{ }The payload's per-key specs.

Returns

object

Corrections the server has to be told about.


receiverTakesVp9FullColor()

function receiverTakesVp9FullColor(): boolean;

Defined in: selkies-wr-core.js:1170

Whether this engine's RTP receiver takes VP9 profile 1, the 4:4:4 profile.

Returns

boolean


settleFullColorSupport()

function settleFullColorSupport(): Promise<void>;

Defined in: selkies-wr-core.js:1190

Turns full color off where this engine cannot decode the codec's 4:4:4 profile over RTP.

Where the decoder has no 4:4:4 profile a full-color stream is not a heavier picture but no picture, so the setting is dropped rather than asked for. The receiver's own capabilities answer for VP9 (profile 1); the decoder probe answers for H.264 and H.265. Written to storage, which is what every payload and the dashboard read, so the toggle shows what the stream is.

Returns

Promise<void>


fullColorDecodable()

function fullColorDecodable(codec): Promise<boolean>;

Defined in: selkies-wr-core.js:1204

Whether this engine decodes the codec's 4:4:4 over WebRTC: the receiver's capabilities for VP9 (profile 1), the decoder probe for H.264 and H.265.

Parameters

ParameterTypeDescription
codecstringA codec name.

Returns

Promise<boolean>


declineUndecodableFullColor()

function declineUndecodableFullColor(): Promise<void>;

Defined in: selkies-wr-core.js:1217

Turns a full color the server announced off again where this engine cannot decode the codec's 4:4:4 over WebRTC, so the stream comes back 4:2:0 on the same codec instead of arriving as one this browser paints nothing of. A locked setting cannot be turned off and is reported once.

Returns

Promise<void>


receiverTakesProfile()

function receiverTakesProfile(codec, profile): boolean;

Defined in: selkies-wr-core.js:1238

Whether this engine's RTP receiver lists codec at an SDP profile-id.

Parameters

ParameterTypeDescription
codecstringA codec name.
profilenumberThe profile id.

Returns

boolean


tenBitDecodable()

function tenBitDecodable(codec, fullcolor): Promise<boolean>;

Defined in: selkies-wr-core.js:1262

Whether this engine decodes the codec at 10 bits over WebRTC: the receiver's capabilities where the profile is one RTP negotiates (VP9 profile 2, or 3 at 4:4:4, H.265 Main 10, and H.264 High 10), the decode of a 10-bit key frame for AV1, whose main profile carries both depths, and for H.264 and H.265 4:4:4, which full color is answered the same way for. Chromium decodes WebRTC AV1 in libwebrtc's dav1d wrapper, which drops every picture deeper than 8 bits ("unhandled bit depth") whatever WebCodecs decodes, so a stream opening at 10 bits never showed a frame there.

Parameters

ParameterTypeDescription
codecstringA codec name.
fullcolorbooleanWhether the stream is 4:4:4.

Returns

Promise<boolean>


streamsFullColor()

function streamsFullColor(codec): boolean;

Defined in: selkies-wr-core.js:1278

Whether the stream on codec is 4:4:4 as far as this page asked for it.

Parameters

ParameterType
codecany

Returns

boolean


settleTenBitSupport()

function settleTenBitSupport(): Promise<void>;

Defined in: selkies-wr-core.js:1285

Turns 10-bit off in storage where this engine cannot decode the codec at 10 bits over RTP, before the first SETTINGS payload, as settleFullColorSupport does for full color.

Returns

Promise<void>


declineUndecodableTenBit()

function declineUndecodableTenBit(): Promise<void>;

Defined in: selkies-wr-core.js:1301

Turns a 10-bit the server announced off again where this engine cannot decode it over WebRTC, so the stream comes back at 8 bits on the same codec. A locked setting cannot be turned off and is reported once.

Returns

Promise<void>


measuredDisplayScale()

function measuredDisplayScale(): number;

Defined in: selkies-wr-core.js:1335

This page's remote pixels per CSS pixel: its decoded buffer over the box drawing it, the ratio a neighbor scales a cross-display drag by (lib/stream-density.js). The requested density stands in until the realized buffer catches up with it.

Returns

number


requestedStreamFramerate()

function requestedStreamFramerate(): number;

Defined in: selkies-wr-core.js:1353

The frame rate this page asks the server for: the stored choice, or the display's own refresh where that is chosen or nothing is (lib/display-refresh.js); null asks for nothing.

Returns

number


followDisplayFramerate()

function followDisplayFramerate(): void;

Defined in: selkies-wr-core.js:1362

Asks the server for the rate requestedStreamFramerate names where it moved: the display measured or remeasured, or the server's span arrived.

Returns

void


applyManualStyle()

function applyManualStyle(
   targetWidth, 
   targetHeight, 
   scaleToFit
): void;

Defined in: selkies-wr-core.js:1471

Sizes and centers the video element for a manual resolution; the exact size is centered too, or a larger viewport would pin the box top-left. Exact is one stream pixel per device pixel, independent of the HiDPI flag, which a manual resolution does not read.

Parameters

ParameterTypeDescription
targetWidthnumberStream width in pixels.
targetHeightnumberStream height in pixels.
scaleToFitbooleanLetterbox into the container instead of showing the exact size.

Returns

void


resetToWindowResolution()

function resetToWindowResolution(targetWidth, targetHeight): void;

Defined in: selkies-wr-core.js:1538

Sizes the video element to the window: the buffer hint in physical pixels, the on-screen box in CSS pixels (styling it with physical pixels overflows the viewport by dpr squared on HiDPI displays), and its image-rendering for the density. The stream the server realizes can be a few pixels off the box (a mode's cell alignment), so the browser scales every frame, a resample Chromium's software compositor pays a frame of latency for when it is smoothed.

Parameters

ParameterTypeDescription
targetWidthnumberWindow width in CSS pixels.
targetHeightnumberWindow height in CSS pixels.

Returns

void


autoDeriveDpi()

function autoDeriveDpi(): number;

Defined in: selkies-wr-core.js:1568

Derives the default scaling_dpi (lib/stream-density.js): from the local display scaling, so remote fonts match local ones, or from a manual resolution, which is a framebuffer of its own that the local screen says nothing about. A stored pick overrides either.

Returns

number


effectiveScalingDpi()

function effectiveScalingDpi(): number;

Defined in: selkies-wr-core.js:1585

The DPI the desktop is asked for: 96 under CSS scaling, where the pick divides the requested resolution instead (lib/stream-density.js).

A manual resolution is the exact framebuffer either way -- a HiDPI toggle must not swing the size the operator asked for -- so there is nothing for the pick to divide there and it governs the desktop, HiDPI or not. Applying it once is not the double scaling that CSS scaling had: the request it would have divided is fixed.

Returns

number


pushScalingDpi()

function pushScalingDpi(): void;

Defined in: selkies-wr-core.js:1590

Sends the desktop the DPI in force.

Returns

void


followDerivedDpi()

function followDerivedDpi(reason): boolean;

Defined in: selkies-wr-core.js:1601

Re-derives scaling_dpi while it sits on its automatic default; a stored value is the dashboard's explicit pick and is left alone. The new value is posted as scalingDpiFollowed so the dashboards show it.

Parameters

ParameterTypeDescription
reasonstringWhat changed, for the log.

Returns

boolean

Whether the derived value moved; the caller pushes it.


maybeFollowDpr()

function maybeFollowDpr(): void;

Defined in: selkies-wr-core.js:1622

Follows a live devicePixelRatio change while scaling_dpi sits on its automatic default, re-deriving and pushing it so the remote UI density matches the display the window is on. Called from the resize handler and the density watcher: an OS scaling change can surface as either, and an emulated one as neither, which only the watcher's poll sees. The video's rendering follows too, since the same stream now meets the box at another scale.

Returns

void


streamResolution()

function streamResolution(width, height): number[];

Defined in: selkies-wr-core.js:1637

The stream resolution sendResolutionToServer asks for width x height, with the density it multiplied them by.

Parameters

ParameterTypeDescription
widthnumber-
heightnumber-

Returns

number[]

The width, the height, and the density.


sendResolutionToServer()

function sendResolutionToServer(width, height): void;

Defined in: selkies-wr-core.js:1653

Requests a stream resolution with the r,WxH message.

A manual resolution is the exact framebuffer and is not multiplied by the device pixel ratio, or a HiDPI toggle would swing it between 1x and 2x; an auto resolution is CSS pixels times dpr unless CSS scaling is on. Both are capped at 4080 so a dpr-2 4K fullscreen never asks for a 7680-wide framebuffer.

Parameters

ParameterTypeDescription
widthnumber-
heightnumber-

Returns

void


enableAutoResize()

function enableAutoResize(): void;

Defined in: selkies-wr-core.js:1674

Follows window resizes with stream resolution requests.

Returns

void


disableAutoResize()

function disableAutoResize(): void;

Defined in: selkies-wr-core.js:1679

Stops following window resizes.

Returns

void


resizeStart()

function resizeStart(): void;

Defined in: selkies-wr-core.js:1697

Debounces window resizes into handleResizeUI.

Returns

void


resizeEnd()

function resizeEnd(): void;

Defined in: selkies-wr-core.js:1707

Runs handleResizeUI once the resize has been quiet for rdelta.

Returns

void


handleResizeUI()

function handleResizeUI(): void;

Defined in: selkies-wr-core.js:1729

Auto-mode resize: requests the window's CSS-pixel size from the server (sendResolutionToServer applies the device pixel ratio) and restyles the element onto it; shared by the debounced resize tail and the reset-to-window path.

A manual preset applied while a debounce is pending is not overwritten when it fires. enable_resize false pins the primary's resolution server-side, so the resize the server ignores is neither requested nor restyled onto; a secondary's stays allowed. The CSS size is clamped so the physical request stays within the 4080 cap and the element box matches what the server realizes.

Returns

void


watchDevicePixelRatio()

function watchDevicePixelRatio(): void;

Defined in: selkies-wr-core.js:1755

Re-runs the auto-resize path when the device pixel ratio changes: a window dragged to a monitor of another density, or an OS scaling change, fires no resize event, and the stream would stay at the old density until the next one. While scaling_dpi sits on its automatic default it is re-derived and pushed too, so the remote UI density follows the display the window is on. A matchMedia resolution query is one-shot at a given dppx, so it is re-armed after each change.

Returns

void


loadLastSessionSettings()

function loadLastSessionSettings(): void;

Defined in: selkies-wr-core.js:1786

Restores the last session's resolution and desktop DPI on connect.

The DPI goes through the server's idempotent set_dpi path, the same one the initial SETTINGS seed takes, so whichever lands first wins. Persisted trackpad mode asks the new channel for the pointer echo it draws from. A manual-mode secondary display reports its size on connect because a secondary lays out from what it reports; a pinned primary (enable_resize false) is styled to the window but keeps the server's resolution.

Returns

void


postSidebarButtonUpdate()

function postSidebarButtonUpdate(): void;

Defined in: selkies-wr-core.js:1811

Posts sidebarButtonStatusUpdate with the state of every pipeline toggle.

Returns

void


setMicrophone()

function setMicrophone(on, askedByServer?): void;

Defined in: selkies-wr-core.js:1830

Starts or stops the microphone uplink and reports the outcome to the sidebar.

Parameters

ParameterTypeDefault valueDescription
onbooleanundefinedThe state asked for.
askedByServer?booleanfalseThe session asked rather than the user, so a refusal latches.

Returns

void


startWebcamCapture()

function startWebcamCapture(askedByServer?): Promise<void>;

Defined in: selkies-wr-core.js:1852

Starts the webcam uplink: the camera track rides the sendonly video transceiver the server reserved in the bundled SDP (the mirror of the microphone), so the browser's own encoder produces the H.264, VP8, VP9, H.265, or AV1 the server's virtual camera decodes, with RTP congestion control and no data-channel framing.

Parameters

ParameterTypeDefault valueDescription
askedByServer?booleanfalseThe session asked rather than the user, so a refusal latches and the next demand does not ask again.

Returns

Promise<void>


stopWebcamCapture()

function stopWebcamCapture(): void;

Defined in: selkies-wr-core.js:1884

Stops the webcam uplink and reports the toggle state.

Returns

void


toggleGamepadConnection()

function toggleGamepadConnection(): boolean;

Defined in: selkies-wr-core.js:1898

Applies the gamepad toggle to the manager; a shared page always polls.

Returns

boolean

Whether polling is on.


handleMessage()

function handleMessage(event): void;

Defined in: selkies-wr-core.js:1929

Handles a same-origin dashboard window message; the module docblock lists the types. A shared page ignores the resolution, command, and clipboard cases: a viewer never drives resolution policy, never reaches the server's command execution path, and never writes its clipboard. A primary whose size the server keeps (enable_resize false) ignores a manual resolution, which the server would refuse.

Parameters

ParameterTypeDescription
eventMessageEvent<any>-

Returns

void


handleSettingsMessage()

function handleSettingsMessage(settings, fromServer?): void;

Defined in: selkies-wr-core.js:2289

Applies a settings payload from the dashboard or the server.

A server-authored payload (the locked and overridden values replayed on every connect) is applied to the runtime but never written to the user's own keys, where it would outlive the lock and masquerade as their pick; only a dashboard-authored payload persists. Settings with no dedicated data-channel opcode ride a SETTINGS passthrough the server applies through handle_update_settings; displayPosition among them moves a secondary page to another side of the primary, and the primary ignores it.

Parameters

ParameterTypeDescription
settings{ }Keys named as the server names them.
fromServer?booleanWhether the server authored the payload.

Returns

void


followDisplaySettings()

function followDisplaySettings(values): void;

Defined in: selkies-wr-core.js:2457

Takes what this page's display streams with (display_settings), which the server sends a page joining a display beside its owner, and the pages of a display another one's pick changed: held for the tab, taken as what this page asks for, and shown in the dashboards.

Parameters

ParameterTypeDescription
values{ }-

Returns

void


sendRespectiveRCvalue()

function sendRespectiveRCvalue(newMode): void;

Defined in: selkies-wr-core.js:2477

Re-sends the parameter the new rate-control mode reads: the bitrate for CBR, the CRF for CRF.

Parameters

ParameterType
newModeany

Returns

void


readDecodedFrame()

function readDecodedFrame(key): void;

Defined in: selkies-wr-core.js:2502

Reads the pixel format the received video decodes to (webrtcDecoder): a VideoFrame of the element's current picture at once, and where the page has MediaStreamTrackProcessor, one frame of a clone of the track, the decoder's own. Once per configuration and again at each opening of the stats, since a decoder can fall back mid-stream; a still screen delivers no frame to the track, so its read is bounded and retried on the next tick.

Parameters

ParameterTypeDescription
keystringThe configuration, codec:WxH.

Returns

void


describeClient()

function describeClient(stats): void;

Defined in: selkies-wr-core.js:2547

This page's half of the stream (window.stream_client) from one getStats() snapshot. It moves only with the stream and costs a few reads, so every tick keeps it current, shut stats included, and a dashboard opening them draws it at once. The path is the pair's kind, relay where either end relays and else the server's candidate type, with the protocol this page reaches its peer or its relay over. The engine is asked about the stream as negotiated, its fmtp line included: its answer for the codec's default profile says nothing of a 4:4:4 profile, which no hardware decoder takes.

Parameters

ParameterTypeDescription
statsanyWebRTCClient.getConnectionStats's result.

Returns

void


sampleStreamStats()

function sampleStreamStats(
   stats, 
   rtt, 
   pc
): void;

Defined in: selkies-wr-core.js:2593

One sample of this page's figures for lib/stream-stats.js, from the same getStats() snapshot the stat watch took: a rate is the change in a cumulative counter since the last sample, a count is counted from the opening, and the first tick after an opening only takes the baseline. A reconnect that replaced the peer connection starts its counters again from zero, so what the old one counted since the opening is carried into the baseline and its first tick only takes the rates' baseline.

Parameters

ParameterTypeDescription
statsanyWebRTCClient.getConnectionStats's result.
rttnumberRound trip in ms.
pcRTCPeerConnectionThe peer connection stats was read from.

Returns

void


enableStatWatch()

function enableStatWatch(): void;

Defined in: selkies-wr-core.js:2692

Starts the stats loop, which reads the peer connection once a second while a dashboard has its stats open or enableWebrtcStatics streams the raw reports to the server as _stats_video, and every STATS_SHUT_MS otherwise, for what it keeps without them: window.fps and currentAudioBufferSize, the figures the metrics loop reports (_f, _l), and window.stream_client (describeClient). An opening is read at once (tickStatsNow) for the baseline, and its first sample follows FIRST_SAMPLE_MS later (sampleStreamStats).

Each tick schedules the next when it ends, so ticks never overlap and double-update the byte baselines; the time window is re-anchored only on success, alongside those baselines, so both cover the same interval. The bandwidth reported is the received throughput (video plus audio), matching the WebSocket server's stat: availableReceiveBandwidth is only the congestion-control estimate and reads far below the real rate on a relay. The audio-buffer gauge is a proxy: the de-jitter depth over the 20 ms Opus frame approximates the frames buffered ahead of playout, since browser-managed audio exposes no frame count. The audio concealment counters (NetEQ) are the RED acceptance metric.

Returns

void


tickStatsNow()

function tickStatsNow(): void;

Defined in: selkies-wr-core.js:2777

Reads the peer connection now, for a dashboard that just opened its stats.

Returns

void


handleWindowFocus()

function handleWindowFocus(): Promise<void>;

Defined in: selkies-wr-core.js:2825

Releases every key server-side and, on Chromium, reads the local clipboard: Firefox and WebKit raise a paste prompt on every focus read, so there the read is driven only by the paste gesture handlers.

Returns

Promise<void>


handleWindowBlur()

function handleWindowBlur(): void;

Defined in: selkies-wr-core.js:2834

Releases every key server-side so none sticks across the blur.

Returns

void


notifyClipboardImageSkip()

function notifyClipboardImageSkip(reason, code): void;

Defined in: selkies-wr-core.js:2844

Tells the dashboard why a clipboard-image upload was skipped, in the fileUpload warning channel transfer warnings use.

Parameters

ParameterTypeDescription
reasonstringHuman-readable reason.
codestringMachine-readable code the dashboard translates.

Returns

void


notifyClipboardImageWriteFailed()

function notifyClipboardImageWriteFailed(error): void;

Defined in: selkies-wr-core.js:2859

Tells the dashboard that a server image never reached the local clipboard. The panel shows nothing of an inbound image but this notice, so a write the browser refuses would otherwise read as the feature not working at all.

Parameters

ParameterTypeDescription
erroranyWhat the write threw.

Returns

void


sendClipboardData()

function sendClipboardData(
   data, 
   mimeType?, 
   onSkip?
): Promise<void>;

Defined in: selkies-wr-core.js:2885

Sends clipboard content to the server in chunks.

Uses the chunked transfer of lib/clipboard-worker-bridge.js, the same wire protocol as the WebSocket core, over the data channel with a drain gate: a multi-MB burst overflows the SCTP send buffer and Chromium closes the channel, taking the session with it. Raw chunks are sized so their base64 fits the data-channel message budget. Only a completed transfer marks the content synced, so a failure leaves it re-sendable.

Parameters

ParameterTypeDefault valueDescription
datastring | ArrayBuffer | Uint8Array<ArrayBufferLike>undefinedText or binary content.
mimeType?string'text/plain'Content type; text is always text/plain.
onSkip?(arg0, arg1) => voidnullCalled with reason and code when nothing is sent.

Returns

Promise<void>


send()

function send(data): void;

Defined in: selkies-wr-core.js:3152

Strict viewers send nothing until collaboration is granted.

Parameters

ParameterType
dataany

Returns

void


applyStartPolicy()

function applyStartPolicy(serverSettings): void;

Defined in: selkies-wr-core.js:3637

Applies the session's start policy from a peer connection's first server_settings payload: the *_on_start settings say which pipelines this page starts with. Only a session owner's primary display page is governed (a shared viewer cannot switch video or audio on, and a second display page exists to show its display), and a pipeline the user already toggled keeps that choice. The server registered this peer with its video and audio senders paused by the same policy, so video and audio off only mirror that here; the microphone and webcam start their uplinks; the gamepad policy seeds a toggle the browser has not persisted.

Parameters

ParameterTypeDescription
serverSettings{ }-

Returns

void


applyRtcConfigAndConnect()

function applyRtcConfigAndConnect(config): void;

Defined in: selkies-wr-core.js:3807

Applies an RTC configuration and opens the connection. Shared by the fetched and the fallback configuration, so a failed TURN fetch still connects: the data channel delivers the server settings, and without it the dashboard never renders its controls or the transport toggle.

Parameters

ParameterType
configany

Returns

void

References

webrtc

Re-exports webrtc

On this page

FunctionsInitUI()Returnswebrtc()ReturnsinitializeReturnscleanupReturnsdcMessageBudget()ReturnsreencodePngOffThread()ParametersReturnssafeSetItem()ParametersReturnsstreamDensity()ReturnsfollowStreamDensity()ReturnsgetFloatParam()ParametersReturnsapplyTimestamp()ParametersReturnsalignResolution()ParametersReturnsapplyEffectiveCursorSetting()ReturnsapplyRawPointerMotion()ReturnsapplyTrackpadSpeed()ReturnsapplyGamepadRumble()ReturnsapplyMacCmdAsCtrl()ReturnsapplyKeyboardShortcuts()ReturnsresolvedRawPointerMotion()ParametersReturnsresolvedMacCmdAsCtrl()ParametersReturnsresolvedCssScaling()ParametersReturnsplayStream()ReturnsrequestWakeLock()ReturnsreleaseWakeLock()ReturnsreportPageVisibility()ReturnsclearResumeWatchdog()ReturnsarmResumeWatchdog()ReturnscheckResumed()ParametersReturnshandleVisibilityChange()ReturnsapplyOutputDevice()ReturnsupdateStatusDisplay()ReturnsupdateVideoImageRendering()ReturnssanitizeAndStoreSettings()ParametersReturnsreceiverTakesVp9FullColor()ReturnssettleFullColorSupport()ReturnsfullColorDecodable()ParametersReturnsdeclineUndecodableFullColor()ReturnsreceiverTakesProfile()ParametersReturnstenBitDecodable()ParametersReturnsstreamsFullColor()ParametersReturnssettleTenBitSupport()ReturnsdeclineUndecodableTenBit()ReturnsmeasuredDisplayScale()ReturnsrequestedStreamFramerate()ReturnsfollowDisplayFramerate()ReturnsapplyManualStyle()ParametersReturnsresetToWindowResolution()ParametersReturnsautoDeriveDpi()ReturnseffectiveScalingDpi()ReturnspushScalingDpi()ReturnsfollowDerivedDpi()ParametersReturnsmaybeFollowDpr()ReturnsstreamResolution()ParametersReturnssendResolutionToServer()ParametersReturnsenableAutoResize()ReturnsdisableAutoResize()ReturnsresizeStart()ReturnsresizeEnd()ReturnshandleResizeUI()ReturnswatchDevicePixelRatio()ReturnsloadLastSessionSettings()ReturnspostSidebarButtonUpdate()ReturnssetMicrophone()ParametersReturnsstartWebcamCapture()ParametersReturnsstopWebcamCapture()ReturnstoggleGamepadConnection()ReturnshandleMessage()ParametersReturnshandleSettingsMessage()ParametersReturnsfollowDisplaySettings()ParametersReturnssendRespectiveRCvalue()ParametersReturnsreadDecodedFrame()ParametersReturnsdescribeClient()ParametersReturnssampleStreamStats()ParametersReturnsenableStatWatch()ReturnstickStatsNow()ReturnshandleWindowFocus()ReturnshandleWindowBlur()ReturnsnotifyClipboardImageSkip()ParametersReturnsnotifyClipboardImageWriteFailed()ParametersReturnssendClipboardData()ParametersReturnssend()ParametersReturnsapplyStartPolicy()ParametersReturnsapplyRtcConfigAndConnect()ParametersReturnsReferenceswebrtc
Edit on GitHub