Skip to content

Commit

Permalink
fixup drm engine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valotvince committed Dec 21, 2021
1 parent 6b720d4 commit 8f7f2e6
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 129 deletions.
26 changes: 16 additions & 10 deletions lib/media/drm_engine.js
Expand Up @@ -389,8 +389,9 @@ shaka.media.DrmEngine = class {
/**
* Attach MediaKeys to the video element
* @return {!Promise}
* @private
*/
async attachMediaKeys() {
async attachMediaKeys_() {
if (this.video_.mediaKeys) {
return;
}
Expand All @@ -406,21 +407,22 @@ shaka.media.DrmEngine = class {
shaka.util.Error.Code.FAILED_TO_ATTACH_TO_VIDEO,
exception.message));
}

this.destroyer_.ensureNotDestroyed();
}

/**
* Processes encrypted event and start licence challenging
* @return {!Promise}
* @private
*/
async onEncryptedEvent(event) {
async onEncryptedEvent_(event) {
/**
* MediaKeys should be added when receiving an encrypted event. Setting
* mediaKeys before could result into encrypted event not being fired on
* some browsers
*/
await this.attachMediaKeys();

this.destroyer_.ensureNotDestroyed();
await this.attachMediaKeys_();

this.newInitData(
event.initDataType,
Expand Down Expand Up @@ -461,25 +463,29 @@ shaka.media.DrmEngine = class {
() => this.closeOpenSessions_());
}

const nonEmptyInitData = this.currentDrmInfo_.initData.find(
(initDataOverride) => initDataOverride.initData.length > 0);

/**
* Legacy implementations requires MediaKeys to be set before having
* webkitneedkey / msneedkey event, which will be translated as an
* encrypted event by the polyfills
*
* If some initData already has been generated, we need to attach media
* keys so we can start session before playback actually begins
*/
if (shaka.util.Platform.isMediaKeysPolyfilled()) {
await this.attachMediaKeys();
if (nonEmptyInitData || shaka.util.Platform.isMediaKeysPolyfilled()) {
await this.attachMediaKeys_();
}

this.destroyer_.ensureNotDestroyed();

this.createOrLoad();

// Explicit init data an offline session is
// sufficient to suppress 'encrypted' events for all streams.
if (!this.offlineSessionIds_.length) {
this.eventManager_.listen(
// eslint-disable-next-line no-restricted-syntax
this.video_, 'encrypted', this.onEncryptedEvent.bind(this));
this.video_, 'encrypted', this.onEncryptedEvent_.bind(this));
}
}

Expand Down

0 comments on commit 8f7f2e6

Please sign in to comment.