Increase the definition surface of videojs types

This commit is contained in:
Stéphane Roucheray
2018-06-24 20:35:28 +02:00
parent 7eae3c4d77
commit a3a2238ecf
2 changed files with 66 additions and 21 deletions
+46 -18
View File
@@ -6,6 +6,7 @@
// Christoph Wagner <https://github.com/IgelCampus>
// Gio Freitas <https://github.com/giofreitas>
// Grzegorz Błaszczyk <https://github.com/gjanblaszczyk>
// Stéphane Roucheray <https://github.com/sroucheray>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// The Video.js API allows you to interact with the video through
@@ -19,6 +20,7 @@ export as namespace videojs;
declare namespace videojs {
const getComponent: typeof Component.getComponent;
const registerComponent: typeof Component.registerComponent;
const getPlugin: typeof Plugin.getPlugin;
interface PlayerOptions {
techOrder?: string[];
@@ -53,15 +55,27 @@ declare namespace videojs {
height: number;
}
class Component {
class EventTarget {
addEventListener(type: string | string[], callback: (eventObject: Event) => void): void;
dispatchEvent(event: string | Event | { [key: string]: any }): void;
off(type?: string | string[], callback?: (eventObject: Event) => void): void;
on(type: string | string[], callback: (eventObject: Event) => void): void;
one(type: string | string[], callback: (eventObject: Event) => void): void;
removeEventListener(type?: string | string[], callback?: (eventObject: Event) => void): void;
trigger(event: string | Event | { [key: string]: any }): void;
}
class Component extends EventTarget {
constructor(player: Player, options: any);
static getComponent(name: 'Player'|'player'): typeof Player;
static getComponent(name: 'Component'|'component' | string): typeof Component;
static registerComponent(name: string, ComponentToRegister: typeof Component): typeof Component;
static getComponent(name: 'Player' | 'player'): Player;
static getComponent(name: 'Button' | 'button'): Button;
static getComponent(name: 'Component' | 'component' | string): Component;
static registerComponent(name: string, ComponentToRegister: Component): Component;
$(selector: string, context?: string|Element): Element;
$$(selector: string, context?: string|Element): NodeList;
$(selector: string, context?: string | Element): Element;
$$(selector: string, context?: string | Element): NodeList;
addChild(child: string | Component, optionsopt?: any, indexopt?: number): Component;
addClass(classToAdd: string): void;
blur(): void;
cancelAnimationFrame(id: number): number;
@@ -70,31 +84,28 @@ declare namespace videojs {
clearTimeout(timeoutId: number): number;
contentEl(): Element;
createEl(tagNameopt?: string, properties?: any, attributes?: any): Element;
currentDimension(widthOrHeight: 'width'|'height'): number;
currentDimension(widthOrHeight: 'width' | 'height'): number;
currentDimensions(): Dimensions;
currentHeight(): number;
currentWidth(): number;
dimension(widthOrHeight: 'width'|'height'): number;
dimension(widthOrHeight: 'width'|'height', num: string|number, skipListenersopt?: boolean): void;
dimensions(width: string|number, height: string|number): void;
dimension(widthOrHeight: 'width' | 'height'): number;
dimension(widthOrHeight: 'width' | 'height', num: string | number, skipListenersopt?: boolean): void;
dimensions(width: string | number, height: string | number): void;
dispose(): void;
el(): Element;
enableTouchActivity(): void;
focus(): void;
getAttribute(attribute: string): string|null;
getChild(name: string): Component|undefined;
getChildById(id: string): Component|undefined;
getAttribute(attribute: string): string | null;
getChild(name: string): Component | undefined;
getChildById(id: string): Component | undefined;
hasClass(classToCheck: string): boolean;
height(): number|string;
height(num: number|string, skipListeners?: boolean): void;
height(): number | string;
height(num: number | string, skipListeners?: boolean): void;
hide(): void;
id(): string;
initChildren(): void;
localize(key: string, tokens?: string[], defaultValue?: string): string;
name(): string;
off(eventName?: string, callback?: (eventObject: Event) => void): void;
on(eventName: string, callback: (eventObject: Event) => void): void;
one(eventName: string, callback: (eventObject: Event) => void): void;
options(obj: any): any;
player(): Player;
ready(callback: (this: this) => void): this;
@@ -112,6 +123,11 @@ declare namespace videojs {
width(num: number, skipListeners?: number): void;
}
class Button extends Component {
controlText(textopt?: string, elopt?: Element): string;
createControlTextEl(elopt: Element): Element;
}
class Player extends Component {
autoplay(value?: boolean): string;
addRemoteTextTrack(options: {}, manualCleanup?: boolean): HTMLTrackElement;
@@ -144,6 +160,18 @@ declare namespace videojs {
width(num: number): void;
}
class Plugin {
static deregisterPlugin(name: string): void;
static getPlugin(name: string): Plugin;
static getPlugins(namesopt?: string[]): { [key: string]: Plugin };
static getPluginVersion(name: string): string;
static isBasic(plugin: Plugin | (() => void)): boolean;
static registerPlugin(name: string, plugin: Plugin | (() => void)): void;
dispose(): void;
getEventHash(hashopt: any): any;
version(): string;
}
namespace dom {
function appendContent(element: Element, content: any): Element;
}
+20 -3
View File
@@ -14,9 +14,9 @@ videojs("example_video_1").ready(function() {
this.src({ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" });
this.src([
{ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" },
{ type: "video/webm", src: "http://www.example.com/path/to/video.webm" },
{ type: "video/ogg", src: "http://www.example.com/path/to/video.ogv" }
{ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" },
{ type: "video/webm", src: "http://www.example.com/path/to/video.webm" },
{ type: "video/ogg", src: "http://www.example.com/path/to/video.ogv" }
]);
const whereYouAt: number = this.currentTime();
@@ -79,3 +79,20 @@ function testEvents(myPlayer: videojs.Player) {
// Removes all listeners.
myPlayer.off();
}
function testComponents() {
let component = videojs.getComponent('Component');
component = videojs.Component.getComponent('Component');
const button = videojs.getComponent('Button');
button.controlText('Button Text');
const player = videojs.getComponent('Player');
player.play();
}
function testPlugin() {
let plugin = videojs.getPlugin('plugin_name');
plugin = videojs.getPlugin('plugin_name');
plugin.dispose();
}