diff --git a/package-lock.json b/package-lock.json index 89fd88e..fb024a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7421,8 +7421,8 @@ "integrity": "sha512-SY76gdxa6qJv6Hd+IayKU7FY2BJw+SR+kJyHnwgyUjXCEEFJ7JGcE+HZiYfW4vq76ypaZRnDxTeZkSF3/Z0PJw==", "dev": true, "requires": { - "is-ci": "1.2.0", - "npm-merge-driver": "2.3.5" + "is-ci": "^1.2.0", + "npm-merge-driver": "^2.3.5" } }, "npm-path": { diff --git a/src/plugin.js b/src/plugin.js index 9da34a6..f0d5727 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -128,11 +128,19 @@ export const handleMsNeedKeyEvent = (event, options, sessions, eventBus) => { return; } - sessions.push({ playready: true }); + let initData = event.initData; + + // Use existing init data from options if provided + if (options.keySystems[PLAYREADY_KEY_SYSTEM] && + options.keySystems[PLAYREADY_KEY_SYSTEM].pssh) { + initData = options.keySystems[PLAYREADY_KEY_SYSTEM].pssh; + } + + sessions.push({ playready: true, initData }); msPrefixed({ video: event.target, - initData: event.initData, + initData, options, eventBus }); diff --git a/test/plugin.test.js b/test/plugin.test.js index 68813e4..cda62b5 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -195,6 +195,21 @@ QUnit.test('handleEncryptedEvent uses predefined init data', function(assert) { }); }); +QUnit.test('handleMsNeedKeyEvent uses predefined init data', function(assert) { + const options = { + keySystems: { + 'com.microsoft.playready': { + pssh: this.initData1 + } + } + }; + const sessions = []; + + handleMsNeedKeyEvent(this.event2, options, sessions); + assert.equal(sessions.length, 1, 'created a session when keySystems in options'); + assert.deepEqual(sessions[0].initData, this.initData1, 'captured initData in the session'); +}); + QUnit.test('handleMsNeedKeyEvent checks for required options', function(assert) { const event = { // mock video target to prevent errors since it's a pain to mock out the continuation