From 3ba8ce309e726e0747e7f5abca6dcf321c89bfbc Mon Sep 17 00:00:00 2001 From: hswaminathan Date: Mon, 26 Aug 2024 13:49:12 -0400 Subject: [PATCH] review changes --- README.md | 13 ++++++++++++- src/eme.js | 16 +++++++++------- src/plugin.js | 9 ++++++++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1cd6979..6006625 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Maintenance Status: Stable - [`keySystems`](#keysystems) - [`emeHeaders`](#emeheaders) - [`firstWebkitneedkeyTimeout`](#firstwebkitneedkeytimeout) + - [`limitRenewalsMaxPauseDuration`](#limitrenewalsmaxpauseduration) + - [`limitRenewalsBeforePlay`](#limitrenewalsbeforeplay) - [Setting Options per Source](#setting-options-per-source) - [Setting Options for All Sources](#setting-options-for-all-sources) - [Header Hierarchy and Removal](#header-hierarchy-and-removal) @@ -368,6 +370,15 @@ emeHeaders: { The amount of time in milliseconds to wait on the first `webkitneedkey` event before making the key request. This was implemented due to a bug in Safari where rendition switches at the start of playback can cause `webkitneedkey` to fire multiple times, with only the last one being valid. +#### `limitRenewalsMaxPauseDuration` + +The duration, in seconds, to wait in paused state before license-renewals are rejected and session is closed. This option limits excess license requests when using limited-duration licenses. + +#### `limitRenewalsBeforePlay` +> Boolean + +If set to true, license renewal is rejected if license expires before play when player is idle. This option limits excess license requests when using limited-duration licenses. + ### Setting Options per Source This is the recommended way of setting most options. Each source may have a different set of requirements; so, it is best to define options on a per source basis. @@ -619,7 +630,7 @@ When the key session is created, an event of type `keysessioncreated` will be tr ``` player.tech().on('keysessioncreated', function(keySession) { // Event data: - // keySession: the mediaKeySession object + // keySession: the mediaKeySession object // https://www.w3.org/TR/encrypted-media/#mediakeysession-interface }); ``` diff --git a/src/eme.js b/src/eme.js index 7b466bf..f1de599 100644 --- a/src/eme.js +++ b/src/eme.js @@ -129,11 +129,11 @@ export const makeNewRequest = (player, requestOptions) => { let pauseTimer; player.on('pause', () => { - if (options.limitRenewalsOnPauseTime && typeof options.limitRenewalsOnPauseTime === 'number') { + if (options.limitRenewalsMaxPauseDuration && typeof options.limitRenewalsMaxPauseDuration === 'number') { pauseTimer = setInterval(() => { timeElapsed++; - if (timeElapsed >= options.limitRenewalsOnPauseTime) { + if (timeElapsed >= options.limitRenewalsMaxPauseDuration) { clearInterval(pauseTimer); } }, 1000); @@ -149,6 +149,7 @@ export const makeNewRequest = (player, requestOptions) => { const keySession = mediaKeys.createSession(); const closeAndRemoveSession = () => { + videojs.log.debug('Session expired, closing the session.'); keySession.close().then(() => { // Because close() is async, this promise could resolve after the @@ -194,12 +195,13 @@ export const makeNewRequest = (player, requestOptions) => { if (event.messageType === 'license-renewal') { const limitRenewalsBeforePlay = options.limitRenewalsBeforePlay; - const limitRenewalsOnPauseTime = options.limitRenewalsOnPauseTime; - - if (!player.hasStarted() && limitRenewalsBeforePlay || - (player.paused() && typeof limitRenewalsOnPauseTime === 'number' && timeElapsed >= limitRenewalsOnPauseTime) || - player.ended()) { + const limitRenewalsMaxPauseDuration = options.limitRenewalsMaxPauseDuration; + const validLimitRenewalsMaxPauseDuration = typeof limitRenewalsMaxPauseDuration === 'number'; + const renewingBeforePlayback = !player.hasStarted() && limitRenewalsBeforePlay; + const maxPauseDurationReached = player.paused() && validLimitRenewalsMaxPauseDuration && timeElapsed >= limitRenewalsMaxPauseDuration; + const ended = player.ended(); + if (renewingBeforePlayback || maxPauseDurationReached || ended) { closeAndRemoveSession(); return; } diff --git a/src/plugin.js b/src/plugin.js index 9b591ba..2b1a329 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -267,6 +267,10 @@ const onPlayerReady = (player, emeError) => { }; if (videojs.browser.IS_FIREFOX) { + // Unlike Chrome, Firefox doesn't receive an `encrypted` event on + // replay and seek-back after content ends and `handleEncryptedEvent` is never called. + // So a fake encrypted event is necessary here. + let handled; player.on('ended', () =>{ @@ -279,7 +283,10 @@ const onPlayerReady = (player, emeError) => { }); }); player.on('play', () => { - if (player.eme.sessions.length === 0) { + const options = player.eme.options; + const limitRenewalsMaxPauseDuration = options.limitRenewalsMaxPauseDuration; + + if (player.eme.sessions.length === 0 && typeof limitRenewalsMaxPauseDuration === 'number') { handled = true; sendMockEncryptedEvent(); }