Skip to content

Commit

Permalink
fix: check for init data (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
forbesjo committed Oct 24, 2018
1 parent ff0a271 commit d966e5b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const handleEncryptedEvent = (event, options, sessions, eventBus) => {
// set of stream(s) or media data."
// eslint-disable-next-line max-len
// @see [Initialization Data Spec]{@link https://www.w3.org/TR/encrypted-media/#initialization-data}
if (hasSession(sessions, initData)) {
if (hasSession(sessions, initData) || !initData) {
// TODO convert to videojs.log.debug and add back in
// https://github.com/videojs/video.js/pull/4780
// videojs.log('eme',
Expand All @@ -89,7 +89,7 @@ export const handleEncryptedEvent = (event, options, sessions, eventBus) => {
};

export const handleWebKitNeedKeyEvent = (event, options, eventBus) => {
if (!options.keySystems || !options.keySystems[FAIRPLAY_KEY_SYSTEM]) {
if (!options.keySystems || !options.keySystems[FAIRPLAY_KEY_SYSTEM] || !event.initData) {
// return silently since it may be handled by a different system
return;
}
Expand Down Expand Up @@ -136,6 +136,10 @@ export const handleMsNeedKeyEvent = (event, options, sessions, eventBus) => {
initData = options.keySystems[PLAYREADY_KEY_SYSTEM].pssh;
}

if (!initData) {
return;
}

sessions.push({ playready: true, initData });

msPrefixed({
Expand Down
37 changes: 36 additions & 1 deletion test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ QUnit.test('handleEncryptedEvent checks for required options', function(assert)
});
});

QUnit.test('handleEncryptedEvent checks for required init data', function(assert) {
const done = assert.async();
const sessions = [];

handleEncryptedEvent({ target: {}, initData: null }, this.options, sessions).then(() => {
assert.equal(sessions.length, 0, 'did not create a session when no init data');
done();
});
});

QUnit.test('handleEncryptedEvent creates session', function(assert) {
const done = assert.async();
const sessions = [];
Expand Down Expand Up @@ -317,8 +327,24 @@ QUnit.test('handleMsNeedKeyEvent checks for required options', function(assert)
assert.equal(sessions[0], createdSession, 'did not replace session');
});

QUnit.test('handleMsNeedKeyEvent checks for required init data', function(assert) {
const event = {
// mock video target to prevent errors since it's a pain to mock out the continuation
// of functionality on a successful pass through of the guards
target: {},
initData: null
};
const options = { keySystems: { 'com.microsoft.playready': true } };
const sessions = [];

handleMsNeedKeyEvent(event, options, sessions);
assert.equal(sessions.length, 0, 'no session created when no init data');
});

QUnit.test('handleWebKitNeedKeyEvent checks for required options', function(assert) {
const event = {};
const event = {
initData: new Uint8Array([1, 2, 3])
};
let options = {};

assert.notOk(handleWebKitNeedKeyEvent(event, options), 'no return when no options');
Expand All @@ -336,6 +362,15 @@ QUnit.test('handleWebKitNeedKeyEvent checks for required options', function(asse
'valid return when proper FairPlay key system');
});

QUnit.test('handleWebKitNeedKeyEvent checks for required init data', function(assert) {
const event = {
initData: null
};
const options = { keySystems: { 'com.apple.fps.1_0': {} } };

assert.notOk(handleWebKitNeedKeyEvent(event, options), 'no return when no init data');
});

QUnit.module('plugin isolated functions');

QUnit.test('hasSession determines if a session exists', function(assert) {
Expand Down

0 comments on commit d966e5b

Please sign in to comment.