Skip to content

Commit

Permalink
Merge branch 'main' into 8393-throttle-clickable-commponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Essk committed Sep 27, 2023
2 parents f196890 + 473176f commit c2599de
Show file tree
Hide file tree
Showing 21 changed files with 2,253 additions and 1,785 deletions.
4 changes: 1 addition & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"not baidu 7",
"not and_qq 11",
"not and_uc 12",
"not kaios 2",
"not op_mini all",
"not op_mob 64"
"not op_mini all"
],
"bugfixes": true,
"loose": true
Expand Down
2 changes: 0 additions & 2 deletions .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ not ie 11
not baidu 7
not and_qq 11
not and_uc 12
not kaios 2
not op_mini all
not op_mob 64
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<a name="8.6.0"></a>
# [8.6.0](https://github.com/videojs/video.js/compare/v8.5.3...v8.6.0) (2023-09-25)

### Features

* enhanced logger ([#8444](https://github.com/videojs/video.js/issues/8444)) ([cf681e0](https://github.com/videojs/video.js/commit/cf681e0))

### Chores

* **package:** Update VHS version ([#8447](https://github.com/videojs/video.js/issues/8447)) ([372b816](https://github.com/videojs/video.js/commit/372b816))

<a name="8.5.3"></a>
## [8.5.3](https://github.com/videojs/video.js/compare/v8.5.2...v8.5.3) (2023-08-23)

Expand Down
3,743 changes: 1,991 additions & 1,752 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "video.js",
"description": "An HTML5 video player that supports HLS and DASH with a common API and skin.",
"version": "8.5.3",
"version": "8.6.0",
"main": "./dist/video.cjs.js",
"module": "./dist/video.es.js",
"style": "./dist/video-js.css",
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@videojs/http-streaming": "3.5.3",
"@videojs/http-streaming": "3.6.0",
"@videojs/vhs-utils": "^4.0.0",
"@videojs/xhr": "2.6.0",
"aes-decrypter": "^4.0.1",
Expand Down
4 changes: 1 addition & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ const primedBabel = babel({
'not baidu 7',
'not and_qq 11',
'not and_uc 12',
'not kaios 2',
'not op_mini all',
'not op_mob 64'
'not op_mini all'
],
bugfixes: true,
loose: true,
Expand Down
8 changes: 8 additions & 0 deletions src/css/components/_control-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
@include background-color-with-alpha($primary-background-color, $primary-background-transparency);
}

// Locks the display only if:
// - controls are not disabled
// - native controls are not used
// - there is no error
.video-js:not(.vjs-controls-disabled, .vjs-using-native-controls, .vjs-error) .vjs-control-bar.vjs-lock-showing {
display: flex !important;
}

// Video has started playing or we are in audioOnlyMode
.vjs-has-started .vjs-control-bar,
.vjs-audio-only-mode .vjs-control-bar {
Expand Down
21 changes: 19 additions & 2 deletions src/js/big-play-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BigPlayButton extends Button {
* This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
* for more detailed information on what a click can be.
*
* @param {KeyboardEvent} event
* @param {KeyboardEvent|MouseEvent|TouchEvent} event
* The `keydown`, `tap`, or `click` event that caused this function to be
* called.
*
Expand All @@ -47,7 +47,7 @@ class BigPlayButton extends Button {
const playPromise = this.player_.play();

// exit early if clicked via the mouse
if (this.mouseused_ && event.clientX && event.clientY) {
if (this.mouseused_ && 'clientX' in event && 'clientY' in event) {
silencePromise(playPromise);

if (this.player_.tech(true)) {
Expand All @@ -74,12 +74,29 @@ class BigPlayButton extends Button {
}
}

/**
* Event handler that is called when a `BigPlayButton` receives a
* `keydown` event.
*
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
*/
handleKeyDown(event) {
this.mouseused_ = false;

super.handleKeyDown(event);
}

/**
* Handle `mousedown` events on the `BigPlayButton`.
*
* @param {MouseEvent} event
* `mousedown` or `touchstart` event that triggered this function
*
* @listens mousedown
*/
handleMouseDown(event) {
this.mouseused_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Button extends ClickableComponent {
* This gets called when a `Button` has focus and `keydown` is triggered via a key
* press.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The event that caused this function to get called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/clickable-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ClickableComponent extends Component {
*
* By default, if the key is Space or Enter, it will trigger a `click` event.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/close-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CloseButton extends Button {
*
* By default, if the key is Esc, it will trigger a `click` event.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
4 changes: 2 additions & 2 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ class Component {
* delegates to `handleKeyDown`. This means anyone calling `handleKeyPress`
* will not see their method calls stop working.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The event that caused this function to be called.
*/
handleKeyPress(event) {
Expand All @@ -1336,7 +1336,7 @@ class Component {
* support toggling the controls through a tap on the video. They get enabled
* because every sub-component would have extra overhead otherwise.
*
* @private
* @protected
* @fires Component#tap
* @listens Component#touchstart
* @listens Component#touchmove
Expand Down
2 changes: 1 addition & 1 deletion src/js/menu/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MenuItem extends ClickableComponent {
* Ignore keys which are used by the menu, but pass any other ones up. See
* {@link ClickableComponent#handleKeyDown} for instances where this is called.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Menu extends Component {
/**
* Handle a `keydown` event on this menu. This listener is added in the constructor.
*
* @param {Event} event
* @param {KeyboardEvent} event
* A `keydown` event that happened on the menu.
*
* @listens keydown
Expand Down
6 changes: 4 additions & 2 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,9 @@ class Player extends Component {
handleTechError_() {
const error = this.tech_.error();

this.error(error);
if (error) {
this.error(error);
}
}

/**
Expand Down Expand Up @@ -3164,7 +3166,7 @@ class Player extends Component {
* This allows player-wide hotkeys (either as defined below, or optionally
* by an external function).
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
3 changes: 2 additions & 1 deletion src/js/tracks/text-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ class TextTrack extends Track {
addCue(originalCue) {
let cue = originalCue;

if (cue.constructor && cue.constructor.name !== 'VTTCue') {
// Testing if the cue is a VTTCue in a way that survives minification
if (!('getCueAsHTML' in cue)) {
cue = new window.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text);

for (const prop in originalCue) {
Expand Down
55 changes: 45 additions & 10 deletions src/js/utils/create-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,34 @@ let history = [];
* Log messages to the console and history based on the type of message
*
* @private
* @param {string} type
* @param {string} name
* The name of the console method to use.
*
* @param {Array} args
* @param {Object} log
* The arguments to be passed to the matching console method.
*
* @param {string} [styles]
* styles for name
*/
const LogByTypeFactory = (name, log) => (type, level, args) => {
const LogByTypeFactory = (name, log, styles) => (type, level, args) => {
const lvl = log.levels[level];
const lvlRegExp = new RegExp(`^(${lvl})$`);

let resultName = name;

if (type !== 'log') {

// Add the type to the front of the message when it's not "log".
args.unshift(type.toUpperCase() + ':');
}

if (styles) {
resultName = `%c${name}`;
args.unshift(styles);
}

// Add console prefix after adding to history.
args.unshift(name + ':');
args.unshift(resultName + ':');

// Add a clone of the args at this point to history.
if (history) {
Expand Down Expand Up @@ -66,7 +76,7 @@ const LogByTypeFactory = (name, log) => (type, level, args) => {
fn[Array.isArray(args) ? 'apply' : 'call'](window.console, args);
};

export default function createLogger(name) {
export default function createLogger(name, delimiter = ':', styles = '') {
// This is the private tracking variable for logging level.
let level = 'info';

Expand Down Expand Up @@ -99,22 +109,47 @@ export default function createLogger(name) {
};

// This is the logByType helper that the logging methods below use
logByType = LogByTypeFactory(name, log);
logByType = LogByTypeFactory(name, log, styles);

/**
* Create a new sublogger which chains the old name to the new name.
* Create a new subLogger which chains the old name to the new name.
*
* For example, doing `videojs.log.createLogger('player')` and then using that logger will log the following:
* ```js
* mylogger('foo');
* // > VIDEOJS: player: foo
* ```
*
* @param {string} name
* @param {string} subName
* The name to add call the new logger
* @param {string} [subDelimiter]
* Optional delimiter
* @param {string} [subStyles]
* Optional styles
* @return {Object}
*/
log.createLogger = (subName, subDelimiter, subStyles) => {
const resultDelimiter = subDelimiter !== undefined ? subDelimiter : delimiter;
const resultStyles = subStyles !== undefined ? subStyles : styles;
const resultName = `${name} ${resultDelimiter} ${subName}`;

return createLogger(resultName, resultDelimiter, resultStyles);
};

/**
* Create a new logger.
*
* @param {string} newName
* The name for the new logger
* @param {string} [newDelimiter]
* Optional delimiter
* @param {string} [newStyles]
* Optional styles
* @return {Object}
*/
log.createLogger = (subname) => createLogger(name + ': ' + subname);
log.createNewLogger = (newName, newDelimiter, newStyles) => {
return createLogger(newName, newDelimiter, newStyles);
};

/**
* Enumeration of available logging levels, where the keys are the level names
Expand Down Expand Up @@ -151,7 +186,7 @@ export default function createLogger(name) {
* If a string matching a key from {@link module:log.levels} is provided, acts
* as a setter.
*
* @param {string} [lvl]
* @param {'all'|'debug'|'info'|'warn'|'error'|'off'} [lvl]
* Pass a valid level to set a new logging level.
*
* @return {string}
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function _cleanUpEvents(elem, type) {
* @param {Element|Object} elem
* Element or object to bind listeners to
*
* @param {string} type
* @param {string[]} types
* Type of event to bind to.
*
* @param {Function} callback
Expand Down
34 changes: 34 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3383,3 +3383,37 @@ QUnit.test('crossOrigin value should be maintained after loadMedia is called', f
playerExample2.dispose();
playerExample3.dispose();
});

QUnit.test('should not reset the error when the tech triggers an error that is null', function(assert) {
sinon.stub(log, 'error');

const player = TestHelpers.makePlayer();

player.src({
src: 'http://example.com/movie.unsupported-format',
type: 'video/unsupported-format'
});

this.clock.tick(60);

// Simulates Chromium's behavior when the poster is invalid

// is only there for context, but does nothing
player.poster('invalid');

const spyError = sinon.spy(player, 'error');
// Chromium behavior produced by the video element
const errorStub = sinon.stub(player.tech(true), 'error').callsFake(() => null);

player.tech(true).trigger('error');
// End

assert.ok(player.hasClass('vjs-error'), 'player has vjs-error class');
assert.ok(spyError.notCalled, 'error was not called');
assert.ok(player.error(), 'error is retained');

player.dispose();
spyError.restore();
errorStub.restore();
log.error.restore();
});
Loading

0 comments on commit c2599de

Please sign in to comment.