UNPKG

@plutotcool/vue-freecaster

Version:

Freecaster video player integration for vue

124 lines (122 loc) 3.98 kB
/** * @module usePlayer */ import { Ref, MaybeRef, HTMLAttributes } from 'vue'; import { Player, PlayerOptions, PlayerEvents } from '../types/Player'; type PlayerAttributes = HTMLAttributes & Record<string, string>; export interface UsePlayerParameters { /** * Freecaster player options * @default undefined */ options?: MaybeRef<PlayerOptions | undefined>; /** * Optional paused model that reads and controls the player state * @default undefined */ paused?: Ref<boolean>; /** * Optional muted model that reads and controls the player state * @default undefined */ muted?: Ref<boolean>; /** * Optional currentSubtitles model that reads and controls the player state * @default undefined */ currentSubtitles?: Ref<TextTrack | undefined>; /** * Optional subtitles model that only reads the player state * @default undefined */ subtitles?: Ref<TextTrack[]>; /** * Optional volume model that reads and controls the player state * @default undefined */ volume?: Ref<number>; /** * Optional currentTime model that reads and controls the player state * @default undefined */ currentTime?: Ref<number>; /** * Optional fullscreen model that reads and controls the player state * @default undefined */ fullscreen?: Ref<boolean>; /** * Optional readyState model that only reads the player state * @default undefined */ readyState?: Ref<number>; /** * Optional player model returned by the composable, fallbacks to an empty ref * @default undefined */ player?: MaybeRef<Player | undefined>; /** * Optional container element ref returned by the composables, fallbacks to an * empty ref * @default undefined */ element?: MaybeRef<HTMLElement | undefined>; /** * Wether to keep the player instance alive after the component is unmounted. * It can then be manually destroyed by calling * {@link UsePlayerContext.destroy}. This can be useful to keep the player * instance alive during vue leave transitions. * @default false */ keepAlive?: MaybeRef<boolean>; /** * Default event listener, called for all events * @default undefined */ emit?: <Type extends keyof PlayerEvents = keyof PlayerEvents>(type: Type, ...args: PlayerEvents[Type]) => void; /** * Event listeners * @default undefined */ listeners?: { [Name in `on${Capitalize<keyof PlayerEvents>}`]?: (...args: PlayerEvents[Name extends `on${infer Event}` ? Uncapitalize<Event> : never]) => void; }; } export interface UsePlayerContext extends UsePlayerParameters { /** * Ref to the freecaster load function. */ load: Ref<((element: Element) => void) | undefined>; /** * Destroy the currently attached player instance. */ destroy: () => void; /** * Event listeners for the player. */ listeners: Required<UsePlayerParameters>['listeners']; /** * Player options provided in {@link UsePlayerParameters.options}. */ options: Ref<PlayerOptions | undefined>; /** * Ref to the player instance. */ player: Ref<Player | undefined>; /** * Ref to the element where the player is attached. Can be passed to the * special ref prop of an element to attach the player to. */ element: Ref<HTMLElement | undefined>; /** * Ref to the player attributes that can be used to bind to the player. Can be * passed the v-bind directive of an element to attach the player to. */ attributes: Ref<PlayerAttributes>; /** * Ref to a key that is updated every time the player loads a new video. */ key: Ref<number>; } export declare function usePlayer(parameters?: UsePlayerParameters): UsePlayerContext; export type { Player, PlayerOptions, PlayerEvents };