import type { BackendState, QualityLevel, SubtitleTrack } from '@nomercy-entertainment/nomercy-player-core'; import type { BackendEventPayload, IVideoBackend } from '../../index.js'; import { MediaElementBackend } from '@nomercy-entertainment/nomercy-player-core'; type TwitchPlayerEvent = 'playing' | 'pause' | 'ended' | 'offline'; interface TwitchQuality { group: string; name: string; height: number; width: number; bitrate: number; } interface TwitchPlayerOptions { width: string; height: string; autoplay: boolean; muted: boolean; controls: boolean; parent: readonly string[]; video?: string; time?: string; channel?: string; } interface TwitchPlayer { play: () => void; pause: () => void; seek: (seconds: number) => void; setVolume: (volume: number) => void; setMuted: (muted: boolean) => void; getCurrentTime: () => number; getDuration: () => number; getQuality: () => string; getQualities: () => TwitchQuality[]; setQuality: (quality: string) => void; addEventListener: (event: TwitchPlayerEvent, handler: () => void) => void; enableCaptions: () => void; disableCaptions: () => void; } interface TwitchSdk { Player: { new (element: HTMLElement, options: TwitchPlayerOptions): TwitchPlayer; PLAYING: 'playing'; PAUSE: 'pause'; ENDED: 'ended'; OFFLINE: 'offline'; }; } /** Why a live channel stopped being playable. */ export interface ChannelGone { channel: string; reason: 'offline' | 'stream-ended'; } declare global { interface Window { Twitch?: TwitchSdk; } } /** Plays VODs and live channels through Twitch's official SDK. */ export declare class TwitchEmbedBackend extends MediaElementBackend implements IVideoBackend { readonly kind: "twitch"; private readonly mount; private readonly container; private readonly menuWatcher; private readonly captionsLabel; private readonly onChannelGone; private channel; private hasPlayed; private chosenGroup; private reportedLevels; private reportedLevel; private player; private poller; private sliceStart; private sliceLength; private reportedDuration; private loadedUrl; private wantedVolume; private wantedMuted; private endedOnce; private loadAttempt; private backendState; /** The element is a stand-in: the base class and the player want one, the picture lives in the iframe. */ constructor(container: HTMLElement, onChannelGone?: (gone: ChannelGone) => void, captionsLabel?: () => string); /** Twitch pauses when anything covers the embed, so it shrinks to sit between the visible control bars. */ makeRoomForControls(controlsShown: boolean): void; /** Starts a VOD or live channel link in a new embed, muted so autoplay is allowed. */ load(url: string): Promise; /** Removes the embed and stops polling it. */ unload(): void; /** Removes everything this backend added to the page. */ dispose(): void; /** Puts the embed on top first, because Twitch refuses to play while it reads as covered. */ play(): Promise; /** Pauses and lowers the embed so the player's controls can show. */ pause(): void; /** Pauses and removes the embed. */ stop(): void; /** Reads or sets the position. Inside a slice it is relative to the start of the slice. */ currentTime(): number; currentTime(seconds: number): void; /** Length of the slice, or of the whole VOD. */ duration(): number; /** Reads or sets the volume on the 0 to 1 scale. */ volume(): number; volume(value: number): void; /** Mutes the embed. */ mute(): void; /** Unmutes the embed. */ unmute(): void; /** Current lifecycle state. */ state(): BackendState; /** The SDK has no buffer reading, so the position stands in. */ buffered(): number; /** Width of the embed on the page. */ videoWidth(): number; /** Height of the embed on the page. */ videoHeight(): number; /** The SDK exposes no audio tracks. */ audioTracks(): []; /** The SDK exposes no audio tracks. */ setAudioTrack(): void; /** Twitch draws its own captions inside the embed and never lists them, so one on/off track stands for them. */ subtitleTracks(): SubtitleTrack[]; /** Any track means captions on, because the embed has only the one. */ setSubtitleTrack(index: number | null): void; /** The renditions Twitch offers, tallest first. */ qualityLevels(): QualityLevel[]; /** Holds one rendition. `auto` means the highest, because Twitch's own auto drops to a blurry one. */ setQuality(level: number | 'auto'): void; /** Index of the rendition playing now, or -1 before Twitch reports one. */ currentLevel(): number; /** The SDK reports no output protection. */ outputProtectionState(): 'unsupported'; /** The menu must not cover the embed, and the embed must not cover the menu, so they sit side by side. */ private makeRoomForMenu; private barHeight; private applyVolume; private raiseEmbed; private closeChannel; private onPlaying; private onPause; private renditions; private holdQuality; private reportQuality; private reportDuration; private tick; private finish; private signal; } export {};