stormcloud-video-player 0.3.39 → 0.3.41

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.
@@ -932,8 +932,8 @@ function createImaController(video, options) {
932
932
  container.style.justifyContent = "center";
933
933
  container.style.pointerEvents = "none";
934
934
  container.style.zIndex = "10";
935
- container.style.backgroundColor = "transparent";
936
- container.style.transition = "opacity 0.3s ease-in-out, background-color 0.3s ease-in-out";
935
+ container.style.backgroundColor = "#000";
936
+ container.style.transition = "opacity 0.3s ease-in-out";
937
937
  container.style.opacity = "0";
938
938
  (_video_parentElement = video.parentElement) === null || _video_parentElement === void 0 ? void 0 : _video_parentElement.appendChild(container);
939
939
  adContainerEl = container;
@@ -1390,11 +1390,11 @@ function createImaController(video, options) {
1390
1390
  adPlaying = false;
1391
1391
  setAdPlayingFlag(false);
1392
1392
  if (adContainerEl) {
1393
- adContainerEl.style.opacity = "0";
1394
- adContainerEl.style.backgroundColor = "transparent";
1393
+ adContainerEl.style.backgroundColor = "#000";
1394
+ adContainerEl.style.opacity = "1";
1395
+ adContainerEl.style.pointerEvents = "none";
1395
1396
  setTimeout(function() {
1396
1397
  if (adContainerEl) {
1397
- adContainerEl.style.pointerEvents = "none";
1398
1398
  adContainerEl.style.display = "none";
1399
1399
  if (adContainerEl.parentElement) {
1400
1400
  adContainerEl.parentElement.removeChild(adContainerEl);
@@ -1402,7 +1402,7 @@ function createImaController(video, options) {
1402
1402
  adContainerEl = void 0;
1403
1403
  adVideoElement = void 0;
1404
1404
  }
1405
- }, 300);
1405
+ }, 500);
1406
1406
  }
1407
1407
  showContentVideo();
1408
1408
  try {
@@ -1478,21 +1478,34 @@ function createImaController(video, options) {
1478
1478
  ensurePlaceholderContainer();
1479
1479
  hideContentVideo();
1480
1480
  if (adContainerEl) {
1481
- adContainerEl.style.display = "flex";
1481
+ var wasHidden = adContainerEl.style.display === "none" || adContainerEl.style.opacity === "0";
1482
+ if (wasHidden) {
1483
+ adContainerEl.style.transition = "none";
1484
+ } else {
1485
+ adContainerEl.style.transition = "opacity 0.3s ease-in-out";
1486
+ }
1482
1487
  adContainerEl.style.backgroundColor = "#000";
1488
+ adContainerEl.style.display = "flex";
1483
1489
  adContainerEl.offsetHeight;
1484
1490
  adContainerEl.style.opacity = "1";
1485
1491
  adContainerEl.style.pointerEvents = "auto";
1492
+ if (wasHidden) {
1493
+ requestAnimationFrame(function() {
1494
+ if (adContainerEl) {
1495
+ adContainerEl.style.transition = "opacity 0.3s ease-in-out";
1496
+ }
1497
+ });
1498
+ }
1486
1499
  }
1487
1500
  },
1488
1501
  hidePlaceholder: function hidePlaceholder() {
1489
1502
  if (adContainerEl) {
1490
1503
  adContainerEl.style.opacity = "0";
1491
- adContainerEl.style.backgroundColor = "transparent";
1492
1504
  setTimeout(function() {
1493
1505
  if (adContainerEl) {
1494
1506
  adContainerEl.style.display = "none";
1495
1507
  adContainerEl.style.pointerEvents = "none";
1508
+ adContainerEl.style.backgroundColor = "#000";
1496
1509
  }
1497
1510
  }, 300);
1498
1511
  }
@@ -2896,7 +2909,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2896
2909
  this.adRequestQueue = [];
2897
2910
  this.maxPlaceholderDurationMs = 5e3;
2898
2911
  this.isShowingPlaceholder = false;
2899
- this.imaControllerPool = /* @__PURE__ */ new Map();
2900
2912
  this.totalAdRequestsInBreak = 0;
2901
2913
  this.maxTotalAdRequestsPerBreak = 20;
2902
2914
  this.pendingAdBreak = null;
@@ -3410,6 +3422,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3410
3422
  _this.clearAdRequestWatchdog();
3411
3423
  _this.activeAdRequestToken = null;
3412
3424
  _this.showAds = true;
3425
+ if (_this.isShowingPlaceholder) {
3426
+ if (_this.config.debugAdTiming) {
3427
+ console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3428
+ }
3429
+ _this.ima.hidePlaceholder();
3430
+ _this.isShowingPlaceholder = false;
3431
+ }
3413
3432
  });
3414
3433
  this.ima.on("content_resume", function() {
3415
3434
  _this.clearAdFailsafeTimer();
@@ -3440,123 +3459,32 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3440
3459
  if (this.config.debugAdTiming) {
3441
3460
  console.log("[StormcloudVideoPlayer] Recreating ImaController for new ad");
3442
3461
  }
3443
- var oldIma = this.ima;
3444
3462
  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) {
3463
+ if (shouldShowPlaceholder && this.ima) {
3464
+ if (this.config.debugAdTiming) {
3465
+ console.log("[StormcloudVideoPlayer] Showing placeholder before destroying old ImaController");
3466
+ }
3451
3467
  this.ima.showPlaceholder();
3468
+ this.isShowingPlaceholder = true;
3452
3469
  }
3453
- if (oldIma) {
3470
+ if (this.ima) {
3454
3471
  try {
3455
- oldIma.destroy();
3472
+ this.ima.destroy();
3456
3473
  } catch (error) {
3457
3474
  if (this.config.debugAdTiming) {
3458
3475
  console.warn("[StormcloudVideoPlayer] Error destroying old ImaController:", error);
3459
3476
  }
3460
3477
  }
3461
3478
  }
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
3479
  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
- 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);
3480
+ this.ima = this.createAdPlayer(continueLiveStreamDuringAds);
3481
+ this.ima.initialize();
3482
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3483
+ this.attachImaEventListeners();
3507
3484
  if (shouldShowPlaceholder) {
3508
3485
  this.ima.showPlaceholder();
3486
+ this.isShowingPlaceholder = true;
3509
3487
  }
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
3488
  }
3561
3489
  },
3562
3490
  {
@@ -4352,7 +4280,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4352
4280
  key: "handleAdStart",
4353
4281
  value: function handleAdStart(_marker) {
4354
4282
  return _async_to_generator(function() {
4355
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, vastTagUrl, firstAdUrlArray, error;
4283
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, firstAdUrlArray, error;
4356
4284
  return _ts_generator(this, function(_state) {
4357
4285
  switch(_state.label){
4358
4286
  case 0:
@@ -4399,32 +4327,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4399
4327
  if (this.config.debugAdTiming) {
4400
4328
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using prefetched ad URLs (".concat(this.adRequestQueue.length + 1, " available)"));
4401
4329
  }
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
4330
  this.clearPendingAdBreak();
4429
4331
  } else {
4430
4332
  if (this.config.debugAdTiming) {
@@ -4623,13 +4525,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4623
4525
  }
4624
4526
  _this.adRequestQueue.push(newAdUrl);
4625
4527
  _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
4528
  generationDelay = _this.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.consecutiveFailures), 5e3) : 500;
4634
4529
  return [
4635
4530
  4,
@@ -4689,36 +4584,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4689
4584
  if (this.config.debugAdTiming) {
4690
4585
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Stopping continuous ad fetching");
4691
4586
  }
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
4587
  }
4723
4588
  },
4724
4589
  {
@@ -5353,10 +5218,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5353
5218
  }
5354
5219
  throw new Error("Too many consecutive failures");
5355
5220
  }
5356
- this.switchToImaController(vastTagUrl);
5357
- if (this.inAdBreak && this.showAds && !this.isShowingPlaceholder) {
5358
- this.ima.showPlaceholder();
5359
- }
5221
+ this.recreateImaController();
5360
5222
  requestToken = ++this.adRequestTokenCounter;
5361
5223
  this.activeAdRequestToken = requestToken;
5362
5224
  this.startAdRequestWatchdog(requestToken);
@@ -5476,7 +5338,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5476
5338
  this.isShowingPlaceholder = false;
5477
5339
  }
5478
5340
  this.adRequestQueue = [];
5479
- this.cleanupImaControllerPool();
5480
5341
  this.inAdBreak = false;
5481
5342
  this.expectedAdBreakDurationMs = void 0;
5482
5343
  this.currentAdBreakStartWallClockMs = void 0;
@@ -5868,7 +5729,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5868
5729
  }
5869
5730
  (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.destroy();
5870
5731
  (_this_ima = this.ima) === null || _this_ima === void 0 ? void 0 : _this_ima.destroy();
5871
- this.cleanupImaControllerPool();
5872
5732
  this.adRequestQueue = [];
5873
5733
  this.consecutiveFailures = 0;
5874
5734
  }