Skip to main content

Class: Vindral

Represents a Vindral client instance

The most essential methods when using the Vindral class are:

  • play() - connects and starts playing; call it from a user gesture to activate audio on browsers that require one
  • attach() - to attach the Vindral video view to the DOM so that users can see it
  • unload() - unloads the instance, it's very important that this is called when cleaning up the Vindral instance, otherwise background timers may leak.

The Vindral instance will emit a variety of events during its lifetime. Use .on("event-name", callback) to listen to these events. See PublicVindralEvents for the event types that can be emitted.

typescript
// minimal configuration of a Vindral client instance
const instance = new Vindral({
url: "https://lb.cdn.vindral.com",
channelId: "vindral_demo1_ci_099ee1fa-80f3-455e-aa23-3d184e93e04f",
})

// Will be called when timed metadata is received
instance.on("metadata", console.log)

// Will be called when a user interaction is needed to activate audio
instance.on("needs user input", console.log)

// Start connecting to the cdn and playing
instance.play()

// Attach the video view to the DOM
instance.attach(document.getElementById("root"))

// When done with the instance
instance.unload()

Extends​

Properties​

pictureInPicture​

readonly pictureInPicture: object

Picture in picture

enter()​

enter: () => Promise<void>

Enters picture in picture

Returns​

Promise<void>

a promise that resolves if successful

exit()​

exit: () => Promise<void>

Exits picture in picture

Returns​

Promise<void>

a promise that resolves if successful

isActive()​

isActive: () => boolean

returns whether picture in picture is currently active

Returns​

boolean

isSupported()​

isSupported: () => boolean

returns whether picture in picture is supported

Returns​

boolean

Accessors​

abrEnabled​

Get Signature​

get abrEnabled(): boolean

Whether ABR is currently enabled

Returns​

boolean

Set Signature​

set abrEnabled(enabled): void

Enable or disable ABR

The client will immediatly stop changing renditon level based on QoS metrics

Note: It is strongly recommended to keep this enabled as it can severly increase the number of buffering events for viewers.

Parameters​
enabled​

boolean

Returns​

void


audioBitRate​

Get Signature​

get audioBitRate(): number

The current average audio bit rate in bits/s

Returns​

number


audioBufferedRanges​

Get Signature​

get audioBufferedRanges(): readonly TimeRange[]

The time ranges buffered for audio. The ranges are specified in milliseconds.

Returns​

readonly TimeRange[]


bufferFullness​

Get Signature​

get bufferFullness(): number

The current buffer fullness as a floating point value between 0-1, where 1 is full and 0 i empty.

Returns​

number


channelCurrentTime​

Get Signature​

get channelCurrentTime(): number

Current time for the channel. This is the actual stream time, passed on from your ingress. Integer overflow could make this value differ from your encoder timestamps if it has been rolling for more than 42 days with RTMP as target.

Note: This is not normalized between channels, thus it can make jumps when switching channels

Returns​

number


channelId​

Get Signature​

get channelId(): string

The current channelId

Returns​

string

Set Signature​

set channelId(channelId): void

Set the current channelId

Possible channels to set are available from channels

Note that the following scenarios are not possible right now:

  • switching channel from a channel with audio to a channel without audio (unless audio only mode is active)
  • switching channel from a channel with video to a channel without video (unless video only mode is active)
Parameters​
channelId​

string

Returns​

void


channels​

Get Signature​

get channels(): readonly Channel[]

Channels that can be switched between

Returns​

readonly Channel[]


connectionState​

Get Signature​

get connectionState(): Readonly<ConnectionState>

The current connection state

Returns​

Readonly<ConnectionState>


currentRenditionLevel​

Get Signature​

get currentRenditionLevel(): Readonly<RenditionLevel> | undefined

The current rendition level

Returns​

Readonly<RenditionLevel> | undefined


currentTime​

Get Signature​

get currentTime(): number

Local current time normalized between all channels in the channel group

Returns​

number


isSwitchingRenditionLevel​

Get Signature​

get isSwitchingRenditionLevel(): boolean

True if the client is currently switching from one rendition level to another

Returns​

boolean


language​

Get Signature​

get language(): string | undefined

The current language

Returns​

string | undefined

Set Signature​

set language(language): void

Set the current language

Parameters​
language​

string | undefined

Returns​

void


languages​

Get Signature​

get languages(): readonly string[]

Languages available

Returns​

readonly string[]


maxAudioBitRate​

Get Signature​

get maxAudioBitRate(): number

The max audio bit rate that will be subscribed to

Note: Returns Number.MAX_SAFE_INTEGER if no limits have been set

Returns​

number

Set Signature​

set maxAudioBitRate(bitRate): void

Set max audio bit rate that will be subscribed to

Note: If ABR is disabled, setting this will make the client instantly subscribe to this bit rate

Parameters​
bitRate​

number

Returns​

void


maxSize​

Get Signature​

get maxSize(): Size

Max size that will be subscribed to

Returns​

Size

Set Signature​

set maxSize(size): void

Set max size that will be subscribed to

Note: If ABR is disabled, setting this will make the client instantly subscribe to this size

Parameters​
size​

Size

Returns​

void


maxVideoBitRate​

Get Signature​

get maxVideoBitRate(): number

The max video bit rate that will be subscribed to

Note: Returns Number.MAX_SAFE_INTEGER if no limits have been set

Returns​

number

Set Signature​

set maxVideoBitRate(bitRate): void

Set max video bit rate that will be subscribed to

Note: If ABR is disabled, setting this will make the client instantly subscribe to this bitrate

Parameters​
bitRate​

number

Returns​

void


media​

Get Signature​

get media(): Media

Which media type is currently being played

Returns​

Media


muted​

Get Signature​

get muted(): boolean

Whether the playback is muted or not

Returns​

boolean

Set Signature​

set muted(muted): void

Set playback to muted/unmuted

Parameters​
muted​

boolean

Returns​

void


playbackLatency​

Get Signature​

get playbackLatency(): number | undefined

The estimated playback latency based on target buffer time, the connection rtt and local playback drift

Returns​

number | undefined


playbackState​

Get Signature​

get playbackState(): Readonly<PlaybackState>

The current playback state

Returns​

Readonly<PlaybackState>


playbackWallclockTime​

Get Signature​

get playbackWallclockTime(): number | undefined

The estimated utc timestamp (in ms) for the playhead.

Returns​

number | undefined


renditionLevels​

Get Signature​

get renditionLevels(): readonly RenditionLevel[]

The rendition levels available.

Returns​

readonly RenditionLevel[]


serverEdgeTime​

Get Signature​

get serverEdgeTime(): number | undefined

Estimated live edge time for the current channel

Returns​

number | undefined


serverWallclockTime​

Get Signature​

get serverWallclockTime(): number | undefined

Returns​

number | undefined

Estimated wallclock time on the edge server in milliseconds


sizeBasedResolutionCapEnabled​

Get Signature​

get sizeBasedResolutionCapEnabled(): boolean

Whether user bandwidth savings by capping the video resolution to the size of the video element is enabled

Returns​

boolean

Set Signature​

set sizeBasedResolutionCapEnabled(enabled): void

Enables or disables user bandwidth savings by capping the video resolution to the size of the video element.

Parameters​
enabled​

boolean

Returns​

void


targetBufferTime​

Get Signature​

get targetBufferTime(): number

The current target buffer time in milliseconds.

Initially, this will always be equal to minBufferTime. Only when using a separate maxBufferTime, the targetBufferTime will be able to vary between min and max.

Returns​

number

Set Signature​

set targetBufferTime(bufferTimeMs): void

Set the current target buffer time in milliseconds.

Note that setting this will not respect min/max buffer time values. For instance with { minBufferTime: 500, maxBufferTime: 3000 }, you can still set targetBufferTime to 100 ms. The dynamic buffer will still work in respect to the originally set values when needed. Therefore we recommend setting targetBufferTime within that range for consistancy if using both min/max.

Parameters​
bufferTimeMs​

number

Returns​

void


targetRenditionLevel​

Get Signature​

get targetRenditionLevel(): Readonly<RenditionLevel> | undefined

The target rendition level that the client is currently switching to

Returns​

Readonly<RenditionLevel> | undefined


textTrack​

Get Signature​

get textTrack(): string | undefined

Get the active text track

Returns​

string | undefined

Set Signature​

set textTrack(label): void

Set the active text track

Parameters​
label​

string | undefined

Returns​

void


textTracks​

Get Signature​

get textTracks(): string[]

Get the available text tracks

Returns​

string[]


uptime​

Get Signature​

get uptime(): number

How long in milliseconds since the instance was created

Returns​

number


videoBitRate​

Get Signature​

get videoBitRate(): number

The current average video bit rate in bits/s

Returns​

number


videoBufferedRanges​

Get Signature​

get videoBufferedRanges(): readonly TimeRange[]

The time ranges buffered for video. The ranges are specified in milliseconds.

Returns​

readonly TimeRange[]


videoKeyframeTimestamps​

Get Signature​

get videoKeyframeTimestamps(): readonly number[]

The timestamps (in milliseconds) of video keyframes currently in the buffer.

Returns​

readonly number[]


volume​

Get Signature​

get volume(): number

The current volume. Note that if the playback is muted volume can still be set.

Returns​

number

Set Signature​

set volume(volume): void

Set the current volume. Setting this to 0 is not equivalent to muting the audio. Setting this to >0 is not equivalent to unmuting the audio.

Note that setting volume is not allowed on iPadOS and iOS devices. This is an OS/browser limitation on the video element.

Read more about it on Apple docs for iOS-Specific Considerations. The following section is the important part: On iOS devices, the audio level is always under the user's physical control. The volume property is not settable in JavaScript. Reading the volume property always returns 1.

Parameters​
volume​

number

The volume to set. A floating point value between 0-1.

Returns​

void

Methods​

attach()​

attach(container): void

Attaches the video view to a DOM element. The Vindral video view will be sized to fill this element while maintaining the correct aspect ratio.

Parameters​

container​

HTMLElement

the container element to append the video view to. Often a div element.

Returns​

void


connect()​

connect(): void

Returns​

void

Deprecated​

since 3.0.0 Use play instead. Connects to the configured channel and starts streaming


getApiClient()​

getApiClient(): ApiClient

The API client for calls to the public available endpoints of the Vindral Live CDN.

Returns​

ApiClient


getCastOptions()​

getCastOptions(): Options

Get options that can be used for CastSender

Returns​

Options


getOptions()​

getOptions(): Options

Get active Vindral Options

Returns​

Options


getStatistics()​

getStatistics(): Statistics

This method collects a statistics report from internal modules. While many of the report's properties are documented, the report may also contain undocumented properties used internally or temporarily for monitoring and improving the performance of the service.

Use undocumented properties at your own risk.

Returns​

Statistics


getThumbnailUrl()​

getThumbnailUrl(): string

Get url for fetching thumbnail. Note that fetching thumbnails only works for an active channel.

Returns​

string


hasListeners()​

hasListeners<T>(eventName): boolean

Check whether there are any listeners registered for the given event.

Type Parameters​

T​

T extends keyof PublicVindralEvents

Parameters​

eventName​

T

Returns​

boolean

Inherited from​

Emitter.hasListeners


off()​

Call Signature​

off<T>(eventName, fn): void

Remove an event listener from eventName

Type Parameters​
T​

T extends "initialized media"

Parameters​
eventName​

T

fn​

() => EventListenerReturnType

Returns​

void

Inherited from​

Emitter.off

Call Signature​

off<T>(eventName, fn): void

Remove an event listener from eventName

Type Parameters​
T​

T extends "error" | "channels" | "context switch" | "metadata" | "server wallclock time" | "needs user input" | "buffer state event" | "playback state" | "volume state" | "languages" | "connection state" | "channel switch" | "language switch" | "rendition levels" | "rendition level" | "text tracks" | "is live" | "channel switch failed" | "timeshift info" | "cmaf fragment"

Parameters​
eventName​

T

fn​

(args) => EventListenerReturnType

Returns​

void

Inherited from​

Emitter.off


on()​

Call Signature​

on<T>(eventName, fn): void

Add an event listener to eventName

Event listeners may optionally return a "defer function" that will be called once all other listeners have been called. This is useful when one listener may want everone to have reacted to an event before calling something.

Type Parameters​
T​

T extends "initialized media"

Parameters​
eventName​

T

fn​

() => void

Returns​

void

Inherited from​

Emitter.on

Call Signature​

on<T>(eventName, fn): void

Add an event listener to eventName

Event listeners may optionally return a "defer function" that will be called once all other listeners have been called. This is useful when one listener may want everone to have reacted to an event before calling something.

Type Parameters​
T​

T extends "error" | "channels" | "context switch" | "metadata" | "server wallclock time" | "needs user input" | "buffer state event" | "playback state" | "volume state" | "languages" | "connection state" | "channel switch" | "language switch" | "rendition levels" | "rendition level" | "text tracks" | "is live" | "channel switch failed" | "timeshift info" | "cmaf fragment"

Parameters​
eventName​

T

fn​

(args) => void

Returns​

void

Inherited from​

Emitter.on


once()​

Call Signature​

once<T>(eventName, fn): void

Add an event listener to eventName that will be called once only

Event listeners may optionally return a "defer function" that will be called once all other listeners have been called. This is useful when one listener may want everone to have reacted to an event before calling something.

Type Parameters​
T​

T extends "initialized media"

Parameters​
eventName​

T

fn​

() => void

Returns​

void

Inherited from​

Emitter.once

Call Signature​

once<T>(eventName, fn): void

Add an event listener to eventName that will be called once only

Event listeners may optionally return a "defer function" that will be called once all other listeners have been called. This is useful when one listener may want everone to have reacted to an event before calling something.

Type Parameters​
T​

T extends "error" | "channels" | "context switch" | "metadata" | "server wallclock time" | "needs user input" | "buffer state event" | "playback state" | "volume state" | "languages" | "connection state" | "channel switch" | "language switch" | "rendition levels" | "rendition level" | "text tracks" | "is live" | "channel switch failed" | "timeshift info" | "cmaf fragment"

Parameters​
eventName​

T

fn​

(args) => void

Returns​

void

Inherited from​

Emitter.once


pause()​

pause(): void

Pauses the stream. Call .play() to resume playback again.

Returns​

void


play()​

play(): void

Start playing the stream.

This method also activates audio or video on web browsers that require a user gesture to enable media playback. The Vindral instance will emit a "needs user input" event to indicate when this is needed. But it is also safe to pre-emptively call this if it is more convenient - such as in cases where the Vindral instance itself is created in a user input event.

Note: In most browsers this method needs to be called within an user-input event handler, such as an onclick handler in order to activate audio. Most implementations call this directly after constructing the Vindral instance once in order to start playing, and then listen to a user-event in order to allow audio to be activated.

Note 2: Even if you pre-emptively call this it is still recommended to listen to "needs user input" and handle that event gracefully.

Returns​

void


reset()​

reset(): void

Reset the event emitter

Returns​

void

Inherited from​

Emitter.reset


unload()​

unload(): Promise<void>

Fully unloads the instance. This disconnects the clients and stops any background tasks. This client instance cannot be used after this has been called.

Returns​

Promise<void>


updateAuthenticationToken()​

updateAuthenticationToken(token): void

Update authentication token on an already established and authenticated connection

Parameters​

token​

string

Returns​

void


updateBufferTimeConfig()​

updateBufferTimeConfig(config): void

Update the dynamic buffer time configuration at runtime. Allows adjusting min and max buffer time without recreating the Vindral instance.

Parameters​

config​
maxBufferTime?​

number

minBufferTime?​

number

Returns​

void


userInput()​

userInput(): void

Returns​

void

Deprecated​

since 3.0.0 Use play instead.

Activates audio or video on web browsers that require a user gesture to enable media playback. The Vindral instance will emit a "needs user input" event to indicate when this is needed. But it is also safe to pre-emptively call this if it is more convenient - such as in cases where the Vindral instance itself is created in a user input event.

Requirements: This method needs to be called within an user-input event handler to function properly, such as an onclick handler.

Note: Even if you pre-emptively call this it is still recommended to listen to "needs user input" and handle that event gracefully.