Skip to content

Commit

Permalink
silence createOrLoad unhandled rejections in attach
Browse files Browse the repository at this point in the history
  • Loading branch information
valotvince committed Oct 11, 2022
1 parent 92c75b9 commit e00ec59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
5 changes: 4 additions & 1 deletion lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ shaka.media.DrmEngine = class {
await this.attachMediaKeys_();
}

this.createOrLoad();
this.createOrLoad().catch(() => {
// Silence errors
// createOrLoad will run async, errors are triggered through onError_
});

// Explicit init data for any one stream or an offline session is
// sufficient to suppress 'encrypted' events for all streams.
Expand Down
40 changes: 20 additions & 20 deletions test/media/drm_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,32 +1088,32 @@ describe('DrmEngine', () => {
message, nativeError, undefined));
});

// it('should throw a OFFLINE_SESSION_REMOVED error', async () => {
// // Given persistent session is not available
// session1.load.and.returnValue(false);
it('should throw a OFFLINE_SESSION_REMOVED error', async () => {
// Given persistent session is not available
session1.load.and.returnValue(false);

// onErrorSpy.and.stub();
onErrorSpy.and.stub();

// await drmEngine.initForPlayback(
// manifest.variants, ['persistent-session-id']);
// await drmEngine.attach(mockVideo);
await drmEngine.initForPlayback(
manifest.variants, ['persistent-session-id']);
await drmEngine.attach(mockVideo);

// expect(drmEngine.initialized()).toBe(true);
expect(drmEngine.initialized()).toBe(true);

// await Util.shortDelay();
await Util.shortDelay();

// expect(mockMediaKeys.createSession).toHaveBeenCalledTimes(1);
// expect(mockMediaKeys.createSession)
// .toHaveBeenCalledWith('persistent-license');
// expect(session1.load).toHaveBeenCalledWith('persistent-session-id');
expect(mockMediaKeys.createSession).toHaveBeenCalledTimes(1);
expect(mockMediaKeys.createSession)
.toHaveBeenCalledWith('persistent-license');
expect(session1.load).toHaveBeenCalledWith('persistent-session-id');

// expect(onErrorSpy).toHaveBeenCalled();
// const error = onErrorSpy.calls.argsFor(0)[0];
// shaka.test.Util.expectToEqualError(error, new shaka.util.Error(
// shaka.util.Error.Severity.CRITICAL,
// shaka.util.Error.Category.DRM,
// shaka.util.Error.Code.OFFLINE_SESSION_REMOVED));
// });
expect(onErrorSpy).toHaveBeenCalled();
const error = onErrorSpy.calls.argsFor(0)[0];
shaka.test.Util.expectToEqualError(error, new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.OFFLINE_SESSION_REMOVED));
});

it('uses persistent session ids when available', async () => {
const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
Expand Down

0 comments on commit e00ec59

Please sign in to comment.