Skip to content

Commit bae6f65

Browse files
committed
Handle expired key status correctly
1 parent 7c1346c commit bae6f65

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/controller/eme-controller.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,16 @@ class EMEController implements ComponentAPI {
318318

319319
private renewKeySession(mediaKeySessionContext: MediaKeySessionContext) {
320320
const decryptdata = mediaKeySessionContext.decryptdata;
321+
const keySessionContext = this.createMediaKeySessionContext(
322+
mediaKeySessionContext
323+
);
321324
this.keyUriToKeySessionPromise[decryptdata.uri] =
322325
this.generateRequestWithPreferredKeySession(
323-
mediaKeySessionContext,
326+
keySessionContext,
324327
'cenc',
325328
decryptdata.pssh
326329
);
330+
this.removeSession(mediaKeySessionContext);
327331
}
328332

329333
private handleParsedKeyResponse(
@@ -1043,6 +1047,7 @@ class EMEController implements ComponentAPI {
10431047
LevelKey.clearKeyUriToKeyIdMap();
10441048

10451049
// Close all sessions and remove media keys from the video element.
1050+
const keySessionCount = mediaKeysList.length;
10461051
EMEController.CDMCleanupPromise = Promise.all(
10471052
mediaKeysList
10481053
.map((mediaKeySessionContext) =>
@@ -1057,7 +1062,7 @@ class EMEController implements ComponentAPI {
10571062
)
10581063
)
10591064
.then(() => {
1060-
if (mediaKeysList.length) {
1065+
if (keySessionCount) {
10611066
this.log('finished closing key sessions and clearing media keys');
10621067
mediaKeysList.length = 0;
10631068
}
@@ -1086,6 +1091,10 @@ class EMEController implements ComponentAPI {
10861091
mediaKeySessionContext.decryptdata =
10871092
mediaKeySessionContext.licenseXhr =
10881093
undefined!;
1094+
const index = this.mediaKeySessions.indexOf(mediaKeySessionContext);
1095+
if (index > -1) {
1096+
this.mediaKeySessions.splice(index, 1);
1097+
}
10891098
return mediaKeysSession
10901099
.remove()
10911100
.catch((error) => {

src/loader/key-loader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ export default class KeyLoader implements ComponentAPI {
8080
});
8181
}
8282

83-
loadClear(loadingFrag: Fragment, encryptedFragments: Fragment[]): void | Promise<void> {
84-
if (this.emeController && this.config.emeEnabled) {
83+
loadClear(
84+
loadingFrag: Fragment,
85+
encryptedFragments: Fragment[]
86+
): void | Promise<void> {
87+
if (this.emeController && this.config.emeEnabled) {
8588
// access key-system with nearest key on start (loaidng frag is unencrypted)
8689
const { sn, cc } = loadingFrag;
8790
for (let i = 0; i < encryptedFragments.length; i++) {

0 commit comments

Comments
 (0)