Skip to content

Commit

Permalink
add initLegacyFairplay to eme API
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Feb 15, 2024
1 parent 0740ed1 commit b5dbacb
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,57 +243,7 @@ const onPlayerReady = (player, emeError) => {
.catch(emeError);
});
} else if (window.WebKitMediaKeys) {
const handleFn = (event) => {
// TODO convert to videojs.log.debug and add back in
// https://github.com/videojs/video.js/pull/4780
// videojs.log('eme', 'Received a \'webkitneedkey\' event');

// TODO it's possible that the video state must be cleared if reusing the same video
// element between sources
setupSessions(player);
handleWebKitNeedKeyEvent(event, playerOptions, player.tech_)
.catch(emeError);
};

// Support Safari EME with FairPlay
// (also used in early Chrome or Chrome with EME disabled flag)
player.tech_.el_.addEventListener('webkitneedkey', (event) => {
const firstWebkitneedkeyTimeout = playerOptions.firstWebkitneedkeyTimeout || 1000;
const src = player.src();
// on source change or first startup reset webkitneedkey options.

player.eme.webkitneedkey_ = player.eme.webkitneedkey_ || {};

// if the source changed we need to handle the first event again.
// track source changes internally.
if (player.eme.webkitneedkey_.src !== src) {
player.eme.webkitneedkey_ = {
handledFirstEvent: false,
src
};
}
// It's possible that at the start of playback a rendition switch
// on a small player in safari's HLS implementation will cause
// two webkitneedkey events to occur. We want to make sure to cancel
// our first existing request if we get another within 1 second. This
// prevents a non-fatal player error from showing up due to a
// request failure.
if (!player.eme.webkitneedkey_.handledFirstEvent) {
// clear the old timeout so that a new one can be created
// with the new rendition's event data
player.clearTimeout(player.eme.webkitneedkey_.timeout);
player.eme.webkitneedkey_.timeout = player.setTimeout(() => {
player.eme.webkitneedkey_.handledFirstEvent = true;
player.eme.webkitneedkey_.timeout = null;
handleFn(event);
}, firstWebkitneedkeyTimeout);
// after we have a verified first request, we will request on
// every other event like normal.
} else {
handleFn(event);
}
});

player.eme.initLegacyFairplay();
} else if (window.MSMediaKeys) {
// IE11 Windows 8.1+
// Since IE11 doesn't support promises, we have to use a combination of
Expand Down Expand Up @@ -405,6 +355,59 @@ const eme = function(options = {}) {
}
}
},
initLegacyFairplay() {
const playerOptions = getOptions(player);
const handleFn = (event) => {
// TODO convert to videojs.log.debug and add back in
// https://github.com/videojs/video.js/pull/4780
// videojs.log('eme', 'Received a \'webkitneedkey\' event');

// TODO it's possible that the video state must be cleared if reusing the same video
// element between sources
setupSessions(player);
handleWebKitNeedKeyEvent(event, playerOptions, player.tech_)
.catch(emeError);
};

// Support Safari EME with FairPlay
// (also used in early Chrome or Chrome with EME disabled flag)
player.tech_.el_.addEventListener('webkitneedkey', (event) => {
const firstWebkitneedkeyTimeout = playerOptions.firstWebkitneedkeyTimeout || 1000;
const src = player.src();
// on source change or first startup reset webkitneedkey options.

player.eme.webkitneedkey_ = player.eme.webkitneedkey_ || {};

// if the source changed we need to handle the first event again.
// track source changes internally.
if (player.eme.webkitneedkey_.src !== src) {
player.eme.webkitneedkey_ = {
handledFirstEvent: false,
src
};
}
// It's possible that at the start of playback a rendition switch
// on a small player in safari's HLS implementation will cause
// two webkitneedkey events to occur. We want to make sure to cancel
// our first existing request if we get another within 1 second. This
// prevents a non-fatal player error from showing up due to a
// request failure.
if (!player.eme.webkitneedkey_.handledFirstEvent) {
// clear the old timeout so that a new one can be created
// with the new rendition's event data
player.clearTimeout(player.eme.webkitneedkey_.timeout);
player.eme.webkitneedkey_.timeout = player.setTimeout(() => {
player.eme.webkitneedkey_.handledFirstEvent = true;
player.eme.webkitneedkey_.timeout = null;
handleFn(event);
}, firstWebkitneedkeyTimeout);
// after we have a verified first request, we will request on
// every other event like normal.
} else {
handleFn(event);
}
});
},
detectSupportedCDMs,
options
};
Expand Down

0 comments on commit b5dbacb

Please sign in to comment.