Skip to content

Commit

Permalink
Work around lack of Tizen key statuses in tests
Browse files Browse the repository at this point in the history
If we haven't gotten a key status within 5 seconds of updating a
session, consider the session "loaded".  This fixes a hung Promise
in DrmEngine for offline use-cases.

Issue #891
Issue #894

Change-Id: Ic4c7478198a0db4b3a3df8842d5f8cd1f6f3e8bd
  • Loading branch information
joeyparrish committed Jun 22, 2017
1 parent 1eb5a41 commit 07d067b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,10 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
/** @type {!MediaKeySession} */
var session = event.target;

var updatePromise;
var activeSession;
for (var i = 0; i < this.activeSessions_.length; i++) {
if (this.activeSessions_[i].session == session) {
updatePromise = this.activeSessions_[i].updatePromise;
activeSession = this.activeSessions_[i];
break;
}
}
Expand All @@ -1080,9 +1080,19 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {

// Request succeeded, now pass the response to the CDM.
return session.update(response.data).then(function() {
if (updatePromise)
updatePromise.resolve();
});
if (activeSession) {
if (activeSession.updatePromise)
activeSession.updatePromise.resolve();
// In case there are no key statuses, consider this session loaded
// after a reasonable timeout. It should definitely not take 5
// seconds to process a license.
setTimeout(function() {
activeSession.loaded = true;
if (this.activeSessions_.every(function(s) { return s.loaded; }))
this.allSessionsLoaded_.resolve();
}.bind(this), 5000);
}
}.bind(this));
}.bind(this), function(error) {
// Ignore destruction errors
if (this.destroyed_) return Promise.resolve();
Expand All @@ -1096,8 +1106,8 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
shaka.util.Error.Code.LICENSE_REQUEST_FAILED,
error);
this.onError_(shakaErr);
if (updatePromise)
updatePromise.reject(shakaErr);
if (activeSession && activeSession.updatePromise)
activeSession.updatePromise.reject(shakaErr);
}.bind(this)).catch(function(error) {
// Ignore destruction errors
if (this.destroyed_) return Promise.resolve();
Expand All @@ -1109,8 +1119,8 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
shaka.util.Error.Code.LICENSE_RESPONSE_REJECTED,
error.message);
this.onError_(shakaErr);
if (updatePromise)
updatePromise.reject(shakaErr);
if (activeSession && activeSession.updatePromise)
activeSession.updatePromise.reject(shakaErr);
}.bind(this));
};

Expand Down

0 comments on commit 07d067b

Please sign in to comment.