Selkies
Developer ReferenceWeb client coreLib

lib/util

Helpers shared by the streaming cores and both dashboards: a small FIFO queue, the human-readable labels for wire values, the decodability checks that keep a client from asking for a stream it cannot play, and the route prefix and localStorage namespace every caller derives the same way.

Classes

Queue

Defined in: lib/util.js:16

A FIFO queue over an array.

Constructors

Constructor
new Queue(...elements): Queue;

Defined in: lib/util.js:18

Parameters
ParameterTypeDescription
...elementsany[]Initial items, enqueued in order.
Returns

Queue

Properties

items
items: any[];

Defined in: lib/util.js:20

Methods

enqueue()
enqueue(...elements): void;

Defined in: lib/util.js:26

Parameters
ParameterTypeDescription
...elementsany[]Items appended in order.
Returns

void

dequeue()
dequeue(count?): any;

Defined in: lib/util.js:35

Removes the oldest count items.

Parameters
ParameterTypeDefault valueDescription
count?number1How many items to drop.
Returns

any

The oldest of the removed items.

size()
size(): number;

Defined in: lib/util.js:40

Returns

number

isEmpty()
isEmpty(): boolean;

Defined in: lib/util.js:45

Returns

boolean

toArray()
toArray(): any[];

Defined in: lib/util.js:50

Returns

any[]

A copy of the items, oldest first.

remove()
remove(element): void;

Defined in: lib/util.js:55

Removes the first occurrence of element.

Parameters
ParameterType
elementany
Returns

void

find()
find(element): boolean;

Defined in: lib/util.js:61

Parameters
ParameterType
elementany
Returns

boolean

Whether element is queued.

clear()
clear(): void;

Defined in: lib/util.js:66

Drops every item.

Returns

void

Variables

DISPLAY_LABELS

const DISPLAY_LABELS: object;

Defined in: lib/util.js:81

Human-readable names for the wire values surfaced in UIs (transport modes, encoders, rate-control modes). The raw values are what the server APIs speak and stay untouched; unknown values fall through unchanged so new wire values render as-is. Locale-invariant technical terms, so they live here once rather than in every dashboard's translation dictionaries.

Type Declaration

websockets
websockets: string = "WebSockets";
webrtc
webrtc: string = "WebRTC";
h264enc
h264enc: string = "H.264";
h265enc
h265enc: string = "H.265";
vp8enc
vp8enc: string = "VP8";
vp9enc
vp9enc: string = "VP9";
av1enc
av1enc: string = "AV1";
h264enc-striped
h264enc-striped: string = "H.264 (Striped)";
jpeg
jpeg: string = "JPEG (Striped)";
cbr
cbr: string = "CBR (Constant Bitrate)";
crf
crf: string = "CRF (Constant Quality)";
auto
auto: string = "Auto";
h264
h264: string = "H.264";
h265
h265: string = "H.265";
vp8
vp8: string = "VP8";
vp9
vp9: string = "VP9";
av1
av1: string = "AV1";
mjpeg
mjpeg: string = "MJPEG";

decoderSupportReady

const decoderSupportReady: Promise<{
}>;

Defined in: lib/util.js:164

Resolves once every codec has been asked of the decoder. Menus built before it resolves offer every codec an engine with WebCodecs might play, and are rebuilt from the answer.


h264FramingReady

const h264FramingReady: Promise<string>;

Defined in: lib/util.js:181

How this engine's VideoDecoder takes H.264: annexb where a key frame in Annex B form decodes (Chromium, Firefox), avcc where it is refused and an avcC description with length-prefixed NAL units is needed instead (WebKit). Asked once, of a 16x16 key frame, in a worker so a slow refusal never holds the page; annexb without WebCodecs or when nothing answers.


isMobileClient

const isMobileClient: boolean;

Defined in: lib/util.js:362

Whether the client is touch-first: its primary pointer is coarse. True on phones and tablets, false on desktops -- including touch-screen laptops, whose primary pointer is still the pointing device. The form factor is fixed for the life of the document, so it is resolved once and available to every first render; a touch-capable device this misses is still caught by the first touchstart.

Functions

displayLabel()

function displayLabel(value): string;

Defined in: lib/util.js:106

Parameters

ParameterTypeDescription
valuestringA wire value.

Returns

string

Its display label, or the value itself when it has none.


decoderAccepts()

function decoderAccepts(
   codec, 
   width, 
   height
): Promise<boolean>;

Defined in: lib/util.js:124

Whether a VideoDecoder here accepts codec at width x height. False without WebCodecs, and when the engine throws on the question.

Parameters

ParameterTypeDescription
codecstringA WebCodecs codec string.
widthnumber-
heightnumber-

Returns

Promise<boolean>


h264Framing()

function h264Framing(): string;

Defined in: lib/util.js:214

Returns

string

The framing h264FramingReady settled on; annexb until it has.


canDecodeEncoder()

function canDecodeEncoder(encoder): boolean;

Defined in: lib/util.js:227

Whether this engine can play an encoder on the WebSocket transport: every video mode decodes through WebCodecs' VideoDecoder, whose answer per codec is read once it is in, while jpeg (striped JPEG painted through createImageBitmap) needs nothing. An engine without WebCodecs therefore still streams: the core's pre-flight pins jpeg instead of failing, and the settings offer nothing it cannot play. The WebRTC transport decodes in the browser's media stack and is not subject to this.

Parameters

ParameterTypeDescription
encoderstringAn encoder wire value.

Returns

boolean


canReceiveEncoder()

function canReceiveEncoder(encoder): boolean;

Defined in: lib/util.js:246

Whether this engine's own WebRTC stack receives an encoder's codec, from RTCRtpReceiver.getCapabilities; an engine that cannot answer the question is given the benefit of the doubt, and the server's negotiation fallback answers a codec it declines.

Parameters

ParameterTypeDescription
encoderstringAn encoder wire value.

Returns

boolean


canPlayEncoder()

function canPlayEncoder(encoder, webrtc): boolean;

Defined in: lib/util.js:266

Whether this engine plays an encoder on a transport: canDecodeEncoder on WebSockets, canReceiveEncoder on WebRTC. A menu lists what it cannot play disabled and marked, so a missing option reads as the browser's limit and never as the server's.

Parameters

ParameterTypeDescription
encoderstringAn encoder wire value.
webrtcbooleanWhether the transport is WebRTC.

Returns

boolean


canDecodeFullColor()

function canDecodeFullColor(codec?): Promise<boolean>;

Defined in: lib/util.js:287

Whether this engine's VideoDecoder will take codec at full color (4:4:4).

Engines differ on the 4:4:4 profiles (High 4:4:4 Predictive, HEVC RExt, VP9 profile 1), and one whose decoder lacks them cannot show the stream at all rather than showing it worse, so full color is asked of the decoder before it is asked of the server. Which engines have them changes with their releases, which is why this probes instead of naming them. The profile is the whole question, so it is asked with the constraint bits the encoders emit, at the smallest frame the level allows, since a level is a ceiling and a size beyond it is a pair an implementation may reject on its own. What a real stream is decoded with comes from its key frame's parameter sets instead.

Parameters

ParameterTypeDefault valueDescription
codec?string"h264"The codec name, h264 by default.

Returns

Promise<boolean>

False for a codec without 4:4:4, and where there is no VideoDecoder at all.


fullColorDecoded()

function fullColorDecoded(codec): boolean;

Defined in: lib/util.js:308

What canDecodeFullColor answered for codec, for a decision that cannot wait on the probe: undefined while it is still out or was never asked.

Parameters

ParameterTypeDescription
codecstringThe codec name.

Returns

boolean


getRoutePrefix()

function getRoutePrefix(): string;

Defined in: lib/util.js:317

Directory this document is served from, without a trailing slash ('' at the server root). Every request the client builds hangs off it, so a deployment reverse-proxied under a subfolder reaches its own routes, and an iframed client reads its own path instead of the frame's.

Returns

string

The path prefix, e.g. /desk.


getStorageAppName()

function getStorageAppName(): string;

Defined in: lib/util.js:331

The localStorage namespace every stored key is prefixed with.

Origin and pathname only, not the full URL: a per-session ?token= must not mint a new namespace on each connect. Cores and dashboards share one prefix, so this derivation is the single one they all call.

Returns

string

Sanitized namespace, empty outside a browser.


isMacDesktop()

function isMacDesktop(): boolean;

Defined in: lib/util.js:346

macOS proper, a narrower question than the Mac family navigator.platform names: an iPad in its desktop-class default reports MacIntel like a Mac does, and its touch points are what tell the two apart. navigator.platform decides and the client hint is only a fallback for an engine that has dropped the deprecated field, since the question is which pointer acceleration curve the OS applies, not which brand the browser reports.

Returns

boolean


isCaptureRefusal()

function isCaptureRefusal(error): boolean;

Defined in: lib/util.js:374

Whether a capture the server asked for failed for good: permission withheld, or no getUserMedia at all. A busy camera or an unmet constraint may clear by the next demand.

Parameters

ParameterTypeDescription
erroranyThe rejection from getUserMedia, or the capture's own error.

Returns

boolean

True where asking again could not succeed.

References

codecOfEncoder

Re-exports codecOfEncoder


codecCarriesFullColor

Re-exports codecCarriesFullColor

On this page

Edit on GitHub