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.
@@ -47,6 +47,8 @@ declare class StormcloudVideoPlayer {
47
47
  private maxPlaceholderDurationMs;
48
48
  private placeholderStartTimeMs;
49
49
  private isShowingPlaceholder;
50
+ private timeUpdateHandler?;
51
+ private emptiedHandler?;
50
52
  constructor(config: StormcloudVideoPlayerConfig);
51
53
  private createAdPlayer;
52
54
  load(): Promise<void>;
@@ -925,6 +925,8 @@ function createHlsAdPlayer(contentVideo, options) {
925
925
  let sessionId;
926
926
  const preloadedAds = /* @__PURE__ */ new Map();
927
927
  const preloadingAds = /* @__PURE__ */ new Map();
928
+ let destroyed = false;
929
+ let pendingTimeouts = [];
928
930
  let trackingFired = {
929
931
  impression: false,
930
932
  start: false,
@@ -1253,7 +1255,11 @@ function createHlsAdPlayer(contentVideo, options) {
1253
1255
  adPlaying = false;
1254
1256
  setAdPlayingFlag(false);
1255
1257
  emit("content_resume");
1256
- setTimeout(() => {
1258
+ const timeoutId = window.setTimeout(() => {
1259
+ if (destroyed) {
1260
+ console.log("[HlsAdPlayer] Player destroyed, skipping post-completion check");
1261
+ return;
1262
+ }
1257
1263
  const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1258
1264
  if (stillInPod) {
1259
1265
  console.log(
@@ -1264,7 +1270,12 @@ function createHlsAdPlayer(contentVideo, options) {
1264
1270
  adContainerEl.style.pointerEvents = "auto";
1265
1271
  }
1266
1272
  }
1273
+ const idx = pendingTimeouts.indexOf(timeoutId);
1274
+ if (idx !== -1) {
1275
+ pendingTimeouts.splice(idx, 1);
1276
+ }
1267
1277
  }, 50);
1278
+ pendingTimeouts.push(timeoutId);
1268
1279
  }
1269
1280
  function handleAdError() {
1270
1281
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1494,6 +1505,11 @@ function createHlsAdPlayer(contentVideo, options) {
1494
1505
  },
1495
1506
  destroy() {
1496
1507
  console.log("[HlsAdPlayer] Destroying");
1508
+ destroyed = true;
1509
+ for (const timeoutId of pendingTimeouts) {
1510
+ clearTimeout(timeoutId);
1511
+ }
1512
+ pendingTimeouts = [];
1497
1513
  adPlaying = false;
1498
1514
  setAdPlayingFlag(false);
1499
1515
  contentVideo.muted = originalMutedState;
@@ -2406,10 +2422,11 @@ var StormcloudVideoPlayer = class {
2406
2422
  this.handleAdPodComplete();
2407
2423
  }
2408
2424
  });
2409
- this.video.addEventListener("timeupdate", () => {
2425
+ this.timeUpdateHandler = () => {
2410
2426
  this.onTimeUpdate(this.video.currentTime);
2411
- });
2412
- this.video.addEventListener("emptied", () => {
2427
+ };
2428
+ this.video.addEventListener("timeupdate", this.timeUpdateHandler);
2429
+ this.emptiedHandler = () => {
2413
2430
  if (this.nativeHlsMode && this.videoSrcProtection && !this.ima.isAdPlaying()) {
2414
2431
  if (this.config.debugAdTiming) {
2415
2432
  console.log(
@@ -2426,7 +2443,8 @@ var StormcloudVideoPlayer = class {
2426
2443
  });
2427
2444
  }
2428
2445
  }
2429
- });
2446
+ };
2447
+ this.video.addEventListener("emptied", this.emptiedHandler);
2430
2448
  }
2431
2449
  shouldUseNativeHls() {
2432
2450
  const streamType = this.getStreamType();
@@ -4062,6 +4080,15 @@ var StormcloudVideoPlayer = class {
4062
4080
  this.clearAdStartTimer();
4063
4081
  this.clearAdStopTimer();
4064
4082
  this.clearAdFailsafeTimer();
4083
+ this.clearAdRequestWatchdog();
4084
+ if (this.timeUpdateHandler) {
4085
+ this.video.removeEventListener("timeupdate", this.timeUpdateHandler);
4086
+ delete this.timeUpdateHandler;
4087
+ }
4088
+ if (this.emptiedHandler) {
4089
+ this.video.removeEventListener("emptied", this.emptiedHandler);
4090
+ delete this.emptiedHandler;
4091
+ }
4065
4092
  if (this.heartbeatInterval) {
4066
4093
  clearInterval(this.heartbeatInterval);
4067
4094
  this.heartbeatInterval = void 0;