mirror of
https://github.com/videojs/video.js.git
synced 2025-07-15 01:34:23 +02:00
fix: registering new player component
Do not allow to register new Player component, if any instance of the current component still exists. Fixes #8925
This commit is contained in:
@ -2023,14 +2023,16 @@ class Component {
|
|||||||
|
|
||||||
// If we have players that were disposed, then their name will still be
|
// If we have players that were disposed, then their name will still be
|
||||||
// in Players.players. So, we must loop through and verify that the value
|
// in Players.players. So, we must loop through and verify that the value
|
||||||
// for each item is not null. This allows registration of the Player component
|
// for each item is null. This allows registration of the Player component
|
||||||
// after all players have been disposed or before any were created.
|
// after all players have been disposed or before any were created.
|
||||||
if (players &&
|
if (players && playerNames.length > 0) {
|
||||||
playerNames.length > 0 &&
|
for (let i = 0; i < playerNames.length; i++) {
|
||||||
playerNames.map((pname) => players[pname]).every(Boolean)) {
|
if (players[playerNames[i]] !== null) {
|
||||||
throw new Error('Can not register Player component after player has been created.');
|
throw new Error('Can not register Player component after player has been created.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component.components_[name] = ComponentToRegister;
|
Component.components_[name] = ComponentToRegister;
|
||||||
Component.components_[toLowerCase(name)] = ComponentToRegister;
|
Component.components_[toLowerCase(name)] = ComponentToRegister;
|
||||||
|
@ -2345,6 +2345,41 @@ QUnit.test('should not allow to register custom player when any player has been
|
|||||||
videojs.registerComponent('Player', Player);
|
videojs.registerComponent('Player', Player);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should not allow to register custom player when any player still exists', function(assert) {
|
||||||
|
const videoTag1 = document.createElement('video');
|
||||||
|
const videoTag2 = document.createElement('video');
|
||||||
|
|
||||||
|
const fixture = document.getElementById('qunit-fixture');
|
||||||
|
|
||||||
|
fixture.appendChild(videoTag1);
|
||||||
|
fixture.appendChild(videoTag2);
|
||||||
|
|
||||||
|
const player1 = videojs(videoTag1);
|
||||||
|
const player2 = videojs(videoTag2);
|
||||||
|
|
||||||
|
class CustomPlayer extends Player {}
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
videojs.registerComponent('Player', CustomPlayer);
|
||||||
|
}, 'Can not register Player component after player has been created');
|
||||||
|
|
||||||
|
player1.dispose();
|
||||||
|
|
||||||
|
// still throws, because player2 still exists
|
||||||
|
assert.throws(function() {
|
||||||
|
videojs.registerComponent('Player', CustomPlayer);
|
||||||
|
}, 'Can not register Player component after player has been created');
|
||||||
|
|
||||||
|
player2.dispose();
|
||||||
|
|
||||||
|
// successfully registers, because no player exists anymore
|
||||||
|
// should not throw
|
||||||
|
videojs.registerComponent('Player', CustomPlayer);
|
||||||
|
|
||||||
|
// reset the Player to the original value;
|
||||||
|
videojs.registerComponent('Player', Player);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('setters getters passed to tech', function(assert) {
|
QUnit.test('setters getters passed to tech', function(assert) {
|
||||||
const tag = TestHelpers.makeTag();
|
const tag = TestHelpers.makeTag();
|
||||||
const fixture = document.getElementById('qunit-fixture');
|
const fixture = document.getElementById('qunit-fixture');
|
||||||
|
Reference in New Issue
Block a user