Skip to main content

API Reference

Bayes Web Player options

The options given below can be defined when instantiating the Bayes Web Player. You can find the options type here. More options and event callbacks will be added in future iterations of the Bayes Web Player.

NameTypeDescriptionDefault value
autoplaybooleanSwitches autoplay on/offtrue
enableUibooleanDisplays the default set of controls that are shipped with the Bayes Web Playertrue
mutedbooleanStarts the player in a muted statefalse
volumenumberInitial volume50
detachablebooleanEnable or disable the detachable functionality of the playertrue
thumbnailstringThumbnail which is displayed before the stream is playedundefined
watermarkWatermarkOptionsWatermark which is displayed on top of the livestreamundefined
defaultErrorMessagestringError message to be displayed when an error occurs during the livestream"Error occurred while retrieving playlist information. Please try again."
defaultOfflineMessagestringMessage to be displayed when the livestream is not broadcasted anymore"Stream is offline."
defaultOfflineTimeoutDurationnumberNumber of seconds the player has to wait before dispatching the offline screen20
defaultTimeUpdateDurationnumberInterval in seconds for onPlayerTimeUpdate.5
isWithinIFramebooleanMake sure to pass this option as true when the player is embedded within an iframefalse

Bayes Web Player callbacks

The below callbacks can be defined as a part of the options object when instantiating the Bayes Web Player.

NameTypeDescription
onReady() => voidCallback to be invoked when the player is ready
onPlay() => voidCallback to be invoked when the player starts playing the livestream
onError() => voidCallback to be invoked when the player fires an error
onPause() => voidCallback to be invoked when the player is paused
onStreamOffline() => voidCallback to be invoked when the livestream is offline
onTimeUpdate(metadata: PlayerMetadata) => voidCallback to invoked while the stream is being played. Will be executed every X seconds where X is the number of seconds passed as defaultTimeUpdateDuration in the options object. Contains the metadata object containing player low level information.

Bayes Web Player API

Bayes Web Player exposes the functionality given below to allow the website to control the player as required. More functionality will be added in the near future.

Player

The below APIs can be called directly on the Player instance. eg: player.init();

NameTypeDescription
constructor(url: string, container: string / HtmlDivElement, options: PlayerOptions, doc?: Document) => PlayerBayes Web Player constructor
init() => voidInitialize the Bayes Web Player instance on the provided container ID, with the given URI and options
play() => voidStarts the video playback
pause() => voidPauses the video playback (Note: Restarted livestreams will begin at the live state)
destroy() => booleanRemove the embeddable player from the webpage
metadata() => PlayerMetadataReturns a player metadata object containing low-level information. (Player must be initialized)

Volume

Volume controls have been segregated into a different instance within the Bayes Web Player. And as such, the below APIs can be invoked via the volume instance. eg: player.volume.set(50);

NameTypeDescription
set(value: IntRange<0, 101>) => voidSets the volume of the player as required
increase() => voidIncrease the volume of the player by ten
decrease() => voidDecrease the volume of the player by ten
mute() => voidMute the Bayes Web Player
unmute() => voidUnmute the Bayes Web Player

User Interface

UI APIs can be invoked via the ui instance of the Bayes Web Player. eg: player.ui.toggle();

NameTypeDescription
fullscreen() => voidToggle fullscreen status
toggle() => voidToggle display of the controls (UI overlay which consists of playback controls)
detach() => voidToggle detachable status of the player
thumbnail(value?: string) => voidSets the thumbnail of the player (Image URL or data URI). If no argument is provided, the function removes the existing thumbnail.
watermark(value?: WatermarkOptions) => voidSets or unsets the watermark of the player. If the value argument is not provided, the function removes any existing watermark.
setStyles(value?: StyleOptions) => voidSets the styles for the elements of the player

Reference Types

PlayerOptions

type PlayerOptions = {
autoplay?: boolean;
muted?: boolean;
enableUi?: boolean;
volume?: IntRange<0, 101>;
detachable?: boolean;
thumbnail?: string;
watermark?: WatermarkOptions;
defaultErrorMessage?: string;
defaultOfflineMessage?: string;
defaultOfflineTimeoutDuration?: number;
defaultTimeUpdateDuration?: number;
styles?: StyleOptions;
onReady?: () => void;
onError?: () => void;
onPlay?: () => void;
onPause?: () => void;
onStreamOffline?: () => void;
onTimeUpdate?: (metadata: PlayerMetadata) => void;
isWithinIFrame: boolean;
};

WatermarkOptions

type WatermarkPosition =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right';

type WatermarkSize = 'sm' | 'md' | 'lg';

type WatermarkOptions = {
src: string;
position?: WatermarkPosition;
size?: WatermarkSize;
opacity?: number;
onClick?: () => void;
};

StyleOptions

Currently style options are limited to updating the default, hover and background colors of the player controls, play button and the control bar. More options such as font sizes, font family, dimensions and positions will be added in future iterations of the Bayes Web Player.

const StyleProps = {
color: 'color',
colorHover: 'color-hover',
backgroundColor: 'background-color'
};

const StyleKeys = {
controls: 'controls',
playButton: 'play-button',
controlBar: 'control-bar'
};

type StyleParams = { [key in keyof typeof StyleProps]: string };

type StyleOptions = { [key in keyof typeof StyleKeys]?: StyleParams };

PlayerMetadata

The below information is accessible when the livestream is initialized and playing. More low-level information will be added in future iterations of the Bayes Web Player.

export type PlayerMetadata = {
bandwidth?: number;
bufferLength?: number;
currentTime?: number;
duration?: number | Infinity;
mediaInfo?: {
mediaBytesTransferred?: number;
mediaRequests?: number;
mediaRequestsAborted?: number;
mediaRequestsErrored?: number;
mediaRequestsTimedout?: number;
mediaSecondsLoaded?: number;
mediaSequence?: number;
};
playerDimensions?: {
height?: number;
width?: number;
};
timestamp?: number;
videoPlaybackQuality?: {
corruptedVideoFrames?: number;
droppedVideoFrames?: number;
totalVideoFrames?: number;
framesPerSecond?: number;
};
};