UNPKG

@exmg/livery

Version:

Ex Machina Group Livery Web SDK.

202 lines (201 loc) 5.45 kB
import { LiveryVuMeter } from '../livery-vu-meter/LiveryVuMeter'; import { EmitterEvents, EventEmitter } from '../util/EventEmitter'; import { Logger } from '../util/Logger'; import { Config } from './Config'; /** * Livery Player Engine events. */ export interface EngineEvents extends EmitterEvents { /** * Sent when the active audio quality changes. */ audioQuality: { /** * Active audio quality index. */ index: number; }; /** * Sent when the collection of available qualities changes. */ qualities: { /** * Available audio qualities. */ audioQualities: { /** * Audio bandwidth in bits per second. */ bandwidth: number; /** * Audio quality index. */ index: number; }[]; /** * Available video qualities. */ videoQualities: { /** * Video andwidth in bits per second. */ bandwidth: number; /** * Video height in pixels. */ height: number; /** * Video quality index. */ index: number; /** * Video width in pixels. */ width: number; }[]; }; /** * Sent when the active video quality changes. */ videoQuality: { /** * Active video quality index. */ index: number; }; /** * Sent when the time at which the media started playing (at `currentTime` 0) has changed. * This can be used to determine the original live broadcast time by adding the current playback time. */ zeroTime: { /** * Milliseconds since January 1, 1970 00:00:00 UTC at which the media currentTime would have been 0. */ zeroTime: number; }; } /** * Abstract Engine class to implemented by specific media transport engines. */ export declare abstract class Engine extends EventEmitter<EngineEvents> { /** * Returns true if this Engine can play media of the specified MIME type. * * @param type MIME type */ static canPlay: (type: string) => boolean; /** * Name of Engine. */ static engineName: string; /** * Livery Stream Config. */ protected readonly config: Readonly<Config>; /** * Logger named by `engineName`. */ protected log: Logger; /** * If true then the audio will initially be silenced. */ protected muted: boolean; /** * Media source URL. */ protected sourceUrl: string; /** * Livery Stream ID. */ protected streamId: string; /** * Local device time offset in milliseconds. * To be added to local time to get synchronized (e.g: server) time. */ protected timeOffset: number; /** * Reference to VU Meter (if any) to be used for volume control. */ protected vuMeter?: LiveryVuMeter; /** * Media element used by this Engine. */ abstract media: HTMLMediaElement; /** * Engine constructor. * * @param options Engine options */ constructor(options: { /** * Livery Stream Config. */ config: Config; /** * If true then the audio will initially be silenced. */ muted?: boolean; /** * Media source URL. */ sourceUrl: string; /** * Livery Stream ID. */ streamId: string; /** * Local device time offset in milliseconds. * To be added to local time to get synchronized (e.g: server) time. */ timeOffset?: number; /** * Reference to VU Meter (if any) to be used for volume control. */ vuMeter?: LiveryVuMeter; }); /** * Initialize media, e.g: start loading media. */ abstract init(): void; /** * Returns true if media is live and duration should be considered infinite. * TODO: Get rid of this; handle it within upcoming duration property getter instead. */ abstract isLive(): boolean; /** * Reload media. */ abstract reload(): void; /** * Select audio quality. * If index is undefined then automatic quality selection will be used. * * @param index Audio quality index * @throws Error when index is invalid or selection is not supported by Engine */ abstract selectAudioQuality(index?: number): void; /** * Select video quality. * If index is undefined then automatic quality selection will be used. * * @param index Video quality index * @throws Error when index is invalid or selection is not supported by Engine */ abstract selectVideoQuality(index?: number): void; /** * Change source to specified URL. * * @param sourceUrl Source URL to change to */ abstract setSource(sourceUrl: string): void; } /** * Concrete Engine class type. * * Note: typeof Engine does not work with abstract class; that can't be instantiated */ export declare type ConcreteEngine = typeof Engine & Function; /** * Engine constructor options. */ export declare type EngineOptions = ConstructorParameters<ConcreteEngine>[0];