import type { IUpdatePlaybackRateWorkerMessage } from "../multithread_types"; import type { ITrackType } from "../public_types"; import type { IRange } from "../utils/ranges"; import type { IReadOnlySharedReference } from "../utils/reference"; import type { CancellationSignal } from "../utils/task_canceller"; import type { IFreezingStatus, IReadOnlyPlaybackObserver, IRebufferingStatus } from "./types"; import type ObservationPosition from "./utils/observation_position"; export interface IWorkerPlaybackObservation { /** * Information on whether the media element was paused at the time of the * Observation. */ paused: IPausedPlaybackObservation; /** * Information on the current media position in seconds at the time of the * Observation. */ position: ObservationPosition; /** `duration` property of the HTMLMediaElement. */ duration: number; /** `readyState` property of the HTMLMediaElement. */ readyState: number; /** Target playback rate at which we want to play the content. */ speed: number; /** Theoretical maximum position on the content that can currently be played. */ maximumPosition: number; /** * Ranges of buffered data per type of media. * `null` if no buffer exists for that type of media. */ buffered: Record; rebuffering: IRebufferingStatus | null; freezing: IFreezingStatus | null; bufferGap: number | undefined; } /** Pause-related information linked to an emitted Playback observation. */ export interface IPausedPlaybackObservation { /** * Known paused state at the time the Observation was emitted. * * `true` indicating that the HTMLMediaElement was in a paused state. * * Note that it might have changed since. If you want truly precize * information, you should recuperate it from the HTMLMediaElement directly * through another mean. */ last: boolean; /** * Actually wanted paused state not yet reached. * This might for example be set to `false` when the content is currently * loading (and thus paused) but with autoPlay enabled. */ pending: boolean | undefined; } export default class WorkerPlaybackObserver implements IReadOnlyPlaybackObserver { private _src; private _cancelSignal; private _messageSender; private _contentId; constructor(src: IReadOnlySharedReference, contentId: string, sendMessage: (msg: IUpdatePlaybackRateWorkerMessage) => void, cancellationSignal: CancellationSignal); getCurrentTime(): number | undefined; getReadyState(): number | undefined; getIsPaused(): boolean | undefined; getReference(): IReadOnlySharedReference; setPlaybackRate(playbackRate: number): void; getPlaybackRate(): number | undefined; listen(cb: (observation: IWorkerPlaybackObservation, stopListening: () => void) => void, options?: { includeLastObservation?: boolean | undefined; clearSignal?: CancellationSignal | undefined; }): void; deriveReadOnlyObserver(transform: (observationRef: IReadOnlySharedReference, cancellationSignal: CancellationSignal) => IReadOnlySharedReference): IReadOnlyPlaybackObserver; }