Skip to content

Commit

Permalink
Add option to customize the polling of expiration time (#2579)
Browse files Browse the repository at this point in the history
A large value effectively disables use of the expiration time

Closes #2252
  • Loading branch information
Álvaro Velad Galván committed May 20, 2020
1 parent ed0d718 commit 8648a3e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Expand Up @@ -198,6 +198,7 @@ shakaDemo.MessageIds = {
TRICK_PLAY_CONTROLS: 'DEMO_TRICK_PLAY_CONTROLS',
TRICK_PLAY_CONTROLS_WARNING: 'DEMO_TRICK_PLAY_CONTROLS_WARNING',
UI_LOCALE: 'DEMO_UI_LOCALE',
UPDATE_EXPIRATION_TIME: 'DEMO_UPDATE_EXPIRATION_TIME',
USE_NATIVE_HLS_SAFARI: 'DEMO_USE_NATIVE_HLS_SAFARI',
USE_PERSISTENT_LICENSES: 'DEMO_USE_PERSISTENT_LICENSES',
VIDEO_ROBUSTNESS: 'DEMO_VIDEO_ROBUSTNESS',
Expand Down
7 changes: 6 additions & 1 deletion demo/config.js
Expand Up @@ -127,7 +127,12 @@ shakaDemo.Config = class {
.addBoolInput_(MessageIds.DELAY_LICENSE,
'drm.delayLicenseRequestUntilPlayed')
.addBoolInput_(MessageIds.LOG_LICENSE_EXCHANGE,
'drm.logLicenseExchange');
'drm.logLicenseExchange')
.addNumberInput_(MessageIds.UPDATE_EXPIRATION_TIME,
'drm.updateExpirationTime',
/* canBeDecimal= */ true,
/* canBeZero= */ false,
/* canBeUnset= */ true);
const advanced = shakaDemoMain.getConfiguration().drm.advanced || {};
const robustnessSuggestions = [
'SW_SECURE_CRYPTO',
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Expand Up @@ -173,6 +173,7 @@
"DEMO_UNSUPPORTED_NO_KEY_SUPPORT": "Your browser does not support the required key systems.",
"DEMO_UNSUPPORTED_NO_LICENSE_SUPPORT": "Your browser does not support offline licenses for the required key systems.",
"DEMO_UNSUPPORTED_NO_OFFLINE": "Your browser does not support offline storage.",
"DEMO_UPDATE_EXPIRATION_TIME": "Update expiration time",
"DEMO_UPLYNK": "Verizon Digital Media Services",
"DEMO_USE_NATIVE_HLS_SAFARI": "Use native HLS on Safari",
"DEMO_USE_PERSISTENT_LICENSES": "Use Persistent Licenses",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Expand Up @@ -695,6 +695,10 @@
"description": "An error message that shows why an asset cannot be stored offline: the browser does not support storing things offline, in general.",
"message": "Your browser does not support offline storage."
},
"DEMO_UPDATE_EXPIRATION_TIME": {
"description": "The name of a configuration value.",
"message": "Update expiration time"
},
"DEMO_UPLYNK": {
"description": "Text that describes an asset that comes from the Verizon Digital Media Services asset library.",
"message": "[PROPER_NAME:Verizon Digital Media Services]"
Expand Down
6 changes: 5 additions & 1 deletion externs/shaka/player.js
Expand Up @@ -518,7 +518,8 @@ shaka.extern.AdvancedDrmConfiguration;
* initDataTransform:
* ((function(!Uint8Array, string, ?shaka.extern.DrmInfo):!Uint8Array)|
* undefined),
* logLicenseExchange: boolean
* logLicenseExchange: boolean,
* updateExpirationTime: number
* }}
*
* @property {shaka.extern.RetryParameters} retryParameters
Expand Down Expand Up @@ -553,6 +554,9 @@ shaka.extern.AdvancedDrmConfiguration;
* This includes the init data, request, and response data, printed as base64
* strings. Don't use in production, for debugging only; has no affect in
* release builds as logging is removed.
* @property {number} updateExpirationTime
* <i>Defaults to 1.</i> <br>
* The frequency in seconds with which to check the expiration of a session.
*
* @exportDoc
*/
Expand Down
9 changes: 6 additions & 3 deletions lib/media/drm_engine.js
Expand Up @@ -29,8 +29,11 @@ goog.require('shaka.util.Uint8ArrayUtils');

/** @implements {shaka.util.IDestroyable} */
shaka.media.DrmEngine = class {
/** @param {shaka.media.DrmEngine.PlayerInterface} playerInterface */
constructor(playerInterface) {
/**
* @param {shaka.media.DrmEngine.PlayerInterface} playerInterface
* @param {number=} updateExpirationTime
*/
constructor(playerInterface, updateExpirationTime = 1) {
/** @private {?shaka.media.DrmEngine.PlayerInterface} */
this.playerInterface_ = playerInterface;

Expand Down Expand Up @@ -109,7 +112,7 @@ shaka.media.DrmEngine = class {
/** @private {?shaka.util.Timer} */
this.expirationTimer_ = new shaka.util.Timer(() => {
this.pollExpiration_();
}).tickEvery(/* seconds= */ 1);
}).tickEvery(/* seconds= */ updateExpirationTime);

// Add a catch to the Promise to avoid console logs about uncaught errors.
const noop = () => {};
Expand Down
3 changes: 2 additions & 1 deletion lib/player.js
Expand Up @@ -2221,7 +2221,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* @return {!shaka.media.DrmEngine}
*/
createDrmEngine(playerInterface) {
return new shaka.media.DrmEngine(playerInterface);
const updateExpirationTime = this.config_.drm.updateExpirationTime;
return new shaka.media.DrmEngine(playerInterface, updateExpirationTime);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Expand Up @@ -73,6 +73,7 @@ shaka.util.PlayerConfiguration = class {
delayLicenseRequestUntilPlayed: false,
initDataTransform: shaka.media.DrmEngine.defaultInitDataTransform,
logLicenseExchange: false,
updateExpirationTime: 1,
};

const manifest = {
Expand Down

0 comments on commit 8648a3e

Please sign in to comment.