@@ -61,11 +61,11 @@ shaka.ads.InterstitialAdManager = class {
61
61
/** @private {!Set.<string>} */
62
62
this . interstitialIds_ = new Set ( ) ;
63
63
64
- /** @private {!Set.<shaka.ads.InterstitialAdManager.Interstitial >} */
64
+ /** @private {!Set.<shaka.extern.AdInterstitial >} */
65
65
this . interstitials_ = new Set ( ) ;
66
66
67
67
/**
68
- * @private {!Map.<shaka.ads.InterstitialAdManager.Interstitial ,
68
+ * @private {!Map.<shaka.extern.AdInterstitial ,
69
69
* Promise<?shaka.media.PreloadManager>>}
70
70
*/
71
71
this . preloadManagerInterstitials_ = new Map ( ) ;
@@ -204,48 +204,63 @@ shaka.ads.InterstitialAdManager = class {
204
204
205
205
206
206
/**
207
- * @param {shaka.extern.Interstitial } interstitial
207
+ * @param {shaka.extern.HLSInterstitial } hlsInterstitial
208
208
*/
209
- async addMetadata ( interstitial ) {
209
+ async addMetadata ( hlsInterstitial ) {
210
210
if ( this . basePlayer_ . getLoadMode ( ) == shaka . Player . LoadMode . SRC_EQUALS &&
211
211
this . usingBaseVideo_ ) {
212
212
shaka . log . alwaysWarn (
213
- 'Unsupported interstitial when using single media element' ,
214
- interstitial ) ;
213
+ 'Unsupported HLS interstitial when using single media element' ,
214
+ hlsInterstitial ) ;
215
215
return ;
216
216
}
217
217
this . updatePlayerConfig_ ( ) ;
218
+ const adInterstitials = await this . getInterstitialsInfo_ ( hlsInterstitial ) ;
219
+ if ( adInterstitials . length ) {
220
+ this . addInterstitials ( adInterstitials ) ;
221
+ } else {
222
+ shaka . log . alwaysWarn ( 'Unsupported HLS interstitial' , hlsInterstitial ) ;
223
+ }
224
+ }
225
+
226
+
227
+ /**
228
+ * @param {!Array.<shaka.extern.AdInterstitial> } interstitials
229
+ */
230
+ addInterstitials ( interstitials ) {
231
+ if ( this . basePlayer_ . getLoadMode ( ) == shaka . Player . LoadMode . SRC_EQUALS &&
232
+ this . usingBaseVideo_ ) {
233
+ shaka . log . alwaysWarn (
234
+ 'Unsupported interstitial when using single media element' ,
235
+ interstitials ) ;
236
+ return ;
237
+ }
218
238
let cuepointsChanged = false ;
219
- const interstitialsAd = await this . getInterstitialsInfo_ ( interstitial ) ;
220
- if ( interstitialsAd . length ) {
221
- for ( const interstitialAd of interstitialsAd ) {
222
- const interstitialId = JSON . stringify ( interstitialAd ) ;
223
- if ( this . interstitialIds_ . has ( interstitialId ) ) {
224
- continue ;
225
- }
226
- cuepointsChanged = true ;
227
- this . interstitialIds_ . add ( interstitialId ) ;
228
- this . interstitials_ . add ( interstitialAd ) ;
229
- let shouldPreload = false ;
230
- if ( interstitial . pre && this . lastTime_ == null ) {
231
- shouldPreload = true ;
232
- } else if ( interstitialAd . startTime == 0 && ! interstitialAd . canJump ) {
239
+ for ( const interstitial of interstitials ) {
240
+ const interstitialId = JSON . stringify ( interstitial ) ;
241
+ if ( this . interstitialIds_ . has ( interstitialId ) ) {
242
+ continue ;
243
+ }
244
+ cuepointsChanged = true ;
245
+ this . interstitialIds_ . add ( interstitialId ) ;
246
+ this . interstitials_ . add ( interstitial ) ;
247
+ let shouldPreload = false ;
248
+ if ( interstitial . pre && this . lastTime_ == null ) {
249
+ shouldPreload = true ;
250
+ } else if ( interstitial . startTime == 0 && ! interstitial . canJump ) {
251
+ shouldPreload = true ;
252
+ } else if ( this . lastTime_ != null ) {
253
+ const difference = interstitial . startTime - this . lastTime_ ;
254
+ if ( difference > 0 && difference <= 10 ) {
233
255
shouldPreload = true ;
234
- } else if ( this . lastTime_ != null ) {
235
- const difference = interstitial . startTime - this . lastTime_ ;
236
- if ( difference > 0 && difference <= 10 ) {
237
- shouldPreload = true ;
238
- }
239
256
}
240
- if ( shouldPreload ) {
241
- if ( ! this . preloadManagerInterstitials_ . has ( interstitialAd ) ) {
242
- this . preloadManagerInterstitials_ . set (
243
- interstitialAd , this . player_ . preload ( interstitialAd . uri ) ) ;
244
- }
257
+ }
258
+ if ( shouldPreload ) {
259
+ if ( ! this . preloadManagerInterstitials_ . has ( interstitial ) ) {
260
+ this . preloadManagerInterstitials_ . set (
261
+ interstitial , this . player_ . preload ( interstitial . uri ) ) ;
245
262
}
246
263
}
247
- } else {
248
- shaka . log . alwaysWarn ( 'Unsupported interstitial' , interstitial ) ;
249
264
}
250
265
if ( cuepointsChanged ) {
251
266
this . cuepointsChanged_ ( ) ;
@@ -274,7 +289,7 @@ shaka.ads.InterstitialAdManager = class {
274
289
/**
275
290
* @param {boolean } needPreRoll
276
291
* @param {number= } numberToSkip
277
- * @return {?shaka.ads.InterstitialAdManager.Interstitial }
292
+ * @return {?shaka.extern.AdInterstitial }
278
293
* @private
279
294
*/
280
295
getCurrentInterstitial_ ( needPreRoll , numberToSkip = 0 ) {
@@ -314,7 +329,7 @@ shaka.ads.InterstitialAdManager = class {
314
329
315
330
316
331
/**
317
- * @param {shaka.ads.InterstitialAdManager.Interstitial } interstitial
332
+ * @param {shaka.extern.AdInterstitial } interstitial
318
333
* @param {number } sequenceLength
319
334
* @param {number } adPosition
320
335
* @param {number } initialTime the clock time the ad started at
@@ -554,21 +569,22 @@ shaka.ads.InterstitialAdManager = class {
554
569
555
570
556
571
/**
557
- * @param {shaka.extern.Interstitial } interstitial
558
- * @return {!Promise.<!Array.<shaka.ads.InterstitialAdManager.Interstitial >> }
572
+ * @param {shaka.extern.HLSInterstitial } hlsInterstitial
573
+ * @return {!Promise.<!Array.<shaka.extern.AdInterstitial >> }
559
574
* @private
560
575
*/
561
- async getInterstitialsInfo_ ( interstitial ) {
576
+ async getInterstitialsInfo_ ( hlsInterstitial ) {
562
577
const interstitialsAd = [ ] ;
563
- if ( ! interstitial ) {
578
+ if ( ! hlsInterstitial ) {
564
579
return interstitialsAd ;
565
580
}
566
- const assetUri = interstitial . values . find ( ( v ) => v . key == 'X-ASSET-URI' ) ;
567
- const assetList = interstitial . values . find ( ( v ) => v . key == 'X-ASSET-LIST' ) ;
581
+ const assetUri = hlsInterstitial . values . find ( ( v ) => v . key == 'X-ASSET-URI' ) ;
582
+ const assetList =
583
+ hlsInterstitial . values . find ( ( v ) => v . key == 'X-ASSET-LIST' ) ;
568
584
if ( ! assetUri && ! assetList ) {
569
585
return interstitialsAd ;
570
586
}
571
- const restrict = interstitial . values . find ( ( v ) => v . key == 'X-RESTRICT' ) ;
587
+ const restrict = hlsInterstitial . values . find ( ( v ) => v . key == 'X-RESTRICT' ) ;
572
588
let isSkippable = true ;
573
589
let canJump = true ;
574
590
if ( restrict && restrict . data ) {
@@ -577,7 +593,8 @@ shaka.ads.InterstitialAdManager = class {
577
593
canJump = ! data . includes ( 'JUMP' ) ;
578
594
}
579
595
let resumeOffset = null ;
580
- const resume = interstitial . values . find ( ( v ) => v . key == 'X-RESUME-OFFSET' ) ;
596
+ const resume =
597
+ hlsInterstitial . values . find ( ( v ) => v . key == 'X-RESUME-OFFSET' ) ;
581
598
if ( resume ) {
582
599
const resumeOffsetString = /** @type {string } */ ( resume . data ) ;
583
600
resumeOffset = parseFloat ( resumeOffsetString ) ;
@@ -586,7 +603,8 @@ shaka.ads.InterstitialAdManager = class {
586
603
}
587
604
}
588
605
let playoutLimit = null ;
589
- const playout = interstitial . values . find ( ( v ) => v . key == 'X-PLAYOUT-LIMIT' ) ;
606
+ const playout =
607
+ hlsInterstitial . values . find ( ( v ) => v . key == 'X-PLAYOUT-LIMIT' ) ;
590
608
if ( playout ) {
591
609
const playoutLimitString = /** @type {string } */ ( playout . data ) ;
592
610
playoutLimit = parseFloat ( playoutLimitString ) ;
@@ -597,7 +615,7 @@ shaka.ads.InterstitialAdManager = class {
597
615
let once = false ;
598
616
let pre = false ;
599
617
let post = false ;
600
- const cue = interstitial . values . find ( ( v ) => v . key == 'CUE' ) ;
618
+ const cue = hlsInterstitial . values . find ( ( v ) => v . key == 'CUE' ) ;
601
619
if ( cue ) {
602
620
const data = /** @type {string } */ ( cue . data ) ;
603
621
once = data . includes ( 'ONCE' ) ;
@@ -606,7 +624,7 @@ shaka.ads.InterstitialAdManager = class {
606
624
}
607
625
let timelineRange = true ;
608
626
const timelineOccupies =
609
- interstitial . values . find ( ( v ) => v . key == 'X-TIMELINE-OCCUPIES' ) ;
627
+ hlsInterstitial . values . find ( ( v ) => v . key == 'X-TIMELINE-OCCUPIES' ) ;
610
628
if ( timelineOccupies ) {
611
629
const data = /** @type {string } */ ( timelineOccupies . data ) ;
612
630
timelineRange = data . includes ( 'RANGE' ) ;
@@ -619,8 +637,8 @@ shaka.ads.InterstitialAdManager = class {
619
637
return interstitialsAd ;
620
638
}
621
639
interstitialsAd . push ( {
622
- startTime : interstitial . startTime ,
623
- endTime : interstitial . endTime ,
640
+ startTime : hlsInterstitial . startTime ,
641
+ endTime : hlsInterstitial . endTime ,
624
642
uri,
625
643
isSkippable,
626
644
canJump,
@@ -650,8 +668,8 @@ shaka.ads.InterstitialAdManager = class {
650
668
for ( const asset of dataAsJson . ASSETS ) {
651
669
if ( asset . URI ) {
652
670
interstitialsAd . push ( {
653
- startTime : interstitial . startTime ,
654
- endTime : interstitial . endTime ,
671
+ startTime : hlsInterstitial . startTime ,
672
+ endTime : hlsInterstitial . endTime ,
655
673
uri : asset . URI ,
656
674
isSkippable,
657
675
canJump,
@@ -741,33 +759,3 @@ shaka.ads.InterstitialAdManager.AssetsList;
741
759
* @property {string } URI
742
760
*/
743
761
shaka . ads . InterstitialAdManager . Asset ;
744
-
745
-
746
- /**
747
- * @typedef {{
748
- * startTime: number,
749
- * endTime: ?number,
750
- * uri: string,
751
- * isSkippable: boolean,
752
- * canJump: boolean,
753
- * resumeOffset: ?number,
754
- * playoutLimit: ?number,
755
- * once: boolean,
756
- * pre: boolean,
757
- * post: boolean,
758
- * timelineRange: boolean
759
- * }}
760
- *
761
- * @property {number } startTime
762
- * @property {?number } endTime
763
- * @property {string } uri
764
- * @property {boolean } isSkippable
765
- * @property {boolean } canJump
766
- * @property {?number } resumeOffset
767
- * @property {?number } playoutLimit
768
- * @property {boolean } once
769
- * @property {boolean } pre
770
- * @property {boolean } post
771
- * @property {boolean } timelineRange
772
- */
773
- shaka . ads . InterstitialAdManager . Interstitial ;
0 commit comments