From 1b46cf9f96beae92d687adc1f823b17392b3083c Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Fri, 22 Jul 2016 18:54:18 +0200 Subject: [PATCH 01/10] create player instance from component to allow to extend player class --- src/js/video.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/video.js b/src/js/video.js index 9047281f11..4ceb7c8888 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -117,8 +117,9 @@ function videojs(id, options, ready) { options = mergeOptions(options, opts); }); + const PlayerComponent = Component.getComponent('Player'); // If not, set up a new player - const player = new Player(tag, options, ready); + const player = new PlayerComponent(tag, options, ready); videojs.hooks('setup').forEach((hookFunction) => hookFunction(player)); From c4d7fce6f7e2717a3fdaf547792eb7f6e099bc60 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Mon, 25 Jul 2016 11:37:33 +0200 Subject: [PATCH 02/10] add test case for custom player --- test/unit/player.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 345da2cd7e..42fea86be5 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1252,3 +1252,15 @@ QUnit.test('When VIDEOJS_NO_DYNAMIC_STYLE is set, apply sizing directly to the t assert.equal(player.tech_.el().height, 300, 'the height is equal 300'); player.dispose(); }); + +test('should allow to use custom player class', function(){ + class CustomPlayer extends Player {} + videojs.registerComponent('Player', CustomPlayer); + + let tag = TestHelpers.makeTag(); + let player = videojs(tag); + + equal(player instanceof CustomPlayer, true, 'player is custom'); + + player.dispose(); +}); From 8088eb4344f30bcaecfd329a6d96f942677fb1b0 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Tue, 15 Nov 2016 23:19:40 +0100 Subject: [PATCH 03/10] throw error when registering player component after any player has been created --- src/js/component.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/component.js b/src/js/component.js index db9b295c0c..aa9ea87150 100644 --- a/src/js/component.js +++ b/src/js/component.js @@ -1440,6 +1440,14 @@ class Component { Component.components_ = {}; } + if (name === 'Player' && Component.components_[name]) { + const Player = Component.components_[name]; + + if (Player.players && Object.keys(Player.players).length > 0) { + throw new Error(`Can't register ${name} component after Player has been created`); + } + } + Component.components_[name] = comp; return comp; From b391c39b1f5f4c0f655f3bc06ca2963ba5fa8012 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Tue, 15 Nov 2016 23:29:37 +0100 Subject: [PATCH 04/10] update test --- test/unit/player.test.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 42fea86be5..9feacad499 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1253,14 +1253,13 @@ QUnit.test('When VIDEOJS_NO_DYNAMIC_STYLE is set, apply sizing directly to the t player.dispose(); }); -test('should allow to use custom player class', function(){ +QUnit.test('should allow to use custom player class', function(assert) { class CustomPlayer extends Player {} videojs.registerComponent('Player', CustomPlayer); - let tag = TestHelpers.makeTag(); - let player = videojs(tag); - - equal(player instanceof CustomPlayer, true, 'player is custom'); + const tag = TestHelpers.makeTag(); + const player = videojs(tag); + assert.equal(player instanceof CustomPlayer, true, 'player is custom'); player.dispose(); }); From 8c449e69a0c7451c093ff3df6d56df58e80739c3 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:52:06 +0100 Subject: [PATCH 05/10] change error message --- src/js/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/component.js b/src/js/component.js index aa9ea87150..36b3d6e031 100644 --- a/src/js/component.js +++ b/src/js/component.js @@ -1444,7 +1444,7 @@ class Component { const Player = Component.components_[name]; if (Player.players && Object.keys(Player.players).length > 0) { - throw new Error(`Can't register ${name} component after Player has been created`); + throw new Error('Can not register Player component after player has been created'); } } From af19d7201e93463f89671bb588ff4723745cc8c9 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:52:56 +0100 Subject: [PATCH 06/10] clear player storage before each test --- test/unit/player.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 9feacad499..f165860317 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -16,6 +16,13 @@ import TechFaker from './tech/tech-faker.js'; QUnit.module('Player', { beforeEach() { this.clock = sinon.useFakeTimers(); + // reset players storage + for (let playerId in Player.players) { + if (Player.players[playerId] !== null) { + Player.players[playerId].dispose(); + } + delete Player.players[playerId]; + } }, afterEach() { this.clock.restore(); From ec6748ae1ef841ae2c62c05625b0fbb2e312871a Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:53:20 +0100 Subject: [PATCH 07/10] change test description --- test/unit/player.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index f165860317..8d4dd93c05 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1260,7 +1260,7 @@ QUnit.test('When VIDEOJS_NO_DYNAMIC_STYLE is set, apply sizing directly to the t player.dispose(); }); -QUnit.test('should allow to use custom player class', function(assert) { +QUnit.test('should allow to register custom player when any player has not been created', function(assert) { class CustomPlayer extends Player {} videojs.registerComponent('Player', CustomPlayer); From dafde8d1e1f2f02853755c52fc73aa81c4cd9dc7 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:54:29 +0100 Subject: [PATCH 08/10] add test case for register custom player after any player has been created --- test/unit/player.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 8d4dd93c05..5b3990f9d1 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1270,3 +1270,17 @@ QUnit.test('should allow to register custom player when any player has not been assert.equal(player instanceof CustomPlayer, true, 'player is custom'); player.dispose(); }); + +QUnit.test('should not allow to register custom player when any player has been created', function(assert) { + const tag = TestHelpers.makeTag(); + const player = videojs(tag); + + class CustomPlayer extends Player {} + try { + videojs.registerComponent('Player', CustomPlayer); + } catch (e) { + return assert.equal(e.message, 'Can not register Player component after player has been created'); + } + + assert.ok(false, 'It should throw Error when any player has been created'); +}); From 154abc7bfc9f29b663f97c770b4f07597971ede5 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:57:32 +0100 Subject: [PATCH 09/10] cs fix --- test/unit/player.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 5b3990f9d1..1c853fcf29 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -17,7 +17,7 @@ QUnit.module('Player', { beforeEach() { this.clock = sinon.useFakeTimers(); // reset players storage - for (let playerId in Player.players) { + for (const playerId in Player.players) { if (Player.players[playerId] !== null) { Player.players[playerId].dispose(); } From 4668526300b4379e7d947326614bc2f887666c19 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 16 Nov 2016 09:57:41 +0100 Subject: [PATCH 10/10] add player dispose to test case --- test/unit/player.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 1c853fcf29..e2e8ef7d46 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1279,6 +1279,7 @@ QUnit.test('should not allow to register custom player when any player has been try { videojs.registerComponent('Player', CustomPlayer); } catch (e) { + player.dispose(); return assert.equal(e.message, 'Can not register Player component after player has been created'); }