Skip to content

Commit

Permalink
feat: add legacy fairplay flow cleanup (#219)
Browse files Browse the repository at this point in the history
Co-authored-by: Dzianis Dashkevich <ddashkevich@brightcove.com>
  • Loading branch information
dzianis-dashkevich and Dzianis Dashkevich committed May 9, 2024
1 parent 7ce2aa9 commit b7ce1e1
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ const eme = function(options = {}) {
});
};

// Support Safari EME with FairPlay
// (also used in early Chrome or Chrome with EME disabled flag)
player.tech_.el_.addEventListener('webkitneedkey', (event) => {
const webkitNeedKeyEventHandler = (event) => {
const firstWebkitneedkeyTimeout = getOptions(player).firstWebkitneedkeyTimeout || 1000;
const src = player.src();
// on source change or first startup reset webkitneedkey options.
Expand Down Expand Up @@ -422,12 +420,31 @@ const eme = function(options = {}) {
player.eme.webkitneedkey_.timeout = null;
handleFn(event);
}, firstWebkitneedkeyTimeout);
// after we have a verified first request, we will request on
// every other event like normal.
// after we have a verified first request, we will request on
// every other event like normal.
} else {
handleFn(event);
}
};

let videoElement = player.tech_.el_;

// Support Safari EME with FairPlay
// (also used in early Chrome or Chrome with EME disabled flag)
videoElement.addEventListener('webkitneedkey', webkitNeedKeyEventHandler);

const cleanup = () => {
videoElement.removeEventListener('webkitneedkey', webkitNeedKeyEventHandler);
videoElement = null;
};

// auto-cleanup:
player.on('dispose', () => {
cleanup();
});

// returning for manual cleanup
return cleanup;
},
detectSupportedCDMs,
options
Expand Down

0 comments on commit b7ce1e1

Please sign in to comment.