From 942718da5c1d22007593775ab9063811735f2045 Mon Sep 17 00:00:00 2001 From: jforbes Date: Wed, 16 Nov 2016 12:13:54 -0500 Subject: [PATCH 1/2] Added option to disable native tracks --- src/js/tech/tech.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/tech/tech.js b/src/js/tech/tech.js index dbbeaaee1c..ed9fafdd64 100644 --- a/src/js/tech/tech.js +++ b/src/js/tech/tech.js @@ -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; } From 42cb533ec0fb73d2d5d8a4196d0809d7c33d8415 Mon Sep 17 00:00:00 2001 From: jforbes Date: Wed, 16 Nov 2016 15:02:12 -0500 Subject: [PATCH 2/2] Added tests --- test/unit/tech/html5.test.js | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/unit/tech/html5.test.js b/test/unit/tech/html5.test.js index 01644205bd..2d2a6eabc8 100644 --- a/test/unit/tech/html5.test.js +++ b/test/unit/tech/html5.test.js @@ -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 = []; @@ -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 = []; @@ -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 = [];