UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

87 lines (86 loc) 3.48 kB
import { DelayedTask } from '../../esl-utils/async/delayed-task'; import type { ESLMedia } from './esl-media'; export declare enum PlayerStates { BUFFERING = 3, ENDED = 0, PAUSED = 2, PLAYING = 1, UNSTARTED = -1, VIDEO_CUED = 5, UNINITIALIZED = -2 } export declare const MediaProviderConfigKeys: (keyof ESLMedia)[]; export type MediaProviderConfig = Pick<ESLMedia, typeof MediaProviderConfigKeys[number]> & ({ mediaSrc: string; } | { mediaId: string; }); export type ProviderType = (new (component: ESLMedia, config: MediaProviderConfig) => BaseProvider) & typeof BaseProvider; export type ProviderObservedParams = 'loop' | 'muted' | 'controls'; /** * BaseProvider class for media API providers * @author Alexey Stsefanovich (ala'n), Yuliya Adamskaya, Natallia Harshunova */ export declare abstract class BaseProvider { static readonly providerName: string; static parseUrl(url: string): Partial<MediaProviderConfig> | null; static parseConfig(component: ESLMedia): MediaProviderConfig; protected config: MediaProviderConfig; protected component: ESLMedia; protected _el: HTMLElement; protected _ready: Promise<any>; protected _cmdMng: DelayedTask; protected _lastCmdType: string; constructor(component: ESLMedia, config: MediaProviderConfig); /** Wraps _ready promise */ get ready(): Promise<any>; /** Bind the provider instance to the component */ abstract bind(): void; /** Unbind the provider instance from the component */ unbind(): void; /** Provider name */ get name(): string; /** @returns current state of the player */ abstract get state(): PlayerStates; /** @returns recommended aspect ratio */ abstract get defaultAspectRatio(): number; /** @returns resource duration */ abstract get duration(): number; /** @returns resource current time */ abstract get currentTime(): number; /** Low-level provider 'seek to' method implementation */ protected abstract seekTo(pos?: number): void | Promise<any>; /** Low-level provider 'play' method implementation */ protected abstract play(): void | Promise<any>; /** Low-level provider 'pause' method implementation */ protected abstract pause(): void | Promise<any>; /** Low-level provider 'stop' method implementation */ protected abstract stop(): void | Promise<any>; /** Set focus to the inner content */ focus(): void; protected onConfigChange(param: ProviderObservedParams, value: boolean): void; /** Set size for inner content */ setSize(width: number | 'auto', height: number | 'auto'): void; setAspectRatio(aspectRatio: number): void; /** Executes onConfigChange action when api is ready */ onSafeConfigChange(param: ProviderObservedParams, value: boolean): void; /** Executes seekTo action when api is ready */ safeSeekTo(pos: number): Promise<void>; /** Executes play when api is ready */ safePlay(system?: boolean): Promise<void>; /** Executes pause when api is ready */ safePause(): Promise<void>; /** * Executes stop when api is ready * @returns Promise */ safeStop(): Promise<void>; /** @returns last requested command type */ get lastCommand(): string; /** * Register current provider. * Can be used as a decorator. */ static register(this: ProviderType): void; static register(this: unknown, provider?: ProviderType): void; }