Skip to content

Commit

Permalink
fix: Throw a player error when trying to play DRM content without eme (
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Sep 23, 2020
1 parent d0ef298 commit ce4d6fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const emeKeySystems = (keySystemOptions, videoPlaylist, audioPlaylist) => {
audio: audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS
};

if (!codecs.audio && codecs.video.split(',').length > 1) {
if (!codecs.audio && codecs.video && codecs.video.split(',').length > 1) {
codecs.video.split(',').forEach(function(codec) {
codec = codec.trim();

Expand Down Expand Up @@ -243,10 +243,6 @@ const setupEmeOptions = ({
audioMedia,
mainPlaylists
}) => {
if (!player.eme) {
return;
}

const sourceOptions = emeKeySystems(sourceKeySystems, media, audioMedia);

if (!sourceOptions) {
Expand All @@ -255,6 +251,13 @@ const setupEmeOptions = ({

player.currentSource().keySystems = sourceOptions;

// eme handles the rest of the setup, so if it is missing
// do nothing.
if (sourceOptions && !player.eme) {
videojs.log.warn('DRM encrypted source cannot be decrypted without a DRM plugin');
return;
}

// works around https://bugs.chromium.org/p/chromium/issues/detail?id=895449
// in non-IE11 browsers. In IE11 this is too early to initialize media keys
if (videojs.browser.IE_VERSION === 11 || !player.eme.initializeMediaKeys) {
Expand Down
27 changes: 25 additions & 2 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5765,9 +5765,9 @@ QUnit.module('setupEmeOptions', {
}
});

QUnit.test('no error if no eme', function(assert) {
QUnit.test('no error if no eme and no key systems', function(assert) {
const player = {};
const sourceKeySystems = {};
const sourceKeySystems = null;
const media = {};
const audioMedia = {};
const mainPlaylists = [];
Expand All @@ -5777,6 +5777,29 @@ QUnit.test('no error if no eme', function(assert) {
assert.ok(true, 'no exception');
});

QUnit.test('log error if no eme and we have key systems', function(assert) {
const sourceKeySystems = {};
const media = {};
const audioMedia = {};
const mainPlaylists = [];
const src = {};
const player = {currentSource: () => src};

let logWarn;
const origWarn = videojs.log.warn;

videojs.log.warn = (line) => {
logWarn = line;
};

setupEmeOptions({ player, sourceKeySystems, media, audioMedia, mainPlaylists });

assert.equal(logWarn, 'DRM encrypted source cannot be decrypted without a DRM plugin', 'logs expected error');
assert.ok(src.hasOwnProperty('keySystems'), 'source key systems was set');

videojs.log.warn = origWarn;
});

QUnit.test('no initialize calls if no source key systems', function(assert) {
let numInitializeCalls = 0;
const player = { eme: { initializeMediaKeys: () => numInitializeCalls++ } };
Expand Down

0 comments on commit ce4d6fd

Please sign in to comment.