Skip to content

Commit

Permalink
fix: Use correct callback function signature for PlayReady license re…
Browse files Browse the repository at this point in the history
…quest callbacks. (#81)
  • Loading branch information
misteroneill committed May 1, 2019
1 parent c2b7d05 commit 07a1f25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ By default, videojs-contrib-eme is not able to decrypt any audio/video.

In order to decrypt audio/video, a user must pass in either relevant license URIs, or methods specific to a source and its combination of key system and codec. These are provided to the plugin via either videojs-contrib-eme's plugin options or source options.

If you're new to DRM on the web, read [about how EME is used to play protected content on the web](https://developers.google.com/web/fundamentals/media/eme).

### Initialization

The videojs-contrib-eme plugin must be initialized before a source is loaded into the player:
Expand Down
9 changes: 8 additions & 1 deletion src/playready.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ export const requestPlayreadyLicense = (keySystemOptions, messageBuffer, emeOpti
headers,
body: message,
responseType: 'arraybuffer'
}, callback);
}, (err, response, responseBody) => {
if (err) {
callback(err);
return;
}

callback(null, responseBody);
});
};
14 changes: 7 additions & 7 deletions test/ms-prefixed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ QUnit.test('calls getKey when provided on key message', function(assert) {
assert.equal(this.session.keys[0], 'a key', 'added correct key to session');

getKeyCallback = (callback) => {
callback('an error', 'an errored key');
callback('an error', {}, 'an errored key');
};

this.session.trigger({
Expand Down Expand Up @@ -253,14 +253,14 @@ QUnit.test('makes request when nothing provided on key message', function(assert
body: utils.stringToArrayBuffer('key value')
};

xhrCalls[0].callback('an error', response);
xhrCalls[0].callback('an error', {}, response);

assert.equal(errorMessage,
'Unable to request key from url: destination-url',
'triggers mskeyerror on event bus when callback has an error');
assert.equal(this.session.keys.length, 0, 'no key added to session');

xhrCalls[0].callback(null, response);
xhrCalls[0].callback(null, {}, response);

assert.equal(this.session.keys.length, 1, 'key added to session');
assert.deepEqual(this.session.keys[0],
Expand Down Expand Up @@ -372,14 +372,14 @@ QUnit.test('makes request with provided url string on key message', function(ass
body: utils.stringToArrayBuffer('key value')
};

xhrCalls[0].callback('an error', response);
xhrCalls[0].callback('an error', {}, response);

assert.equal(errorMessage,
'Unable to request key from url: provided-url',
'triggers mskeyerror on event bus when callback has an error');
assert.equal(this.session.keys.length, 0, 'no key added to session');

xhrCalls[0].callback(null, response);
xhrCalls[0].callback(null, {}, response);

assert.equal(this.session.keys.length, 1, 'key added to session');
assert.deepEqual(this.session.keys[0],
Expand Down Expand Up @@ -456,15 +456,15 @@ QUnit.test('makes request with provided url on key message', function(assert) {
body: utils.stringToArrayBuffer('key value')
};

xhrCalls[0].callback('an error', response);
xhrCalls[0].callback('an error', {}, response);

assert.equal(callCounts.licenseRequestAttempts, 1, 'license request event triggered');
assert.equal(errorMessage,
'Unable to request key from url: provided-url',
'triggers mskeyerror on event bus when callback has an error');
assert.equal(this.session.keys.length, 0, 'no key added to session');

xhrCalls[0].callback(null, response);
xhrCalls[0].callback(null, {}, response);

assert.equal(callCounts.licenseRequestAttempts, 2,
'second license request event triggered');
Expand Down

0 comments on commit 07a1f25

Please sign in to comment.