Skip to content

Commit

Permalink
perf: Another 5ms of startup time improvements (#6145)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed Aug 29, 2019
1 parent f324d1f commit 22782b8
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 97 deletions.
50 changes: 20 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
Expand Down
3 changes: 3 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const primedBabel = babel({
loose: true,
modules: false
}]
],
plugins: [
'@babel/plugin-transform-object-assign'
]
});

Expand Down
3 changes: 1 addition & 2 deletions src/js/error-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import Component from './component';
import ModalDialog from './modal-dialog';
import mergeOptions from './utils/merge-options';

/**
* A display that indicates an error has occurred. This means that the video
Expand Down Expand Up @@ -57,7 +56,7 @@ class ErrorDisplay extends ModalDialog {
*
* @private
*/
ErrorDisplay.prototype.options_ = mergeOptions(ModalDialog.prototype.options_, {
ErrorDisplay.prototype.options_ = Object.assign({}, ModalDialog.prototype.options_, {
pauseOnOpen: false,
fillAlways: true,
temporary: false,
Expand Down
97 changes: 53 additions & 44 deletions src/js/tech/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import mergeOptions from '../utils/merge-options.js';
import {toTitleCase} from '../utils/string-cases.js';
import {NORMAL as TRACK_TYPES} from '../tracks/track-types';
import setupSourceset from './setup-sourceset';
import defineLazyProperty from '../utils/define-lazy-property.js';

/**
* HTML5 Media Controller - Wrapper for HTML5 Media API
Expand Down Expand Up @@ -887,23 +888,27 @@ class Html5 extends Tech {

/* HTML5 Support Testing ---------------------------------------------------- */

if (Dom.isReal()) {

/**
* Element for testing browser HTML5 media capabilities
*
* @type {Element}
* @constant
* @private
*/
Html5.TEST_VID = document.createElement('video');
/**
* Element for testing browser HTML5 media capabilities
*
* @type {Element}
* @constant
* @private
*/
defineLazyProperty(Html5, 'TEST_VID', function() {
if (!Dom.isReal()) {
return;
}
const video = document.createElement('video');
const track = document.createElement('track');

track.kind = 'captions';
track.srclang = 'en';
track.label = 'English';
Html5.TEST_VID.appendChild(track);
}
video.appendChild(track);

return video;
});

/**
* Check if HTML5 media is supported by this browser/device.
Expand Down Expand Up @@ -1115,15 +1120,12 @@ Html5.Events = [
* @type {boolean}
* @default {@link Html5.canControlVolume}
*/
Html5.prototype.featuresVolumeControl = Html5.canControlVolume();

/**
* Boolean indicating whether the `Tech` supports muting volume.
*
* @type {bolean}
* @default {@link Html5.canMuteVolume}
*/
Html5.prototype.featuresMuteControl = Html5.canMuteVolume();

/**
* Boolean indicating whether the `Tech` supports changing the speed at which the media
Expand All @@ -1134,15 +1136,42 @@ Html5.prototype.featuresMuteControl = Html5.canMuteVolume();
* @type {boolean}
* @default {@link Html5.canControlPlaybackRate}
*/
Html5.prototype.featuresPlaybackRate = Html5.canControlPlaybackRate();

/**
* Boolean indicating whether the `Tech` supports the `sourceset` event.
*
* @type {boolean}
* @default
*/
Html5.prototype.featuresSourceset = Html5.canOverrideAttributes();
/**
* Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeTextTracks}
*/
/**
* Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeVideoTracks}
*/
/**
* Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeAudioTracks}
*/
[
['featuresVolumeControl', 'canControlVolume'],
['featuresMuteControl', 'canMuteVolume'],
['featuresPlaybackRate', 'canControlPlaybackRate'],
['featuresSourceset', 'canOverrideAttributes'],
['featuresNativeTextTracks', 'supportsNativeTextTracks'],
['featuresNativeVideoTracks', 'supportsNativeVideoTracks'],
['featuresNativeAudioTracks', 'supportsNativeAudioTracks']
].forEach(function([key, fn]) {
defineLazyProperty(Html5.prototype, key, () => Html5[fn](), false);
});

/**
* Boolean indicating whether the `HTML5` tech currently supports the media element
Expand Down Expand Up @@ -1182,40 +1211,18 @@ Html5.prototype.featuresProgressEvents = true;
*/
Html5.prototype.featuresTimeupdateEvents = true;

/**
* Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeTextTracks}
*/
Html5.prototype.featuresNativeTextTracks = Html5.supportsNativeTextTracks();

/**
* Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeVideoTracks}
*/
Html5.prototype.featuresNativeVideoTracks = Html5.supportsNativeVideoTracks();

/**
* Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
*
* @type {boolean}
* @default {@link Html5.supportsNativeAudioTracks}
*/
Html5.prototype.featuresNativeAudioTracks = Html5.supportsNativeAudioTracks();

// HTML5 Feature detection and Device Fixes --------------------------------- //
const canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
const mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
let canPlayType;

Html5.patchCanPlayType = function() {

// Android 4.0 and above can play HLS to some extent but it reports being unable to do so
// Firefox and Chrome report correctly
if (browser.ANDROID_VERSION >= 4.0 && !browser.IS_FIREFOX && !browser.IS_CHROME) {
canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
Html5.TEST_VID.constructor.prototype.canPlayType = function(type) {
const mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;

if (type && mpegurlRE.test(type)) {
return 'maybe';
}
Expand All @@ -1227,7 +1234,9 @@ Html5.patchCanPlayType = function() {
Html5.unpatchCanPlayType = function() {
const r = Html5.TEST_VID.constructor.prototype.canPlayType;

Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
if (canPlayType) {
Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
}
return r;
};

Expand Down
4 changes: 1 addition & 3 deletions src/js/tracks/track-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import AudioTrack from './audio-track';
import VideoTrack from './video-track';
import HTMLTrackElement from './html-track-element';

import mergeOptions from '../utils/merge-options';

/*
* This file contains all track properties that are used in
* player.js, tech.js, html5.js and possibly other techs in the future.
Expand Down Expand Up @@ -55,7 +53,7 @@ const REMOTE = {
}
};

const ALL = mergeOptions(NORMAL, REMOTE);
const ALL = Object.assign({}, NORMAL, REMOTE);

REMOTE.names = Object.keys(REMOTE);
NORMAL.names = Object.keys(NORMAL);
Expand Down
Loading

0 comments on commit 22782b8

Please sign in to comment.