diff --git a/src/js/video.js b/src/js/video.js index 96e79d7cc7..9b3e19e91c 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -65,8 +65,6 @@ if (typeof HTMLVideoElement === 'undefined' && function videojs(id, options, ready) { let tag; - options = options || {}; - // Allow for element or ID to be passed in // String ID if (typeof id === 'string') { @@ -111,6 +109,8 @@ function videojs(id, options, ready) { return tag.player || Player.players[tag.playerId]; } + options = options || {}; + videojs.hooks('beforesetup').forEach(function(hookFunction) { const opts = hookFunction(tag, mergeOptions(options)); diff --git a/test/unit/video.test.js b/test/unit/video.test.js index c9252613c1..2472d06600 100644 --- a/test/unit/video.test.js +++ b/test/unit/video.test.js @@ -2,6 +2,7 @@ import videojs from '../../src/js/video.js'; import TestHelpers from './test-helpers.js'; import * as Dom from '../../src/js/utils/dom.js'; +import log from '../../src/js/utils/log.js'; import document from 'global/document'; QUnit.module('video.js'); @@ -45,6 +46,44 @@ QUnit.test('should return a video player instance', function(assert) { player2.dispose(); }); +QUnit.test('should log about already initalized players if options already passed', +function(assert) { + const origWarnLog = log.warn; + const fixture = document.getElementById('qunit-fixture'); + const warnLogs = []; + + log.warn = (args) => { + warnLogs.push(args); + }; + + fixture.innerHTML += ''; + + const player = videojs('test_vid_id', { techOrder: ['techFaker'] }); + + assert.ok(player, 'created player from tag'); + assert.equal(player.id(), 'test_vid_id', 'player has the right ID'); + assert.equal(warnLogs.length, 0, 'no warn logs'); + + const playerAgain = videojs('test_vid_id'); + + assert.equal(player, playerAgain, 'did not create a second player from same tag'); + assert.equal(warnLogs.length, 0, 'no warn logs'); + + const playerAgainWithOptions = videojs('test_vid_id', { techOrder: ['techFaker'] }); + + assert.equal(player, + playerAgainWithOptions, + 'did not create a second player from same tag'); + assert.equal(warnLogs.length, 1, 'logged a warning'); + assert.equal(warnLogs[0], + 'Player "test_vid_id" is already initialised. Options will not be applied.', + 'logged the right message'); + + log.warn = origWarnLog; + + player.dispose(); +}); + QUnit.test('should return a video player instance from el html5 tech', function(assert) { const fixture = document.getElementById('qunit-fixture');