Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try to re-request key if the session expired #120

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/eme.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ export const getSupportedKeySystem = (keySystems) => {
return promise;
};

export const makeNewRequest = ({
mediaKeys,
initDataType,
initData,
options,
getLicense,
removeSession,
eventBus
}) => {
export const makeNewRequest = (requestOptions) => {
const {
mediaKeys,
initDataType,
initData,
options,
getLicense,
removeSession,
eventBus
} = requestOptions;
const keySession = mediaKeys.createSession();

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -140,6 +141,7 @@ export const makeNewRequest = ({
// videojs.log.debug('Session expired, closing the session.');
keySession.close().then(() => {
removeSession(initData);
makeNewRequest(requestOptions);
});
}
}, false);
Expand Down
12 changes: 10 additions & 2 deletions test/eme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ QUnit.test('keystatuseschange triggers keystatuschange on eventBus for each key'

});

QUnit.test('keystatuseschange with expired key closes session', function(assert) {
QUnit.test('keystatuseschange with expired key closes and recreates session', function(assert) {
const removeSessionCalls = [];
// once the eme module gets the removeSession function, the session argument is already
// bound to the function (note that it's a custom session maintained by the plugin, not
Expand All @@ -150,10 +150,15 @@ QUnit.test('keystatuseschange with expired key closes session', function(assert)
const eventBus = {
trigger: (name) => {}
};
let creates = 0;

makeNewRequest({
mediaKeys: {
createSession: () => mockSession
createSession: () => {
creates++;

return mockSession;
}
},
initDataType: '',
initData,
Expand All @@ -163,6 +168,7 @@ QUnit.test('keystatuseschange with expired key closes session', function(assert)
eventBus
});

assert.equal(creates, 1, 'created session');
assert.equal(mockSession.listeners.length, 2, 'added listeners');
assert.equal(mockSession.listeners[1].type,
'keystatuseschange',
Expand Down Expand Up @@ -190,6 +196,8 @@ QUnit.test('keystatuseschange with expired key closes session', function(assert)
// synchronously
assert.equal(removeSessionCalls.length, 1, 'called remove session');
assert.equal(removeSessionCalls[0], initData, 'called to remove session with initData');

assert.equal(creates, 2, 'created another session');
});

QUnit.test('keystatuseschange with internal-error logs a warning', function(assert) {
Expand Down