diff --git a/types/vimeo__player/index.d.ts b/types/vimeo__player/index.d.ts new file mode 100755 index 0000000000..7f26465b14 --- /dev/null +++ b/types/vimeo__player/index.d.ts @@ -0,0 +1,107 @@ +// Type definitions for @vimeo/player 2.0 +// Project: https://github.com/vimeo/player.js +// Definitions by: Denis Yılmaz , Felix Albert +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// tslint:disable-next-line no-single-declare-module +declare module "@vimeo/player" { + function myMethod(a: string): string; + function myOtherMethod(a: number): number; + + type CallbackFunction = (...args: any[]) => any; + + interface Error {name: string; message: string; method: string; } + + interface PasswordError extends Error {name: "PasswordError"; message: string; method: string; } + interface PrivacyError extends Error {name: "PrivacyError"; message: string; method: string; } + interface InvalidTrackLanguageError extends Error {name: "InvalidTrackLanguageError"; message: string; method: string; } + interface InvalidTrackError extends Error {name: "InvalidTrackError"; message: string; method: string; } + interface UnsupportedError extends Error {name: "UnsupportedError"; message: string; method: string; } + interface ContrastError extends Error {name: "ContrastError"; message: string; method: string; } + interface InvalidCuePoint extends Error {name: "InvalidCuePoint"; message: string; method: string; } + interface RangeError extends Error {name: "RangeError"; message: string; method: string; } + interface TypeError extends Error {name: "TypeError"; message: string; method: string; } + + type EventName = "play" | "pause" | "ended" | "timeupdate" | "progress" | "seeked" | "texttrackchange" | "cuechange" | "cuepoint" | "volumechange" | "error" | "loaded" | string; + type EventCallback = (data: any) => any; + + class Player { + constructor(element: HTMLIFrameElement|HTMLElement|string, options: Options); + + on(event: EventName, callback: EventCallback): void; + off(event: EventName, callback?: EventCallback): void; + loadVideo(id: number): VimeoPromise; + ready(): VimeoPromise; + enableTextTrack(language: string, kind?: string): VimeoPromise; + disableTextTrack(): VimeoPromise; + pause(): VimeoPromise; + play(): VimeoPromise; + unload(): VimeoPromise; + getAutopause(): VimeoPromise; + setAutopause(autopause: boolean): VimeoPromise; + getColor(): VimeoPromise; + setColor(color: string): VimeoPromise; + addCuePoint(time: number, data: VimeoCuePointData): VimeoPromise; + removeCuePoint(id: string): VimeoPromise; + getCuePoints(): VimeoPromise; + getCurrentTime(): VimeoPromise; + setCurrentTime(seconds: number): VimeoPromise; + getDuration(): VimeoPromise; + getEnded(): VimeoPromise; + getLoop(): VimeoPromise; + setLoop(loop: boolean): VimeoPromise; + getPaused(): VimeoPromise; + getTextTracks(): VimeoPromise; + getVideoEmbedCode(): VimeoPromise; + getVideoId(): VimeoPromise; + getVideoTitle(): VimeoPromise; + getVideoWidth(): VimeoPromise; + getVideoHeight(): VimeoPromise; + getVideoUrl(): VimeoPromise; + getVolume(): VimeoPromise; + setVolume(volume: number): VimeoPromise; + } + + interface VimeoCuePoint { + time: number; + data: VimeoCuePointData; + id: string; + } + + interface VimeoCuePointData extends Object { + customKey: string; + } + + interface VimeoTextTrack { + language: string; + kind: string; + label: string; + mode?: string; + } + + interface Options { + id?: number; + url?: string; + autopause?: boolean; + autoplay?: boolean; + byline?: boolean; + color?: string; + height?: number; + loop?: boolean; + maxheight?: number; + maxwidth?: number; + portrait?: boolean; + title?: boolean; + width?: number; + } + + interface VimeoPromise extends Promise { + ( + successCallback?: (promiseValue: Result) => void, + rejectCallback?: (reasonValue: Reason) => void + ): Promise; + } + + /*~ You can declare properties of the module using const, let, or var */ + const playerMap: WeakMap; + const readyMap: WeakMap; +} diff --git a/types/vimeo__player/tsconfig.json b/types/vimeo__player/tsconfig.json new file mode 100644 index 0000000000..515a54d8e8 --- /dev/null +++ b/types/vimeo__player/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "types", + "typeRoots": [ + "types" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vimeo__player-tests.ts" + ] +} \ No newline at end of file diff --git a/types/vimeo__player/tslint.json b/types/vimeo__player/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/vimeo__player/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/vimeo__player/vimeo__player-tests.ts b/types/vimeo__player/vimeo__player-tests.ts new file mode 100644 index 0000000000..8f3e27daaf --- /dev/null +++ b/types/vimeo__player/vimeo__player-tests.ts @@ -0,0 +1,449 @@ +import { Player } from '@vimeo/player'; + +// based on README.md of @vimeo/player >> https://github.com/vimeo/player.js + +let player: Player ; + +player = new Player('handstick', { + id: 19231868, + width: 640 +}); + +let onPlay = (data: any ) => { + // data is an object containing properties specific to that event +}; + +player.on('play', onPlay); + +// If later on you decide that you don’t need to listen for play anymore. +player.off('play', onPlay); + +// Alternatively, `off` can be called with just the event name to remove all +// listeners. +player.off('play'); + +player.loadVideo(76979871).then((id) => { + // the video successfully loaded +}).catch((error) => { + switch (error.name) { + case 'TypeError': + // the id was not a number + break; + + case 'PasswordError': + // the video is password-protected and the viewer needs to enter the + // password first + break; + + case 'PrivacyError': + // the video is password-protected or private + break; + + default: + // some other error occurred + break; + } +}); + +player.ready().then(() => { + // the player is ready +}); + +player.enableTextTrack('en').then((track) => { + console.log(track.label); + console.log(track.kind); + console.log(track.language); + // track.language = the iso code for the language + // track.kind = 'captions' or 'subtitles' + // track.label = the human-readable label +}).catch((error) => { + switch (error.name) { + case 'InvalidTrackLanguageError': + // no track was available with the specified language + break; + + case 'InvalidTrackError': + // no track was available with the specified language and kind + break; + + default: + // some other error occurred + break; + } +}); + +player.disableTextTrack().then(() => { + // the track was disabled +}).catch((error) => { + // an error occurred +}); + +player.pause().then(() => { + // the video was paused +}).catch((error) => { + switch (error.name) { + case 'PasswordError': + // the video is password-protected and the viewer needs to enter the + // password first + break; + + case 'PrivacyError': + // the video is private + break; + + default: + // some other error occurred + break; + } +}); + +player.play().then( () => { + // the video was played +}).catch((error) => { + switch (error.name) { + case 'PasswordError': + // the video is password-protected and the viewer needs to enter the + // password first + break; + + case 'PrivacyError': + // the video is private + break; + + default: + // some other error occurred + break; + } +}); + +player.unload().then( () => { + // the video was unloaded +}).catch( (error) => { + // an error occurred +}); + +player.getAutopause().then( (autopause) => { + // autopause = whether autopause is turned on or off +}).catch( (error) => { + switch (error.name) { + case 'UnsupportedError': + // Autopause is not supported with the current player or browser + break; + + default: + // some other error occurred + break; + } +}); + +player.setAutopause(false).then( (autopause) => { + // autopause was turned off +}).catch( (error) => { + switch (error.name) { + case 'UnsupportedError': + // Autopause is not supported with the current player or browser + break; + + default: + // some other error occurred + break; + } +}); + +player.getColor().then( (color) => { + // color = the hex color of the player +}).catch( (error) => { + // an error occurred +}); + +player.setColor('#00adef').then( (color) => { + // color was successfully set +}).catch( (error) => { + switch (error.name) { + case 'ContrastError': + // the color was set, but the contrast is outside of the acceptable + // range + break; + + case 'TypeError': + // the string was not a valid hex or rgb color + break; + + case 'EmbedSettingsError': + // the owner of the video has chosen to use a specific color + break; + + default: + // some other error occurred + break; + } +}); + +player.addCuePoint(15, { + customKey: 'customValue' +}).then( (id) => { + // cue point was added successfully +}).catch( (error) => { + switch (error.name) { + case 'UnsupportedError': + // cue points are not supported with the current player or browser + break; + + case 'RangeError': + // the time was less than 0 or greater than the video’s duration + break; + + default: + // some other error occurred + break; + } +}); + +player.removeCuePoint('09ecf4e4-b587-42cf-ad9f-e666b679c9ab').then( (id) => { + // cue point was removed successfully +}).catch( (error) => { + switch (error.name) { + case 'UnsupportedError': + // cue points are not supported with the current player or browser + break; + + case 'InvalidCuePoint': + // a cue point with the id passed wasn’t found + break; + + default: + // some other error occurred + break; + } +}); + +player.getCuePoints().then( (cuePoints) => { + // cuePoints = an array of cue point objects +}).catch( (error) => { + switch (error.name) { + case 'UnsupportedError': + // cue points are not supported with the current player or browser + break; + + default: + // some other error occurred + break; + } +}); + +player.getCurrentTime().then( (seconds) => { + // seconds = the current playback position +}).catch( (error) => { + // an error occurred +}); + +player.setCurrentTime(30.456).then( (seconds) => { + // seconds = the actual time that the player seeked to +}).catch( (error) => { + switch (error.name) { + case 'RangeError': + // the time was less than 0 or greater than the video’s duration + break; + + default: + // some other error occurred + break; + } +}); + +player.getDuration().then((duration) => { + // duration = the duration of the video in seconds +}).catch((error) => { + // an error occurred +}); + +player.getEnded().then((ended) => { + // ended = whether or not the video has ended +}).catch((error) => { + // an error occurred +}); + +player.getLoop().then((loop) => { + // loop = whether loop is turned on or not +}).catch((error) => { + // an error occurred +}); + +player.setLoop(true).then((loop) => { + // loop was turned on +}).catch((error) => { + // an error occurred +}); + +player.getPaused().then((paused) => { + // paused = whether or not the player is paused +}).catch((error) => { + // an error occurred +}); + +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); + }); +}).catch((error) => { + // an error occurred + error.name; +}); + +player.getVideoEmbedCode().then((embedCode) => { + // embedCode =