From eebf18cabdcee3c62daee9bed9ceb2958f30f9f5 Mon Sep 17 00:00:00 2001 From: Martin Stark <901824+martinstark@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:19:27 +0100 Subject: [PATCH] fix: DrmEngine exception thrown when using FairPlay (#4971) Closes #4902 This is not intended to be a complete fix for the issue, I do not understand the effect this new ternary on the shaka player as a whole. I have not found the root cause for `this.currentDrmInfo_` being `undefined` when accessed. It does, however, look like it has previously been acceptable for this property to be `undefined`. During the work to add Fairplay support in 2022, accessing `this.currentDrmInfo_` was added on line 483. This line **does not** accept that `this.currentDrmInfo_` can be undefined. A few lines below this, `this.createOrLoad()` is called, which **does** accept that `this.currentDrmInfo_` can be `undefined`. The latter piece of code was last modified in 2019. https://github.com/shaka-project/shaka-player/blob/c471d23bc25db11dda85a18870ebd3fe37971848/lib/media/drm_engine.js#L483-L498 https://github.com/shaka-project/shaka-player/blob/c471d23bc25db11dda85a18870ebd3fe37971848/lib/media/drm_engine.js#L626-L629 --- lib/media/drm_engine.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 05971e08ac..c7549b186b 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -480,8 +480,10 @@ shaka.media.DrmEngine = class { () => this.closeOpenSessions_()); } - const manifestInitData = this.currentDrmInfo_.initData.find( - (initDataOverride) => initDataOverride.initData.length > 0); + const manifestInitData = this.currentDrmInfo_ ? + this.currentDrmInfo_.initData.find( + (initDataOverride) => initDataOverride.initData.length > 0, + ) : null; /** * We can attach media keys before the playback actually begins when: