@@ -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 ) => {
0 commit comments