Skip to content

Commit

Permalink
improved fix for errors thrown on player dispose with an open key ses…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
misteroneill committed May 3, 2024
1 parent fe72738 commit b09fb3a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/eme.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ export const makeNewRequest = (player, requestOptions) => {
});

player.on('dispose', () => {
keySession.close().then(() => {
eventBus.trigger({
type: 'keysessionclosed',
keySession
});
}).catch((error) => {
keySession.close().catch((error) => {
const metadata = {
errorType: EmeError.EMEFailedToCloseSession,
keySystem
Expand Down Expand Up @@ -168,9 +163,11 @@ export const makeNewRequest = (player, requestOptions) => {
keySession.addEventListener(KEY_STATUSES_CHANGE, (event) => {
let expired = false;

if (!eventBus) {
// Protect from race conditions causing the player to be disposed.
if (player.isDisposed()) {
return;
}

// Re-emit the keystatuseschange event with the entire keyStatusesMap
eventBus.trigger({
type: KEY_STATUSES_CHANGE,
Expand Down Expand Up @@ -213,6 +210,13 @@ export const makeNewRequest = (player, requestOptions) => {
// session can be created.
videojs.log.debug('Session expired, closing the session.');
keySession.close().then(() => {

// Because close() is async, this promise could resolve after the
// player has been disposed.
if (player.isDisposed()) {
return;
}

eventBus.trigger({
type: 'keysessionclosed',
keySession
Expand Down

0 comments on commit b09fb3a

Please sign in to comment.