stormcloud-video-player 0.3.39 → 0.3.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2896,7 +2896,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2896
2896
  this.adRequestQueue = [];
2897
2897
  this.maxPlaceholderDurationMs = 5e3;
2898
2898
  this.isShowingPlaceholder = false;
2899
- this.imaControllerPool = /* @__PURE__ */ new Map();
2900
2899
  this.totalAdRequestsInBreak = 0;
2901
2900
  this.maxTotalAdRequestsPerBreak = 20;
2902
2901
  this.pendingAdBreak = null;
@@ -3410,6 +3409,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3410
3409
  _this.clearAdRequestWatchdog();
3411
3410
  _this.activeAdRequestToken = null;
3412
3411
  _this.showAds = true;
3412
+ if (_this.isShowingPlaceholder) {
3413
+ if (_this.config.debugAdTiming) {
3414
+ console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3415
+ }
3416
+ _this.ima.hidePlaceholder();
3417
+ _this.isShowingPlaceholder = false;
3418
+ }
3413
3419
  });
3414
3420
  this.ima.on("content_resume", function() {
3415
3421
  _this.clearAdFailsafeTimer();
@@ -3440,123 +3446,32 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3440
3446
  if (this.config.debugAdTiming) {
3441
3447
  console.log("[StormcloudVideoPlayer] Recreating ImaController for new ad");
3442
3448
  }
3443
- var oldIma = this.ima;
3444
3449
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3445
- var continueLiveStreamDuringAds = this.shouldContinueLiveStreamDuringAds();
3446
- this.ima = this.createAdPlayer(continueLiveStreamDuringAds);
3447
- this.ima.initialize();
3448
- this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3449
- this.attachImaEventListeners();
3450
- if (shouldShowPlaceholder) {
3450
+ if (shouldShowPlaceholder && this.ima) {
3451
+ if (this.config.debugAdTiming) {
3452
+ console.log("[StormcloudVideoPlayer] Showing placeholder before destroying old ImaController");
3453
+ }
3451
3454
  this.ima.showPlaceholder();
3455
+ this.isShowingPlaceholder = true;
3452
3456
  }
3453
- if (oldIma) {
3457
+ if (this.ima) {
3454
3458
  try {
3455
- oldIma.destroy();
3459
+ this.ima.destroy();
3456
3460
  } catch (error) {
3457
3461
  if (this.config.debugAdTiming) {
3458
3462
  console.warn("[StormcloudVideoPlayer] Error destroying old ImaController:", error);
3459
3463
  }
3460
3464
  }
3461
3465
  }
3462
- }
3463
- },
3464
- {
3465
- key: "precreateImaController",
3466
- value: function precreateImaController(vastTagUrl) {
3467
- if (this.imaControllerPool.has(vastTagUrl)) {
3468
- return this.imaControllerPool.get(vastTagUrl);
3469
- }
3470
- if (this.config.debugAdTiming) {
3471
- console.log("[StormcloudVideoPlayer] Pre-creating ImaController for: ".concat(vastTagUrl));
3472
- }
3473
- var continueLiveStreamDuringAds = this.shouldContinueLiveStreamDuringAds();
3474
- var controller = this.createAdPlayer(continueLiveStreamDuringAds);
3475
- controller.initialize();
3476
- controller.updateOriginalMutedState(this.video.muted, this.video.volume);
3477
- this.attachImaEventListenersToController(controller);
3478
- this.imaControllerPool.set(vastTagUrl, controller);
3479
- return controller;
3480
- }
3481
- },
3482
- {
3483
- key: "getOrCreateImaController",
3484
- value: function getOrCreateImaController(vastTagUrl) {
3485
- if (this.imaControllerPool.has(vastTagUrl)) {
3486
- var controller2 = this.imaControllerPool.get(vastTagUrl);
3487
- this.imaControllerPool.delete(vastTagUrl);
3488
- return controller2;
3489
- }
3490
- if (this.config.debugAdTiming) {
3491
- console.log("[StormcloudVideoPlayer] Controller not in pool, creating new one for: ".concat(vastTagUrl));
3492
- }
3493
3466
  var continueLiveStreamDuringAds = this.shouldContinueLiveStreamDuringAds();
3494
- var controller = this.createAdPlayer(continueLiveStreamDuringAds);
3495
- controller.initialize();
3496
- controller.updateOriginalMutedState(this.video.muted, this.video.volume);
3497
- this.attachImaEventListenersToController(controller);
3498
- return controller;
3499
- }
3500
- },
3501
- {
3502
- key: "switchToImaController",
3503
- value: function switchToImaController(vastTagUrl) {
3504
- var oldIma = this.ima;
3505
- var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3506
- this.ima = this.getOrCreateImaController(vastTagUrl);
3467
+ this.ima = this.createAdPlayer(continueLiveStreamDuringAds);
3468
+ this.ima.initialize();
3469
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3470
+ this.attachImaEventListeners();
3507
3471
  if (shouldShowPlaceholder) {
3508
3472
  this.ima.showPlaceholder();
3473
+ this.isShowingPlaceholder = true;
3509
3474
  }
3510
- if (oldIma && oldIma !== this.ima) {
3511
- try {
3512
- oldIma.destroy();
3513
- } catch (error) {
3514
- if (this.config.debugAdTiming) {
3515
- console.warn("[StormcloudVideoPlayer] Error destroying old ImaController:", error);
3516
- }
3517
- }
3518
- }
3519
- }
3520
- },
3521
- {
3522
- key: "attachImaEventListenersToController",
3523
- value: function attachImaEventListenersToController(controller) {
3524
- var originalIma = this.ima;
3525
- this.ima = controller;
3526
- this.attachImaEventListeners();
3527
- this.ima = originalIma;
3528
- }
3529
- },
3530
- {
3531
- key: "cleanupImaControllerPool",
3532
- value: function cleanupImaControllerPool() {
3533
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3534
- try {
3535
- for(var _iterator = this.imaControllerPool.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3536
- var _step_value = _sliced_to_array(_step.value, 2), vastTagUrl = _step_value[0], controller = _step_value[1];
3537
- try {
3538
- controller.destroy();
3539
- } catch (error) {
3540
- if (this.config.debugAdTiming) {
3541
- console.warn("[StormcloudVideoPlayer] Error destroying controller for ".concat(vastTagUrl, ":"), error);
3542
- }
3543
- }
3544
- }
3545
- } catch (err) {
3546
- _didIteratorError = true;
3547
- _iteratorError = err;
3548
- } finally{
3549
- try {
3550
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3551
- _iterator.return();
3552
- }
3553
- } finally{
3554
- if (_didIteratorError) {
3555
- throw _iteratorError;
3556
- }
3557
- }
3558
- }
3559
- this.imaControllerPool.clear();
3560
3475
  }
3561
3476
  },
3562
3477
  {
@@ -4352,7 +4267,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4352
4267
  key: "handleAdStart",
4353
4268
  value: function handleAdStart(_marker) {
4354
4269
  return _async_to_generator(function() {
4355
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, vastTagUrl, firstAdUrlArray, error;
4270
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, firstAdUrlArray, error;
4356
4271
  return _ts_generator(this, function(_state) {
4357
4272
  switch(_state.label){
4358
4273
  case 0:
@@ -4399,32 +4314,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4399
4314
  if (this.config.debugAdTiming) {
4400
4315
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using prefetched ad URLs (".concat(this.adRequestQueue.length + 1, " available)"));
4401
4316
  }
4402
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4403
- try {
4404
- for(_iterator = this.adRequestQueue[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4405
- vastTagUrl = _step.value;
4406
- try {
4407
- this.precreateImaController(vastTagUrl);
4408
- } catch (error) {
4409
- if (this.config.debugAdTiming) {
4410
- console.warn("[StormcloudVideoPlayer] Failed to pre-create controller for ".concat(vastTagUrl, ":"), error);
4411
- }
4412
- }
4413
- }
4414
- } catch (err) {
4415
- _didIteratorError = true;
4416
- _iteratorError = err;
4417
- } finally{
4418
- try {
4419
- if (!_iteratorNormalCompletion && _iterator.return != null) {
4420
- _iterator.return();
4421
- }
4422
- } finally{
4423
- if (_didIteratorError) {
4424
- throw _iteratorError;
4425
- }
4426
- }
4427
- }
4428
4317
  this.clearPendingAdBreak();
4429
4318
  } else {
4430
4319
  if (this.config.debugAdTiming) {
@@ -4623,13 +4512,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4623
4512
  }
4624
4513
  _this.adRequestQueue.push(newAdUrl);
4625
4514
  _this.totalAdsInBreak++;
4626
- try {
4627
- _this.precreateImaController(newAdUrl);
4628
- } catch (error) {
4629
- if (_this.config.debugAdTiming) {
4630
- console.warn("[StormcloudVideoPlayer] Failed to pre-create controller for ".concat(newAdUrl, ":"), error);
4631
- }
4632
- }
4633
4515
  generationDelay = _this.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.consecutiveFailures), 5e3) : 500;
4634
4516
  return [
4635
4517
  4,
@@ -4689,36 +4571,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4689
4571
  if (this.config.debugAdTiming) {
4690
4572
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Stopping continuous ad fetching");
4691
4573
  }
4692
- var queueSet = new Set(this.adRequestQueue);
4693
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4694
- try {
4695
- for(var _iterator = this.imaControllerPool.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4696
- var _step_value = _sliced_to_array(_step.value, 2), vastTagUrl = _step_value[0], controller = _step_value[1];
4697
- if (!queueSet.has(vastTagUrl)) {
4698
- try {
4699
- controller.destroy();
4700
- } catch (error) {
4701
- if (this.config.debugAdTiming) {
4702
- console.warn("[StormcloudVideoPlayer] Error destroying unused controller for ".concat(vastTagUrl, ":"), error);
4703
- }
4704
- }
4705
- this.imaControllerPool.delete(vastTagUrl);
4706
- }
4707
- }
4708
- } catch (err) {
4709
- _didIteratorError = true;
4710
- _iteratorError = err;
4711
- } finally{
4712
- try {
4713
- if (!_iteratorNormalCompletion && _iterator.return != null) {
4714
- _iterator.return();
4715
- }
4716
- } finally{
4717
- if (_didIteratorError) {
4718
- throw _iteratorError;
4719
- }
4720
- }
4721
- }
4722
4574
  }
4723
4575
  },
4724
4576
  {
@@ -5353,10 +5205,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5353
5205
  }
5354
5206
  throw new Error("Too many consecutive failures");
5355
5207
  }
5356
- this.switchToImaController(vastTagUrl);
5357
- if (this.inAdBreak && this.showAds && !this.isShowingPlaceholder) {
5358
- this.ima.showPlaceholder();
5359
- }
5208
+ this.recreateImaController();
5360
5209
  requestToken = ++this.adRequestTokenCounter;
5361
5210
  this.activeAdRequestToken = requestToken;
5362
5211
  this.startAdRequestWatchdog(requestToken);
@@ -5476,7 +5325,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5476
5325
  this.isShowingPlaceholder = false;
5477
5326
  }
5478
5327
  this.adRequestQueue = [];
5479
- this.cleanupImaControllerPool();
5480
5328
  this.inAdBreak = false;
5481
5329
  this.expectedAdBreakDurationMs = void 0;
5482
5330
  this.currentAdBreakStartWallClockMs = void 0;
@@ -5868,7 +5716,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5868
5716
  }
5869
5717
  (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.destroy();
5870
5718
  (_this_ima = this.ima) === null || _this_ima === void 0 ? void 0 : _this_ima.destroy();
5871
- this.cleanupImaControllerPool();
5872
5719
  this.adRequestQueue = [];
5873
5720
  this.consecutiveFailures = 0;
5874
5721
  }