mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-23 21:35:37 +08:00
[@types/vimeo__player] Updating typings to match Vimeo's player.js v2.6.3 (#27749)
* Updated typings to match Vimeo's player.js v2.6.3, updated tests to reflect new methods, properties, and events * Cleanup of unused boilerplate lines * setPlaybackRate may return RangeError * options argument in constructor is optional
This commit is contained in:
19
types/vimeo__player/index.d.ts
vendored
19
types/vimeo__player/index.d.ts
vendored
@@ -1,13 +1,11 @@
|
||||
// Type definitions for @vimeo/player 2.0
|
||||
// Type definitions for @vimeo/player 2.6.3
|
||||
// Project: https://github.com/vimeo/player.js
|
||||
// Definitions by: Denis Yılmaz <https://github.com/denisyilmaz>
|
||||
// Felix Albert <f.albert.work@icloud.com>
|
||||
// Tim Chen <https://github.com/timc13>
|
||||
// Terry Mun <https://github.com/terrymun>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export function myMethod(a: string): string;
|
||||
export function myOtherMethod(a: number): number;
|
||||
|
||||
export type CallbackFunction = (...args: any[]) => any;
|
||||
|
||||
export interface Error {name: string; message: string; method: string; }
|
||||
@@ -22,11 +20,12 @@ export interface InvalidCuePoint extends Error {name: "InvalidCuePoint"; message
|
||||
export interface RangeError extends Error {name: "RangeError"; message: string; method: string; }
|
||||
export interface TypeError extends Error {name: "TypeError"; message: string; method: string; }
|
||||
|
||||
export type EventName = "play" | "pause" | "ended" | "timeupdate" | "progress" | "seeked" | "texttrackchange" | "cuechange" | "cuepoint" | "volumechange" | "error" | "loaded" | string;
|
||||
export type EventName = "play" | "pause" | "ended" | "timeupdate" | "progress" | "seeked" | "texttrackchange" |
|
||||
"cuechange" | "cuepoint" | "volumechange" | "playbackratechange" | "bufferstart" | "bufferend" | "error" | "loaded" | string;
|
||||
export type EventCallback = (data: any) => any;
|
||||
|
||||
export class Player {
|
||||
constructor(element: HTMLIFrameElement|HTMLElement|string, options: Options);
|
||||
constructor(element: HTMLIFrameElement|HTMLElement|string, options?: Options);
|
||||
|
||||
on(event: EventName, callback: EventCallback): void;
|
||||
off(event: EventName, callback?: EventCallback): void;
|
||||
@@ -51,6 +50,8 @@ export class Player {
|
||||
getLoop(): VimeoPromise<boolean, Error>;
|
||||
setLoop(loop: boolean): VimeoPromise<boolean, Error>;
|
||||
getPaused(): VimeoPromise<boolean, Error>;
|
||||
getPlaybackRate(): VimeoPromise<number, Error>;
|
||||
setPlaybackRate(playbackRate: number): VimeoPromise<number, RangeError | Error>;
|
||||
getTextTracks(): VimeoPromise<VimeoTextTrack[], Error>;
|
||||
getVideoEmbedCode(): VimeoPromise<string, Error>;
|
||||
getVideoId(): VimeoPromise<number, Error>;
|
||||
@@ -85,14 +86,20 @@ export interface Options {
|
||||
url?: string;
|
||||
autopause?: boolean;
|
||||
autoplay?: boolean;
|
||||
background?: boolean;
|
||||
byline?: boolean;
|
||||
color?: string;
|
||||
height?: number;
|
||||
loop?: boolean;
|
||||
maxheight?: number;
|
||||
maxwidth?: number;
|
||||
muted?: boolean;
|
||||
playsinline?: boolean;
|
||||
portrait?: boolean;
|
||||
responsive?: boolean;
|
||||
speed?: boolean;
|
||||
title?: boolean;
|
||||
transparent?: boolean;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,21 @@ let player: Player ;
|
||||
|
||||
player = new Player('handstick', {
|
||||
id: 19231868,
|
||||
width: 640
|
||||
width: 640,
|
||||
|
||||
// Use default values for settings, to test typings
|
||||
autopause: true,
|
||||
autoplay: false,
|
||||
background: false,
|
||||
byline: true,
|
||||
color: '#00adef',
|
||||
loop: false,
|
||||
muted: false,
|
||||
playsinline: true,
|
||||
portrait: true,
|
||||
speed: false,
|
||||
title: true,
|
||||
transparent: true
|
||||
});
|
||||
|
||||
const onPlay = (data: any) => {
|
||||
@@ -281,12 +295,33 @@ player.getPaused().then((paused) => {
|
||||
// an error occurred
|
||||
});
|
||||
|
||||
player.getPlaybackRate().then((playbackRate) => {
|
||||
// playbackRate = a numeric value of the current playback rate
|
||||
}).catch((error) => {
|
||||
// an error occurred
|
||||
});
|
||||
|
||||
player.setPlaybackRate(0.5).then((playbackRate) => {
|
||||
// playback rate was set
|
||||
}).catch((error) => {
|
||||
switch (error.name) {
|
||||
case 'RangeError':
|
||||
// the playback rate was less than 0.5 or greater than 2
|
||||
break;
|
||||
|
||||
default:
|
||||
// some other error occurred
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
player.getTextTracks().then((tracks) => {
|
||||
// tracks = an array of track objects
|
||||
tracks.forEach((track) => {
|
||||
console.log(track.label);
|
||||
console.log(track.kind);
|
||||
console.log(track.language);
|
||||
console.log(track.mode);
|
||||
});
|
||||
}).catch((error) => {
|
||||
// an error occurred
|
||||
@@ -436,6 +471,19 @@ player.on('volumechange', (data) => {
|
||||
console.log(data.volume);
|
||||
});
|
||||
|
||||
player.on('playbackratechange', (data) => {
|
||||
// data is an object containing properties specific to that event
|
||||
console.log(data.playbackRate);
|
||||
});
|
||||
|
||||
player.on('bufferstart', (data) => {
|
||||
// no associated data with this event
|
||||
});
|
||||
|
||||
player.on('bufferend', (data) => {
|
||||
// no associated data with this event
|
||||
});
|
||||
|
||||
player.on('error', (data) => {
|
||||
// data is an object containing properties specific to that event
|
||||
console.log(data.message);
|
||||
|
||||
Reference in New Issue
Block a user