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.d.cts CHANGED
@@ -148,6 +148,8 @@ declare class StormcloudVideoPlayer {
148
148
  private maxPlaceholderDurationMs;
149
149
  private placeholderStartTimeMs;
150
150
  private isShowingPlaceholder;
151
+ private timeUpdateHandler?;
152
+ private emptiedHandler?;
151
153
  constructor(config: StormcloudVideoPlayerConfig);
152
154
  private createAdPlayer;
153
155
  load(): Promise<void>;
package/lib/index.d.ts CHANGED
@@ -148,6 +148,8 @@ declare class StormcloudVideoPlayer {
148
148
  private maxPlaceholderDurationMs;
149
149
  private placeholderStartTimeMs;
150
150
  private isShowingPlaceholder;
151
+ private timeUpdateHandler?;
152
+ private emptiedHandler?;
151
153
  constructor(config: StormcloudVideoPlayerConfig);
152
154
  private createAdPlayer;
153
155
  load(): Promise<void>;
package/lib/index.js CHANGED
@@ -920,6 +920,8 @@ function createHlsAdPlayer(contentVideo, options) {
920
920
  let sessionId;
921
921
  const preloadedAds = /* @__PURE__ */ new Map();
922
922
  const preloadingAds = /* @__PURE__ */ new Map();
923
+ let destroyed = false;
924
+ let pendingTimeouts = [];
923
925
  let trackingFired = {
924
926
  impression: false,
925
927
  start: false,
@@ -1248,7 +1250,11 @@ function createHlsAdPlayer(contentVideo, options) {
1248
1250
  adPlaying = false;
1249
1251
  setAdPlayingFlag(false);
1250
1252
  emit("content_resume");
1251
- setTimeout(() => {
1253
+ const timeoutId = window.setTimeout(() => {
1254
+ if (destroyed) {
1255
+ console.log("[HlsAdPlayer] Player destroyed, skipping post-completion check");
1256
+ return;
1257
+ }
1252
1258
  const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1253
1259
  if (stillInPod) {
1254
1260
  console.log(
@@ -1259,7 +1265,12 @@ function createHlsAdPlayer(contentVideo, options) {
1259
1265
  adContainerEl.style.pointerEvents = "auto";
1260
1266
  }
1261
1267
  }
1268
+ const idx = pendingTimeouts.indexOf(timeoutId);
1269
+ if (idx !== -1) {
1270
+ pendingTimeouts.splice(idx, 1);
1271
+ }
1262
1272
  }, 50);
1273
+ pendingTimeouts.push(timeoutId);
1263
1274
  }
1264
1275
  function handleAdError() {
1265
1276
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1489,6 +1500,11 @@ function createHlsAdPlayer(contentVideo, options) {
1489
1500
  },
1490
1501
  destroy() {
1491
1502
  console.log("[HlsAdPlayer] Destroying");
1503
+ destroyed = true;
1504
+ for (const timeoutId of pendingTimeouts) {
1505
+ clearTimeout(timeoutId);
1506
+ }
1507
+ pendingTimeouts = [];
1492
1508
  adPlaying = false;
1493
1509
  setAdPlayingFlag(false);
1494
1510
  contentVideo.muted = originalMutedState;
@@ -2401,10 +2417,11 @@ var StormcloudVideoPlayer = class {
2401
2417
  this.handleAdPodComplete();
2402
2418
  }
2403
2419
  });
2404
- this.video.addEventListener("timeupdate", () => {
2420
+ this.timeUpdateHandler = () => {
2405
2421
  this.onTimeUpdate(this.video.currentTime);
2406
- });
2407
- this.video.addEventListener("emptied", () => {
2422
+ };
2423
+ this.video.addEventListener("timeupdate", this.timeUpdateHandler);
2424
+ this.emptiedHandler = () => {
2408
2425
  if (this.nativeHlsMode && this.videoSrcProtection && !this.ima.isAdPlaying()) {
2409
2426
  if (this.config.debugAdTiming) {
2410
2427
  console.log(
@@ -2421,7 +2438,8 @@ var StormcloudVideoPlayer = class {
2421
2438
  });
2422
2439
  }
2423
2440
  }
2424
- });
2441
+ };
2442
+ this.video.addEventListener("emptied", this.emptiedHandler);
2425
2443
  }
2426
2444
  shouldUseNativeHls() {
2427
2445
  const streamType = this.getStreamType();
@@ -4057,6 +4075,15 @@ var StormcloudVideoPlayer = class {
4057
4075
  this.clearAdStartTimer();
4058
4076
  this.clearAdStopTimer();
4059
4077
  this.clearAdFailsafeTimer();
4078
+ this.clearAdRequestWatchdog();
4079
+ if (this.timeUpdateHandler) {
4080
+ this.video.removeEventListener("timeupdate", this.timeUpdateHandler);
4081
+ delete this.timeUpdateHandler;
4082
+ }
4083
+ if (this.emptiedHandler) {
4084
+ this.video.removeEventListener("emptied", this.emptiedHandler);
4085
+ delete this.emptiedHandler;
4086
+ }
4060
4087
  if (this.heartbeatInterval) {
4061
4088
  clearInterval(this.heartbeatInterval);
4062
4089
  this.heartbeatInterval = void 0;