Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
harisha-swaminathan committed Aug 26, 2024
1 parent 65453bd commit 3ba8ce3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
});
```
Expand Down
16 changes: 9 additions & 7 deletions src/eme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () =>{
Expand All @@ -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();
}
Expand Down

0 comments on commit 3ba8ce3

Please sign in to comment.