Skip to content

Interface: ElementContext ​

Given to init, one per element instance.

Properties ​

catalog? ​

readonly optional catalog?: CatalogReader

Set for elements the catalog loads, and inherited by what they load.


client ​

readonly client: MOQtailClient

Always the current client, it changes after a reconnect.


player ​

readonly player: PlayerHandle


signal ​

readonly signal: AbortSignal

Aborted when the instance is destroyed.


tracks ​

readonly tracks: readonly (object & object & object)[]

The tracks this instance was loaded for, empty without a catalog.


worker? ​

readonly optional worker?: object

Set while the player has a worker and the definition's threads allows it.

bridge() ​

bridge(pad): void

Sends them to receive() on the main thread instead. Each worker pad the element takes needs one of the two.

Parameters ​
pad ​

Pad

Returns ​

void

create() ​

create<E>(name, request?): Remote<E>

Creates the engine serveWorker registered as name. Calls on it queue until it exists, and a failure to create it reaches context.fail.

Type Parameters ​
E ​

E extends Engine

Parameters ​
name ​

string

request? ​
options? ​

object

The engine's init.options.

outputs? ​

Pad[]

Source pads of the element, carrying THREAD worker: the engine's init.outputs, in order.

report? ​

(report) => void

The engine's init.report.

transfer? ​

Transferable[]

Transferred with options, for example an OffscreenCanvas.

Returns ​

Remote<E>

has() ​

has(name): boolean

Parameters ​
name ​

string

Returns ​

boolean

inWorker() ​

inWorker(pad): boolean

Whether pad is a worker pad, or a sink pad one feeds.

Parameters ​
pad ​

Pad

Returns ​

boolean

link(pad, engine): void

Sends the items of pad, a sink pad fed by a worker pad, to engine in the worker.

Parameters ​
pad ​

Pad

engine ​

Remote<Engine>

Returns ​

void

Methods ​

attach() ​

attach(element): void

Called by the BaseElement constructor, so the player hears what the instance emits.

Parameters ​

element ​

BaseElement

Returns ​

void


cost() ​

cost(track): Promise<number | undefined>

How many transforms the chain would load to take the pad of the source probe() picks for track to a declared sink. Undefined when none is reached, or an element on the way doesn't supports the track. 0 without declared sinks, or for a source whose definition doesn't say what pad it makes. Worked out from capabilities, not negotiate: a declared transform that declines a pad it could take, as WebCodecs does past its first, still gets transforms loaded for it.

Parameters ​

track ​

Identifiers

Returns ​

Promise<number | undefined>


fail() ​

fail(error): void

Reports a fatal error from outside receive(), such as a decoder's or an engine's.

Parameters ​

error ​

PlayerError

Returns ​

void


load() ​

load<E>(definition, request?): Promise<E>

Returns the existing instance when the same definition and tracks are already loaded.

Type Parameters ​

E ​

E extends BaseElement

Parameters ​

definition ​

ElementDefinition<E>

request? ​

ElementLoadRequest

Returns ​

Promise<E>


probe() ​

probe(identifiers): SourceElementDefinition<SourceElement, readonly (keyof ElementInterfaces)[]> | undefined

The source definition the player would pick for identifiers, as source() does.

Parameters ​

identifiers ​

Identifiers

Returns ​

SourceElementDefinition<SourceElement, readonly (keyof ElementInterfaces)[]> | undefined


release() ​

release(element): Promise<void>

Drops this element's reference to one it loaded; it's destroyed once no holder is left.

Parameters ​

element ​

BaseElement

Returns ​

Promise<void>


switchSource() ​

switchSource(identifiers): SourceElementDefinition<SourceElement, readonly (keyof ElementInterfaces)[]> | undefined

The active plugins' switch source that ranks first for identifiers, as probe() ranks.

Parameters ​

identifiers ​

Identifiers

Returns ​

SourceElementDefinition<SourceElement, readonly (keyof ElementInterfaces)[]> | undefined