stormcloud-video-player 0.3.12 → 0.3.14

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.
package/lib/index.cjs CHANGED
@@ -989,6 +989,8 @@ function createHlsAdPlayer(contentVideo, options) {
989
989
  let sessionId;
990
990
  const preloadedAds = /* @__PURE__ */ new Map();
991
991
  const preloadingAds = /* @__PURE__ */ new Map();
992
+ let destroyed = false;
993
+ let pendingTimeouts = [];
992
994
  let trackingFired = {
993
995
  impression: false,
994
996
  start: false,
@@ -1317,7 +1319,11 @@ function createHlsAdPlayer(contentVideo, options) {
1317
1319
  adPlaying = false;
1318
1320
  setAdPlayingFlag(false);
1319
1321
  emit("content_resume");
1320
- setTimeout(() => {
1322
+ const timeoutId = window.setTimeout(() => {
1323
+ if (destroyed) {
1324
+ console.log("[HlsAdPlayer] Player destroyed, skipping post-completion check");
1325
+ return;
1326
+ }
1321
1327
  const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1322
1328
  if (stillInPod) {
1323
1329
  console.log(
@@ -1328,7 +1334,12 @@ function createHlsAdPlayer(contentVideo, options) {
1328
1334
  adContainerEl.style.pointerEvents = "auto";
1329
1335
  }
1330
1336
  }
1337
+ const idx = pendingTimeouts.indexOf(timeoutId);
1338
+ if (idx !== -1) {
1339
+ pendingTimeouts.splice(idx, 1);
1340
+ }
1331
1341
  }, 50);
1342
+ pendingTimeouts.push(timeoutId);
1332
1343
  }
1333
1344
  function handleAdError() {
1334
1345
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1558,6 +1569,11 @@ function createHlsAdPlayer(contentVideo, options) {
1558
1569
  },
1559
1570
  destroy() {
1560
1571
  console.log("[HlsAdPlayer] Destroying");
1572
+ destroyed = true;
1573
+ for (const timeoutId of pendingTimeouts) {
1574
+ clearTimeout(timeoutId);
1575
+ }
1576
+ pendingTimeouts = [];
1561
1577
  adPlaying = false;
1562
1578
  setAdPlayingFlag(false);
1563
1579
  contentVideo.muted = originalMutedState;
@@ -2470,10 +2486,11 @@ var StormcloudVideoPlayer = class {
2470
2486
  this.handleAdPodComplete();
2471
2487
  }
2472
2488
  });
2473
- this.video.addEventListener("timeupdate", () => {
2489
+ this.timeUpdateHandler = () => {
2474
2490
  this.onTimeUpdate(this.video.currentTime);
2475
- });
2476
- this.video.addEventListener("emptied", () => {
2491
+ };
2492
+ this.video.addEventListener("timeupdate", this.timeUpdateHandler);
2493
+ this.emptiedHandler = () => {
2477
2494
  if (this.nativeHlsMode && this.videoSrcProtection && !this.ima.isAdPlaying()) {
2478
2495
  if (this.config.debugAdTiming) {
2479
2496
  console.log(
@@ -2490,7 +2507,8 @@ var StormcloudVideoPlayer = class {
2490
2507
  });
2491
2508
  }
2492
2509
  }
2493
- });
2510
+ };
2511
+ this.video.addEventListener("emptied", this.emptiedHandler);
2494
2512
  }
2495
2513
  shouldUseNativeHls() {
2496
2514
  const streamType = this.getStreamType();
@@ -4126,6 +4144,15 @@ var StormcloudVideoPlayer = class {
4126
4144
  this.clearAdStartTimer();
4127
4145
  this.clearAdStopTimer();
4128
4146
  this.clearAdFailsafeTimer();
4147
+ this.clearAdRequestWatchdog();
4148
+ if (this.timeUpdateHandler) {
4149
+ this.video.removeEventListener("timeupdate", this.timeUpdateHandler);
4150
+ delete this.timeUpdateHandler;
4151
+ }
4152
+ if (this.emptiedHandler) {
4153
+ this.video.removeEventListener("emptied", this.emptiedHandler);
4154
+ delete this.emptiedHandler;
4155
+ }
4129
4156
  if (this.heartbeatInterval) {
4130
4157
  clearInterval(this.heartbeatInterval);
4131
4158
  this.heartbeatInterval = void 0;