Skip to content

Commit

Permalink
fix: Skip flash-based source handler with DASH source (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
forbesjo authored Jan 17, 2018
1 parent 1c2a38b commit 8422a18
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 41 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
sudo: required
dist: trusty
language: node_js
node_js:
- 8
addons:
chrome: stable
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-detect-browsers": "^2.0.0",
"karma-firefox-launcher": "^0.1.0",
"karma-firefox-launcher": "^1.1.0",
"karma-ie-launcher": "^0.2.0",
"karma-qunit": "^1.2.1",
"karma-safari-launcher": "^0.1.0",
Expand Down
11 changes: 7 additions & 4 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ class HlsHandler extends Component {
* this object in normal usage.
*/
const HlsSourceHandler = function(mode) {
const sourceHandlerOptions = { hls: { mode } };

return {
canHandleSource(srcObj, options = {}) {
let localOptions = videojs.mergeOptions(videojs.options, options);
Expand All @@ -647,10 +649,10 @@ const HlsSourceHandler = function(mode) {
localOptions.hls.mode !== mode) {
return false;
}
return HlsSourceHandler.canPlayType(srcObj.type, localOptions);
return HlsSourceHandler.canPlayType(srcObj.type, videojs.mergeOptions(localOptions, sourceHandlerOptions));
},
handleSource(source, tech, options = {}) {
let localOptions = videojs.mergeOptions(videojs.options, options, {hls: {mode}});
let localOptions = videojs.mergeOptions(videojs.options, options, sourceHandlerOptions);

if (mode === 'flash') {
// We need to trigger this asynchronously to give others the chance
Expand All @@ -667,7 +669,7 @@ const HlsSourceHandler = function(mode) {
return tech.hls;
},
canPlayType(type, options = {}) {
let localOptions = videojs.mergeOptions(videojs.options, options);
let localOptions = videojs.mergeOptions(videojs.options, sourceHandlerOptions, options);

if (HlsSourceHandler.canPlayType(type, localOptions)) {
return 'maybe';
Expand All @@ -685,7 +687,8 @@ HlsSourceHandler.canPlayType = function(type, options) {

const sourceType = simpleTypeFromSourceType(type);

if (sourceType === 'dash') {
if (sourceType === 'dash' && options.hls.mode !== 'flash') {
// favor native DASH support if it's available
if (!options.hls.overrideNative && Hls.supportsNativeDash) {
return false;
}
Expand Down
54 changes: 33 additions & 21 deletions test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,35 +372,47 @@ QUnit.module('Configuration - Global Only', {
}
});

QUnit.test('DASH can be handled', function(assert) {
let htmlCanHandleSource = new HlsSourceHandler('html5').canHandleSource;
let flashCanHandleSource = new HlsSourceHandler('flash').canHandleSource;

assert.ok(htmlCanHandleSource({type: 'application/dash+xml'}), 'supported with MSE');
assert.notOk(flashCanHandleSource({type: 'application/dash+xml'}), 'not supported in Flash');
});

QUnit.test('global mode override - flash', function(assert) {
videojs.options.hls.mode = 'flash';
let htmlSourceHandler = new HlsSourceHandler('html5');
let flashSourceHandler = new HlsSourceHandler('flash');
let htmlCanHandleSource = new HlsSourceHandler('html5').canHandleSource;
let flashCanHandleSource = new HlsSourceHandler('flash').canHandleSource;

assert.notOk(htmlCanHandleSource({type: 'application/x-mpegURL'}),
'Cannot play html as we are overriden not to');

assert.equal(
htmlSourceHandler.canHandleSource({type: 'application/x-mpegURL'}),
false,
assert.ok(flashCanHandleSource({type: 'application/x-mpegURL'}),
'Can play flash as it is supported and overrides allow');

assert.notOk(htmlCanHandleSource({type: 'application/dash+xml'}),
'Cannot play html as we are overriden not to');

assert.equal(
flashSourceHandler.canHandleSource({type: 'application/x-mpegURL'}),
true,
'Can play flash as it is supported and overides allow');
assert.notOk(flashCanHandleSource({type: 'application/dash+xml'}),
'Cannot play flash as it is unsupported');
});

QUnit.test('global mode override - html', function(assert) {
videojs.options.hls.mode = 'html5';
let htmlSourceHandler = new HlsSourceHandler('html5');
let flashSourceHandler = new HlsSourceHandler('flash');

assert.equal(
htmlSourceHandler.canHandleSource({type: 'application/x-mpegURL'}),
true,
'Can play html as we support it and overides allow');

assert.equal(
flashSourceHandler.canHandleSource({type: 'application/x-mpegURL'}),
false,
'Cannot play flash as we are overiden not to');
let htmlCanHandleSource = new HlsSourceHandler('html5').canHandleSource;
let flashCanHandleSource = new HlsSourceHandler('flash').canHandleSource;

assert.ok(htmlCanHandleSource({type: 'application/x-mpegURL'}),
'Can play html as we support it and overrides allow');

assert.notOk(flashCanHandleSource({type: 'application/x-mpegURL'}),
'Cannot play flash as we are overriden not to');

assert.ok(htmlCanHandleSource({type: 'application/dash+xml'}),
'Can play html as we support it and overrides allow');

assert.notOk(flashCanHandleSource({type: 'application/dash+xml'}),
'Cannot play flash as we are overriden not to');
});

8 changes: 7 additions & 1 deletion test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(config) {
};

if (process.env.TRAVIS) {
config.browsers = ['ChromeHeadless'];
config.browsers = ['ChromeHeadlessNoSandbox'];
}

// If no browsers are specified, we enable `karma-detect-browsers`
Expand All @@ -44,6 +44,12 @@ module.exports = function(config) {
level: 'error',
terminal: false
},
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
preprocessors: {
'test/**/*.test.js': ['browserify']
},
Expand Down
20 changes: 11 additions & 9 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2000,15 +2000,17 @@ QUnit.test('the source handler supports HLS mime types', function(assert) {
});

QUnit.test('the source handler supports DASH mime types', function(assert) {
const techs = ['html5', 'flash'];

techs.forEach(function(techName) {
assert.ok(HlsSourceHandler(techName).canHandleSource({
type: 'aPplication/dAsh+xMl'
}), 'supports application/dash+xml');
assert.ok(HlsSourceHandler(techName).canPlayType('aPpLicAtion/DaSh+XmL'),
'supports application/dash+xml');
});
assert.ok(HlsSourceHandler('html5').canHandleSource({
type: 'aPplication/dAsh+xMl'
}), 'supports application/dash+xml');
assert.ok(HlsSourceHandler('html5').canPlayType('aPpLicAtion/DaSh+XmL'),
'supports application/dash+xml');

assert.notOk(HlsSourceHandler('flash').canHandleSource({
type: 'aPplication/dAsh+xMl'
}), 'does not support application/dash+xml');
assert.notOk(HlsSourceHandler('flash').canPlayType('aPpLicAtion/DaSh+XmL'),
'does not support application/dash+xml');
});

QUnit.test('the source handler does not support non HLS/DASH mime types',
Expand Down

0 comments on commit 8422a18

Please sign in to comment.