stormcloud-video-player 0.6.2 → 0.6.3

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.
@@ -1257,7 +1257,7 @@ function createVastAdLayer(contentVideo, options) {
1257
1257
  }
1258
1258
  function playAd(bids) {
1259
1259
  return _async_to_generator(function() {
1260
- var winner, ad, contentVolume, _contentVideo_parentElement, container, adVolume, mediaFile;
1260
+ var winner, ad, contentVolume, adVolume2, mediaFile2, _contentVideo_parentElement, container, adVolume, mediaFile;
1261
1261
  return _ts_generator(this, function(_state) {
1262
1262
  switch(_state.label){
1263
1263
  case 0:
@@ -1301,37 +1301,71 @@ function createVastAdLayer(contentVideo, options) {
1301
1301
  trackingFired.impression = true;
1302
1302
  contentVolume = contentVideo.volume;
1303
1303
  originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1304
- if (singleElementMode) {
1305
- mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1306
- teardownCurrentPlayback();
1307
- adVideoElement = contentVideo;
1308
- adHls = void 0;
1304
+ if (!singleElementMode) return [
1305
+ 3,
1306
+ 3
1307
+ ];
1308
+ mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1309
+ teardownCurrentPlayback();
1310
+ adVideoElement = contentVideo;
1311
+ adHls = void 0;
1312
+ adPlaying = true;
1313
+ setAdPlayingFlag(true);
1314
+ contentVideo.removeAttribute("src");
1315
+ contentVideo.load();
1316
+ if (!continueLiveStreamDuringAds) {
1317
+ contentVideo.pause();
1318
+ }
1319
+ contentVideo.muted = true;
1320
+ contentVideo.volume = 0;
1321
+ return [
1322
+ 4,
1323
+ new Promise(function(resolve) {
1324
+ return setTimeout(resolve, 200);
1325
+ })
1326
+ ];
1327
+ case 2:
1328
+ _state.sent();
1329
+ if (destroyed || tornDown) return [
1330
+ 2
1331
+ ];
1332
+ contentVideo.style.visibility = "visible";
1333
+ contentVideo.style.opacity = "1";
1334
+ emit("content_pause");
1335
+ setupAdEventListeners();
1336
+ adVolume2 = originalMutedState ? 1 : originalVolume;
1337
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1338
+ adVideoElement.muted = false;
1339
+ mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1340
+ if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1341
+ startPlayback(mediaFile2);
1342
+ return [
1343
+ 2
1344
+ ];
1345
+ case 3:
1346
+ if (!adContainerEl) {
1347
+ ;
1348
+ container = document.createElement("div");
1349
+ container.style.position = "absolute";
1350
+ container.style.left = "0";
1351
+ container.style.top = "0";
1352
+ container.style.right = "0";
1353
+ container.style.bottom = "0";
1354
+ container.style.display = "none";
1355
+ container.style.alignItems = "center";
1356
+ container.style.justifyContent = "center";
1357
+ container.style.pointerEvents = "none";
1358
+ container.style.zIndex = "10";
1359
+ container.style.backgroundColor = "#000";
1360
+ (_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
1361
+ adContainerEl = container;
1362
+ }
1363
+ if (!adVideoElement) {
1364
+ adVideoElement = createAdVideoElement();
1365
+ adContainerEl.appendChild(adVideoElement);
1309
1366
  setupAdEventListeners();
1310
1367
  } else {
1311
- if (!adContainerEl) {
1312
- ;
1313
- container = document.createElement("div");
1314
- container.style.position = "absolute";
1315
- container.style.left = "0";
1316
- container.style.top = "0";
1317
- container.style.right = "0";
1318
- container.style.bottom = "0";
1319
- container.style.display = "none";
1320
- container.style.alignItems = "center";
1321
- container.style.justifyContent = "center";
1322
- container.style.pointerEvents = "none";
1323
- container.style.zIndex = "10";
1324
- container.style.backgroundColor = "#000";
1325
- (_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
1326
- adContainerEl = container;
1327
- }
1328
- if (!adVideoElement) {
1329
- adVideoElement = createAdVideoElement();
1330
- adContainerEl.appendChild(adVideoElement);
1331
- setupAdEventListeners();
1332
- } else {
1333
- teardownCurrentPlayback();
1334
- }
1368
+ teardownCurrentPlayback();
1335
1369
  }
1336
1370
  if (!continueLiveStreamDuringAds) {
1337
1371
  contentVideo.pause();
@@ -1343,7 +1377,7 @@ function createVastAdLayer(contentVideo, options) {
1343
1377
  adVolume = originalMutedState ? 1 : originalVolume;
1344
1378
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1345
1379
  adVideoElement.muted = false;
1346
- if (!singleElementMode && adContainerEl) {
1380
+ if (adContainerEl) {
1347
1381
  adContainerEl.style.display = "flex";
1348
1382
  adContainerEl.style.pointerEvents = "auto";
1349
1383
  }
@@ -1447,6 +1481,7 @@ function createVastAdLayer(contentVideo, options) {
1447
1481
  if (debug) console.log("".concat(LOG, " [preload] HLS manifest parsed, token=").concat(token));
1448
1482
  });
1449
1483
  hls.on(import_hls.default.Events.ERROR, function(_evt, data) {
1484
+ if (!preloadSlots.has(token)) return;
1450
1485
  if (data.fatal) {
1451
1486
  if (debug) console.warn("".concat(LOG, " [preload] HLS error for token=").concat(token));
1452
1487
  preloadSlots.delete(token);
@@ -1483,113 +1518,146 @@ function createVastAdLayer(contentVideo, options) {
1483
1518
  }
1484
1519
  function playPreloaded(token) {
1485
1520
  return _async_to_generator(function() {
1486
- var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, adVolume, container;
1521
+ var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, nonFatalNetworkErrors, adVolume, container;
1487
1522
  return _ts_generator(this, function(_state) {
1488
- if (destroyed) return [
1489
- 2,
1490
- Promise.reject(new Error("Layer has been destroyed"))
1491
- ];
1492
- slot = preloadSlots.get(token);
1493
- if (!slot) {
1494
- if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
1495
- return [
1496
- 2
1497
- ];
1498
- }
1499
- preloadSlots.delete(token);
1500
- if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
1501
- contentVolume = contentVideo.volume;
1502
- originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1503
- sessionId = generateSessionId();
1504
- currentAd = slot.ad;
1505
- trackingFired = _object_spread({}, createEmptyTrackingState());
1506
- fireTrackingPixels2(slot.ad.trackingUrls.impression);
1507
- trackingFired.impression = true;
1508
- if (singleElementMode) {
1509
- mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1510
- teardownCurrentPlayback();
1511
- adVideoElement = contentVideo;
1512
- adHls = void 0;
1513
- setupAdEventListeners();
1514
- if (!continueLiveStreamDuringAds) {
1515
- contentVideo.pause();
1516
- }
1517
- contentVideo.muted = true;
1518
- contentVideo.volume = 0;
1519
- adPlaying = true;
1520
- setAdPlayingFlag(true);
1521
- adVolume2 = originalMutedState ? 1 : originalVolume;
1522
- contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
1523
- contentVideo.muted = false;
1524
- emit("content_pause");
1525
- if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
1526
- startPlayback(slot.mediaFile);
1527
- return [
1528
- 2
1529
- ];
1530
- }
1531
- if (smartTVMode && !slot.videoEl) {
1532
- teardownCurrentPlayback();
1533
- if (adVideoElement) {
1534
- adVideoElement.remove();
1535
- adVideoElement = void 0;
1536
- }
1537
- videoEl = createAdVideoElement();
1538
- videoEl.style.visibility = "visible";
1539
- videoEl.style.pointerEvents = "none";
1540
- container2 = ensureAdContainer();
1541
- container2.appendChild(videoEl);
1542
- adVideoElement = videoEl;
1543
- setupAdEventListeners();
1544
- if (!continueLiveStreamDuringAds) {
1545
- contentVideo.pause();
1546
- }
1547
- contentVideo.muted = true;
1548
- contentVideo.volume = 0;
1549
- adPlaying = true;
1550
- setAdPlayingFlag(true);
1551
- adVolume21 = originalMutedState ? 1 : originalVolume;
1552
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
1553
- adVideoElement.muted = false;
1554
- container2.style.display = "flex";
1555
- container2.style.pointerEvents = "auto";
1556
- emit("content_pause");
1557
- if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
1558
- startPlayback(slot.mediaFile);
1559
- return [
1560
- 2
1561
- ];
1562
- }
1563
- teardownCurrentPlayback();
1564
- if (adVideoElement && adVideoElement !== slot.videoEl) {
1565
- adVideoElement.remove();
1566
- }
1567
- slot.videoEl.style.visibility = "visible";
1568
- slot.videoEl.style.pointerEvents = "none";
1569
- adVideoElement = slot.videoEl;
1570
- adHls = slot.hlsInstance;
1571
- setupAdEventListeners();
1572
- if (!continueLiveStreamDuringAds) {
1573
- contentVideo.pause();
1523
+ switch(_state.label){
1524
+ case 0:
1525
+ if (destroyed) return [
1526
+ 2,
1527
+ Promise.reject(new Error("Layer has been destroyed"))
1528
+ ];
1529
+ slot = preloadSlots.get(token);
1530
+ if (!slot) {
1531
+ if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
1532
+ return [
1533
+ 2
1534
+ ];
1535
+ }
1536
+ preloadSlots.delete(token);
1537
+ if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
1538
+ contentVolume = contentVideo.volume;
1539
+ originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1540
+ sessionId = generateSessionId();
1541
+ currentAd = slot.ad;
1542
+ trackingFired = _object_spread({}, createEmptyTrackingState());
1543
+ fireTrackingPixels2(slot.ad.trackingUrls.impression);
1544
+ trackingFired.impression = true;
1545
+ if (!singleElementMode) return [
1546
+ 3,
1547
+ 2
1548
+ ];
1549
+ mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1550
+ teardownCurrentPlayback();
1551
+ adVideoElement = contentVideo;
1552
+ adHls = void 0;
1553
+ adPlaying = true;
1554
+ setAdPlayingFlag(true);
1555
+ contentVideo.removeAttribute("src");
1556
+ contentVideo.load();
1557
+ contentVideo.muted = true;
1558
+ contentVideo.volume = 0;
1559
+ return [
1560
+ 4,
1561
+ new Promise(function(resolve) {
1562
+ return setTimeout(resolve, 200);
1563
+ })
1564
+ ];
1565
+ case 1:
1566
+ _state.sent();
1567
+ if (destroyed || tornDown) return [
1568
+ 2
1569
+ ];
1570
+ contentVideo.style.visibility = "visible";
1571
+ contentVideo.style.opacity = "1";
1572
+ emit("content_pause");
1573
+ setupAdEventListeners();
1574
+ adVolume2 = originalMutedState ? 1 : originalVolume;
1575
+ contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
1576
+ contentVideo.muted = false;
1577
+ if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
1578
+ startPlayback(slot.mediaFile);
1579
+ return [
1580
+ 2
1581
+ ];
1582
+ case 2:
1583
+ if (smartTVMode && !slot.videoEl) {
1584
+ teardownCurrentPlayback();
1585
+ if (adVideoElement) {
1586
+ adVideoElement.remove();
1587
+ adVideoElement = void 0;
1588
+ }
1589
+ videoEl = createAdVideoElement();
1590
+ videoEl.style.visibility = "visible";
1591
+ videoEl.style.pointerEvents = "none";
1592
+ container2 = ensureAdContainer();
1593
+ container2.appendChild(videoEl);
1594
+ adVideoElement = videoEl;
1595
+ setupAdEventListeners();
1596
+ if (!continueLiveStreamDuringAds) {
1597
+ contentVideo.pause();
1598
+ }
1599
+ contentVideo.muted = true;
1600
+ contentVideo.volume = 0;
1601
+ adPlaying = true;
1602
+ setAdPlayingFlag(true);
1603
+ adVolume21 = originalMutedState ? 1 : originalVolume;
1604
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
1605
+ adVideoElement.muted = false;
1606
+ container2.style.display = "flex";
1607
+ container2.style.pointerEvents = "auto";
1608
+ emit("content_pause");
1609
+ if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
1610
+ startPlayback(slot.mediaFile);
1611
+ return [
1612
+ 2
1613
+ ];
1614
+ }
1615
+ teardownCurrentPlayback();
1616
+ if (adVideoElement && adVideoElement !== slot.videoEl) {
1617
+ adVideoElement.remove();
1618
+ }
1619
+ slot.videoEl.style.visibility = "visible";
1620
+ slot.videoEl.style.pointerEvents = "none";
1621
+ adVideoElement = slot.videoEl;
1622
+ adHls = slot.hlsInstance;
1623
+ if (adHls) {
1624
+ nonFatalNetworkErrors = 0;
1625
+ adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
1626
+ if (!adPlaying) return;
1627
+ if (data.fatal) {
1628
+ handleAdError();
1629
+ } else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
1630
+ nonFatalNetworkErrors++;
1631
+ if (nonFatalNetworkErrors >= 3) {
1632
+ if (debug) console.warn("".concat(LOG, " [preload] Too many non-fatal HLS network errors during playback, treating as fatal"));
1633
+ handleAdError();
1634
+ }
1635
+ }
1636
+ });
1637
+ }
1638
+ setupAdEventListeners();
1639
+ if (!continueLiveStreamDuringAds) {
1640
+ contentVideo.pause();
1641
+ }
1642
+ contentVideo.muted = true;
1643
+ contentVideo.volume = 0;
1644
+ adPlaying = true;
1645
+ setAdPlayingFlag(true);
1646
+ adVolume = originalMutedState ? 1 : originalVolume;
1647
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1648
+ adVideoElement.muted = false;
1649
+ container = ensureAdContainer();
1650
+ container.style.display = "flex";
1651
+ container.style.pointerEvents = "auto";
1652
+ emit("content_pause");
1653
+ adVideoElement.play().catch(function(error) {
1654
+ console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
1655
+ handleAdError();
1656
+ });
1657
+ return [
1658
+ 2
1659
+ ];
1574
1660
  }
1575
- contentVideo.muted = true;
1576
- contentVideo.volume = 0;
1577
- adPlaying = true;
1578
- setAdPlayingFlag(true);
1579
- adVolume = originalMutedState ? 1 : originalVolume;
1580
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1581
- adVideoElement.muted = false;
1582
- container = ensureAdContainer();
1583
- container.style.display = "flex";
1584
- container.style.pointerEvents = "auto";
1585
- emit("content_pause");
1586
- adVideoElement.play().catch(function(error) {
1587
- console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
1588
- handleAdError();
1589
- });
1590
- return [
1591
- 2
1592
- ];
1593
1661
  });
1594
1662
  })();
1595
1663
  }
@@ -3845,7 +3913,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3845
3913
  };
3846
3914
  this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
3847
3915
  }
3848
- if (!this.config.disableFiller && !this.video.muted) {
3916
+ if (!this.config.disableFiller && !this.video.muted && !this.adLayer.isAdPlaying()) {
3849
3917
  this.video.muted = true;
3850
3918
  this.video.volume = 0;
3851
3919
  if (this.config.debugAdTiming) {
@@ -5479,7 +5547,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5479
5547
  console.log("[StormcloudVideoPlayer] Smart TV: audio state restored on MANIFEST_PARSED after re-attach");
5480
5548
  }
5481
5549
  hlsRef.startLoad(-1);
5482
- tryPlay(0);
5483
5550
  if (debugEnabled) {
5484
5551
  console.log("[StormcloudVideoPlayer] Smart TV: seeking to live edge and resuming playback after re-attach");
5485
5552
  }