@@ -9,6 +9,7 @@ goog.provide('shaka.media.DrmEngine');
9
9
goog . require ( 'goog.asserts' ) ;
10
10
goog . require ( 'shaka.log' ) ;
11
11
goog . require ( 'shaka.net.NetworkingEngine' ) ;
12
+ goog . require ( 'shaka.util.ArrayUtils' ) ;
12
13
goog . require ( 'shaka.util.BufferUtils' ) ;
13
14
goog . require ( 'shaka.util.Destroyer' ) ;
14
15
goog . require ( 'shaka.util.DrmUtils' ) ;
@@ -67,12 +68,18 @@ shaka.media.DrmEngine = class {
67
68
*/
68
69
this . activeSessions_ = new Map ( ) ;
69
70
71
+ /** @private {!Array.<!shaka.net.NetworkingEngine.PendingRequest>} */
72
+ this . activeRequests_ = [ ] ;
73
+
70
74
/**
71
75
* @private {!Map<string,
72
76
* {initData: ?Uint8Array, initDataType: ?string}> }
73
77
*/
74
78
this . storedPersistentSessions_ = new Map ( ) ;
75
79
80
+ /** @private {boolean} */
81
+ this . hasInitData_ = false ;
82
+
76
83
/** @private {!shaka.util.PublicPromise} */
77
84
this . allSessionsLoaded_ = new shaka . util . PublicPromise ( ) ;
78
85
@@ -706,6 +713,7 @@ shaka.media.DrmEngine = class {
706
713
707
714
// Reset the promise for the next sessions to come if key needs aren't
708
715
// satisfied with persistent sessions
716
+ this . hasInitData_ = false ;
709
717
this . allSessionsLoaded_ = new shaka . util . PublicPromise ( ) ;
710
718
this . allSessionsLoaded_ . catch ( ( ) => { } ) ;
711
719
}
@@ -767,11 +775,16 @@ shaka.media.DrmEngine = class {
767
775
}
768
776
}
769
777
778
+ // Mark that there is init data, so that the preloader will know to wait
779
+ // for sessions to be loaded.
780
+ this . hasInitData_ = true ;
781
+
770
782
// If there are pre-existing sessions that have all been loaded
771
783
// then reset the allSessionsLoaded_ promise, which can now be
772
784
// used to wait for new sesssions to be loaded
773
785
if ( this . activeSessions_ . size > 0 && this . areAllSessionsLoaded_ ( ) ) {
774
786
this . allSessionsLoaded_ . resolve ( ) ;
787
+ this . hasInitData_ = false ;
775
788
this . allSessionsLoaded_ = new shaka . util . PublicPromise ( ) ;
776
789
this . allSessionsLoaded_ . catch ( ( ) => { } ) ;
777
790
}
@@ -1387,6 +1400,14 @@ shaka.media.DrmEngine = class {
1387
1400
this . video_ . paused && ! this . initialRequestsSent_ ) ;
1388
1401
}
1389
1402
1403
+ /** @return {!Promise } */
1404
+ async waitForActiveRequests ( ) {
1405
+ if ( this . hasInitData_ ) {
1406
+ await this . allSessionsLoaded_ ;
1407
+ await Promise . all ( this . activeRequests_ . map ( ( req ) => req . promise ) ) ;
1408
+ }
1409
+ }
1410
+
1390
1411
/**
1391
1412
* Sends a license request.
1392
1413
* @param {!MediaKeyMessageEvent } event
@@ -1446,7 +1467,9 @@ shaka.media.DrmEngine = class {
1446
1467
try {
1447
1468
const req = this . playerInterface_ . netEngine . request (
1448
1469
requestType , request , { isPreload : this . isPreload_ ( ) } ) ;
1470
+ this . activeRequests_ . push ( req ) ;
1449
1471
response = await req . promise ;
1472
+ shaka . util . ArrayUtils . remove ( this . activeRequests_ , req ) ;
1450
1473
} catch ( error ) {
1451
1474
if ( this . destroyer_ . destroyed ( ) ) {
1452
1475
return ;
0 commit comments