Last active
October 12, 2021 22:18
-
-
Save spencercap/11fd3b5644868f1a5af638dfb7ce5e3b to your computer and use it in GitHub Desktop.
CloudflarePlayerApiTypes.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from: https://developers.cloudflare.com/stream/viewing-videos/using-the-player-api | |
export type CfPlayer = { | |
// methods | |
play(): Promise<void>; | |
pause(): void; | |
addEventListener( | |
eventName: CfPlayerEvents, | |
listener: (...args: any[]) => void | |
): void; | |
removeEventListener( | |
eventName: CfPlayerEvents, | |
listener: (...args: any[]) => void | |
): void; | |
destroy(): void; | |
hookBeacon(t: any): void; | |
// properties (get + set) | |
autoplay: boolean; | |
readonly buffered: TimeRanges; | |
controls: boolean; // show/hide | |
currentTime: number; // seconds | |
defaultTextTrack: any; | |
readonly duration: number; // seconds | |
readonly ended: boolean; | |
loop: boolean; | |
muted: boolean; | |
readonly paused: boolean; | |
readonly played: TimeRanges; | |
preload: boolean | 'none'; | |
volume: number; // 0.0 – 1.0 | |
// undocumented | |
playbackRate: number; // 0.25 – 2.0 | |
poster: string; | |
src: string; | |
videoWidth: number; | |
videoHeight: number; | |
}; | |
export type CfPlayerEvents = typeof CfValidPlayerEvents[number]; | |
export const CfValidPlayerEvents: readonly [ | |
// events (standard) - https://developer.mozilla.org/en-US/docs/Web/Events#media | |
'abort', | |
'canplay', | |
'canplaythrough', | |
'durationchange', | |
'ended', | |
'error', | |
'loadeddata', | |
'loadedmetadata', | |
'loadstart', | |
'pause', | |
'play', | |
'playing', | |
'progress', | |
'ratechange', | |
'seeked', | |
'seeking', | |
'stalled', | |
'suspend', | |
'timeupdate', | |
'volumechange', | |
'waiting', | |
// events (non-standard) | |
'stream-adstart', | |
'stream-adend', | |
'stream-adtimeout' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i use this type after including the cloudflare player api script in
index.html
like:or after importing the player api in code like:
whichever way, my linter + code completion are happy if i add this to a global types declaration file (
globals.d.ts
) like so:for reference: the cloudflare player api