Skip to content

Commit

Permalink
fix: fix cleanup issues (#220)
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 17, 2024
1 parent 998580e commit 6b82ffa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,22 @@ const eme = function(options = {}) {
// (also used in early Chrome or Chrome with EME disabled flag)
videoElement.addEventListener('webkitneedkey', webkitNeedKeyEventHandler);

const cleanup = () => {
videoElement.removeEventListener('webkitneedkey', webkitNeedKeyEventHandler);
const cleanupWebkitNeedKeyHandler = () => {
// no need in auto-cleanup if manual clean is called
player.off('dispose', cleanupWebkitNeedKeyHandler);
// check for null, if manual cleanup is called multiple times for any reason
if (videoElement !== null) {
videoElement.removeEventListener('webkitneedkey', webkitNeedKeyEventHandler);
}

videoElement = null;
};

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

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

0 comments on commit 6b82ffa

Please sign in to comment.