UNPKG

@livepeer/core-web

Version:

Livepeer UI Kit's core web library, for adding reactive stores to video elements.

73 lines (67 loc) 3.74 kB
import * as _livepeer_core_media from '@livepeer/core/media'; import { MediaControllerStore, DeviceInformation, InitialProps, PlaybackError, PlaybackEvent, Src } from '@livepeer/core/media'; import { HlsConfig as HlsConfig$1 } from 'hls.js'; type HlsConfig = Partial<HlsConfig$1>; declare const addEventListeners: (element: HTMLMediaElement, store: MediaControllerStore) => { destroy: () => void; }; declare const getDeviceInfo: (version: string) => DeviceInformation; type MediaMetricsOptions = Pick<InitialProps, "viewerId"> & { /** * Sets a custom source URL for playback, such as `https://livepeercdn.studio/hls/{playbackId}/index.m3u8`. * If not specified, the function defaults to using the `src` attribute of the HTMLMediaElement. * Note: For custom players that do not set the `src` attribute of the `video` element, opting instead for formats like `blob:<src>` or omitting `src` altogether, metrics collection may not function correctly. */ src?: string; /** * Sets a custom playback ID for playback. * If not specified, the function defaults to parsing the `src` attribute of the HTMLMediaElement to get the playback ID. */ playbackId?: string; /** * Disables the `progress` event listener, which is used to monitor when media is in a "playing" state. */ disableProgressListener?: boolean; /** * The interval at which metrics are sent via HTTP, in ms. Default 5000. */ interval?: number; /** * Callback called when there is an error. */ onError?: ((error: PlaybackError) => any) | null | undefined; /** * A callback that is called when the player's metrics events are emitted. * This can be used to integrate with other analytics providers. */ onPlaybackEvents?: (events: PlaybackEvent[]) => Promise<any> | any; }; /** * Initializes media playback metrics collection for a video or audio element. * This adds event listeners to the media element with a store that updates on events and send them to a websocket. * Returns a `destroy` function which must be called when the video element is removed from the DOM. * * @param {HTMLMediaElement | undefined | null} element The media element from which to capture playback metrics. * @param {Partial<MediaMetricsOptions>} opts Optional configuration options including: * - `src`: Overrides the `src` URL for playback - defaults to the `src` attribute of the HTMLMediaElement. Use this with custom players that do not set the `src` attribute of the `video` element. * - `playbackId`: Overrides the `playbackId` - defaults to parsing from the `src` attribute of the HTMLMediaElement. Use this with custom players that do not have a valid src URL which contains a playback ID. * - `onError`: A callback function that is called when an error occurs in the metrics collection process. * - `viewerId`: An identifier for the viewer to associate metrics with a specific user or session. * * @returns An object containing a `destroy` function to clean up resources. * The `destroy` function must be used to remove event listeners and perform other cleanup actions on unmount. */ declare function addMediaMetrics(element: HTMLMediaElement | undefined | null, opts?: Partial<MediaMetricsOptions>): { /** @deprecated */ legacyMetrics: _livepeer_core_media.LegacyMetricsStatus | null; destroy: () => void; } | { destroy: () => void; /** @deprecated */ legacyMetrics?: undefined; }; /** * Checks if the native HTML5 video player can play the mime type. */ declare const canPlayMediaNatively: (src: Src) => boolean; export { type HlsConfig, addEventListeners, addMediaMetrics, canPlayMediaNatively, getDeviceInfo };