Skip to content

Commit

Permalink
feat(tracks): Added option to disable native tracks (#3786)
Browse files Browse the repository at this point in the history
This adds nativeAudioTracks and nativeVideoTracks tech options, this will disable hooking into the native track APIs. This would be useful when using videojs-contrib-hls on Edge.
  • Loading branch information
forbesjo authored and gkatsev committed Nov 23, 2016
1 parent d69551a commit 9b9f89e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ class Tech extends Component {
this.manualTimeUpdatesOn();
}

if (options.nativeCaptions === false || options.nativeTextTracks === false) {
['Text', 'Audio', 'Video'].forEach((track) => {
if (options[`native${track}Tracks`] === false) {
this[`featuresNative${track}Tracks`] = false;
}
});

if (options.nativeCaptions === false) {
this.featuresNativeTextTracks = false;
}

Expand Down
60 changes: 60 additions & 0 deletions test/unit/tech/html5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ if (Html5.supportsNativeTextTracks()) {
assert.equal(adds[2][0], 'removetrack', 'removetrack event handler added');
});

QUnit.test('does not add native textTrack listeners when disabled', function(assert) {
const events = [];
const tt = {
length: 0,
addEventListener: (type, fn) => events.push([type, fn]),
removeEventListener: (type, fn) => events.push([type, fn])
};
const el = document.createElement('div');

el.textTracks = tt;

/* eslint-disable no-unused-vars */
const htmlTech = new Html5({el, nativeTextTracks: false});
/* eslint-enable no-unused-vars */

assert.equal(events.length, 0, 'no listeners added');

/* eslint-disable no-unused-vars */
const htmlTechAlternate = new Html5({el, nativeCaptions: false});
/* eslint-enable no-unused-vars */

assert.equal(events.length, 0, 'no listeners added');
});

QUnit.test('remove all tracks from emulated list on dispose', function(assert) {
const adds = [];
const rems = [];
Expand Down Expand Up @@ -351,6 +375,24 @@ if (Html5.supportsNativeAudioTracks()) {
assert.equal(adds[2][0], 'removetrack', 'removetrack event handler added');
});

QUnit.test('does not add native audioTrack listeners when disabled', function(assert) {
const events = [];
const at = {
length: 0,
addEventListener: (type, fn) => events.push([type, fn]),
removeEventListener: (type, fn) => events.push([type, fn])
};
const el = document.createElement('div');

el.audioTracks = at;

/* eslint-disable no-unused-vars */
const htmlTech = new Html5({el, nativeAudioTracks: false});
/* eslint-enable no-unused-vars */

assert.equal(events.length, 0, 'no listeners added');
});

QUnit.test('remove all tracks from emulated list on dispose', function(assert) {
const adds = [];
const rems = [];
Expand Down Expand Up @@ -401,6 +443,24 @@ if (Html5.supportsNativeVideoTracks()) {
assert.equal(adds[2][0], 'removetrack', 'removetrack event handler added');
});

QUnit.test('does not add native audioTrack listeners when disabled', function(assert) {
const events = [];
const vt = {
length: 0,
addEventListener: (type, fn) => events.push([type, fn]),
removeEventListener: (type, fn) => events.push([type, fn])
};
const el = document.createElement('div');

el.videoTracks = vt;

/* eslint-disable no-unused-vars */
const htmlTech = new Html5({el, nativeVideoTracks: false});
/* eslint-enable no-unused-vars */

assert.equal(events.length, 0, 'no listeners added');
});

QUnit.test('remove all tracks from emulated list on dispose', function(assert) {
const adds = [];
const rems = [];
Expand Down

0 comments on commit 9b9f89e

Please sign in to comment.