mirror of
https://github.com/videojs/video.js.git
synced 2025-01-19 10:54:16 +02:00
feat: add debug mode (#6687)
When `debug(true)` is called, it will fire a `debugon` event that plugins and components can then use to do extra logging or anything else that's helpful to for debugging. It will also set the log level to debug. When `debug(false)` is called, it will fire a `debugoff` event that plugins and components can then use to stop doing extra logging or helpful debugging. It will reset the log level to whatever it was previously. Co-authored-by: ipadilla4 <ipadilla@brightcove.com>
This commit is contained in:
parent
f6a66e62de
commit
3d505ef0c5
@ -379,6 +379,9 @@ class Player extends Component {
|
||||
// Init state userActive_
|
||||
this.userActive_ = false;
|
||||
|
||||
// Init debugEnabled_
|
||||
this.debugEnabled_ = false;
|
||||
|
||||
// if the global option object was accidentally blown away by
|
||||
// someone, bail early with an informative error
|
||||
if (!this.options_ ||
|
||||
@ -485,6 +488,11 @@ class Player extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
// Enable debug mode to fire debugon event for all plugins.
|
||||
if (options.debug) {
|
||||
this.debug(true);
|
||||
}
|
||||
|
||||
this.options_.playerOptions = playerOptionsCopy;
|
||||
|
||||
this.middleware_ = [];
|
||||
@ -4734,6 +4742,30 @@ class Player extends Component {
|
||||
// IE10-specific (2012 flex spec), available for completeness
|
||||
'msFlexOrder' in elem.style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set debug mode to enable/disable logs at info level.
|
||||
*
|
||||
* @param {boolean} enabled
|
||||
* @fires Player#debugon
|
||||
* @fires Player#debugoff
|
||||
*/
|
||||
debug(enabled) {
|
||||
if (enabled === undefined) {
|
||||
return this.debugEnabled_;
|
||||
}
|
||||
if (enabled) {
|
||||
this.trigger('debugon');
|
||||
this.previousLogLevel_ = this.log.level;
|
||||
this.log.level('debug');
|
||||
this.debugEnabled_ = true;
|
||||
} else {
|
||||
this.trigger('debugoff');
|
||||
this.log.level(this.previousLogLevel_);
|
||||
this.previousLogLevel_ = undefined;
|
||||
this.debugEnabled_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2259,6 +2259,62 @@ QUnit.test('Should accept multiple calls to currentTime after player initializat
|
||||
assert.equal(player.currentTime(), 800, 'The last value passed is stored as the currentTime value');
|
||||
});
|
||||
|
||||
QUnit.test('Should fire debugon event when debug mode is enabled', function(assert) {
|
||||
const player = TestHelpers.makePlayer({});
|
||||
const debugOnSpy = sinon.spy();
|
||||
|
||||
player.on('debugon', debugOnSpy);
|
||||
player.debug(true);
|
||||
|
||||
assert.ok(debugOnSpy.calledOnce, 'debugon event was fired');
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
QUnit.test('Should fire debugoff event when debug mode is disabled', function(assert) {
|
||||
const player = TestHelpers.makePlayer({});
|
||||
const debugOffSpy = sinon.spy();
|
||||
|
||||
player.on('debugoff', debugOffSpy);
|
||||
player.debug(false);
|
||||
|
||||
assert.ok(debugOffSpy.calledOnce, 'debugoff event was fired');
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
QUnit.test('Should enable debug mode and store log level when calling options', function(assert) {
|
||||
const player = TestHelpers.makePlayer({debug: true});
|
||||
|
||||
assert.ok(player.previousLogLevel_, 'debug', 'previous log level is stored when enabling debug');
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
QUnit.test('Should restore previous log level when disabling debug mode', function(assert) {
|
||||
const player = TestHelpers.makePlayer();
|
||||
|
||||
player.log.level('error');
|
||||
player.debug(true);
|
||||
assert.ok(player.log.level(), 'debug', 'log level is debug when debug is enabled');
|
||||
|
||||
player.debug(false);
|
||||
assert.ok(player.log.level(), 'error', 'previous log level was restored');
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
QUnit.test('Should return if debug is enabled or disabled', function(assert) {
|
||||
const player = TestHelpers.makePlayer();
|
||||
|
||||
player.debug(true);
|
||||
const enabled = player.debug();
|
||||
|
||||
assert.ok(enabled);
|
||||
|
||||
player.debug(false);
|
||||
const disabled = player.debug();
|
||||
|
||||
assert.notOk(disabled);
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
const testOrSkip = 'pictureInPictureEnabled' in document ? 'test' : 'skip';
|
||||
|
||||
QUnit[testOrSkip]('Should only allow requestPictureInPicture if the tech supports it', function(assert) {
|
||||
@ -2289,5 +2345,4 @@ QUnit[testOrSkip]('Should only allow requestPictureInPicture if the tech support
|
||||
delete player.tech_.el_.disablePictureInPicture;
|
||||
player.requestPictureInPicture();
|
||||
assert.equal(count, 1, 'requestPictureInPicture not passed through when tech does not support');
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user