From 8b4734fb5a0d9eab06480f0122cbc0c08dbde28e Mon Sep 17 00:00:00 2001 From: Joe Flateau Date: Wed, 1 Apr 2020 15:46:22 -0400 Subject: [PATCH] video.js: ensure example class-based plugin works (#43558) * ensure example class-based plugin works * additional test to be sure Plugin has player property --- types/video.js/index.d.ts | 2 +- types/video.js/video.js-tests.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/types/video.js/index.d.ts b/types/video.js/index.d.ts index a3b0f0b0b5..5fb8aa0b29 100644 --- a/types/video.js/index.d.ts +++ b/types/video.js/index.d.ts @@ -3954,7 +3954,7 @@ declare namespace videojs { * @param player * A Video.js player instance. */ - new(player: Player): Plugin; + new (player: Player, options?: any): Plugin; /** * De-register a Video.js plugin. diff --git a/types/video.js/video.js-tests.ts b/types/video.js/video.js-tests.ts index 0e252f6e0f..0bb906b170 100644 --- a/types/video.js/video.js-tests.ts +++ b/types/video.js/video.js-tests.ts @@ -1,4 +1,4 @@ -import videojs from 'video.js'; +import videojs, { VideoJsPlayer } from 'video.js'; videojs("example_video_1").ready(function() { // EXAMPLE: Start playing the video. @@ -131,6 +131,32 @@ function testPlugin(player: videojs.Player, options: {}) { }); }); (player as any).uloztoExample(options); + + const Plugin = videojs.getPlugin('plugin'); + + interface ExamplePluginOptions { + customClass: string; + } + + class ExamplePlugin extends Plugin { + constructor(player: VideoJsPlayer, options: ExamplePluginOptions) { + super(player, options); + + if (options.customClass) { + player.addClass(options.customClass); + } + + player.on('playing', () => { + videojs.log('playback began!'); + }); + + this.player.on('pause', () => { + videojs.log('playback ended'); + }); + } + } + + videojs.registerPlugin('ExamplePlugin', ExamplePlugin); } function testLogger() {