stormcloud-video-player 0.6.3 → 0.6.5

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.
@@ -979,6 +979,7 @@ function createVastAdLayer(contentVideo, options) {
979
979
  var destroyed = false;
980
980
  var tornDown = false;
981
981
  var trackingFired = createEmptyTrackingState();
982
+ var adStallTimerId;
982
983
  var currentAdEventHandlers;
983
984
  var preloadSlots = /* @__PURE__ */ new Map();
984
985
  function emit(event, payload) {
@@ -1052,6 +1053,14 @@ function createVastAdLayer(contentVideo, options) {
1052
1053
  } else if (debug) {
1053
1054
  console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
1054
1055
  }
1056
+ } else {
1057
+ var mp4Only1 = candidates.filter(function(f) {
1058
+ return !isHlsMediaFile(f);
1059
+ });
1060
+ if (mp4Only1.length > 0) {
1061
+ candidates = mp4Only1;
1062
+ if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
1063
+ }
1055
1064
  }
1056
1065
  var firstFile = candidates[0];
1057
1066
  if (candidates.length === 1) return firstFile;
@@ -1094,7 +1103,14 @@ function createVastAdLayer(contentVideo, options) {
1094
1103
  video.volume = 1;
1095
1104
  return video;
1096
1105
  }
1106
+ function clearAdStallTimer() {
1107
+ if (adStallTimerId != null) {
1108
+ clearTimeout(adStallTimerId);
1109
+ adStallTimerId = void 0;
1110
+ }
1111
+ }
1097
1112
  function removeAdEventListeners() {
1113
+ clearAdStallTimer();
1098
1114
  if (!currentAdEventHandlers || !adVideoElement) return;
1099
1115
  var el = adVideoElement;
1100
1116
  el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
@@ -1104,6 +1120,7 @@ function createVastAdLayer(contentVideo, options) {
1104
1120
  el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
1105
1121
  el.removeEventListener("pause", currentAdEventHandlers.pause);
1106
1122
  el.removeEventListener("play", currentAdEventHandlers.play);
1123
+ el.removeEventListener("waiting", currentAdEventHandlers.waiting);
1107
1124
  currentAdEventHandlers = void 0;
1108
1125
  }
1109
1126
  function setupAdEventListeners() {
@@ -1128,6 +1145,7 @@ function createVastAdLayer(contentVideo, options) {
1128
1145
  }
1129
1146
  },
1130
1147
  playing: function playing() {
1148
+ clearAdStallTimer();
1131
1149
  var ad = currentAd;
1132
1150
  if (!ad || trackingFired.start) return;
1133
1151
  trackingFired.start = true;
@@ -1164,6 +1182,16 @@ function createVastAdLayer(contentVideo, options) {
1164
1182
  if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
1165
1183
  fireTrackingPixels2(currentAd.trackingUrls.resume);
1166
1184
  }
1185
+ },
1186
+ waiting: function waiting() {
1187
+ clearAdStallTimer();
1188
+ adStallTimerId = setTimeout(function() {
1189
+ adStallTimerId = void 0;
1190
+ if (adPlaying) {
1191
+ if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
1192
+ handleAdError();
1193
+ }
1194
+ }, 8e3);
1167
1195
  }
1168
1196
  };
1169
1197
  adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
@@ -1173,6 +1201,7 @@ function createVastAdLayer(contentVideo, options) {
1173
1201
  adVideoElement.addEventListener("volumechange", handlers.volumechange);
1174
1202
  adVideoElement.addEventListener("pause", handlers.pause);
1175
1203
  adVideoElement.addEventListener("play", handlers.play);
1204
+ adVideoElement.addEventListener("waiting", handlers.waiting);
1176
1205
  currentAdEventHandlers = handlers;
1177
1206
  }
1178
1207
  function setAdPlayingFlag(isPlaying) {
@@ -1184,6 +1213,7 @@ function createVastAdLayer(contentVideo, options) {
1184
1213
  }
1185
1214
  function handleAdComplete() {
1186
1215
  if (tornDown) return;
1216
+ clearAdStallTimer();
1187
1217
  if (debug) console.log("".concat(LOG, " Handling ad completion"));
1188
1218
  adPlaying = false;
1189
1219
  setAdPlayingFlag(false);
@@ -1197,6 +1227,7 @@ function createVastAdLayer(contentVideo, options) {
1197
1227
  function handleAdError() {
1198
1228
  if (tornDown) return;
1199
1229
  if (!adPlaying) return;
1230
+ clearAdStallTimer();
1200
1231
  if (debug) console.log("".concat(LOG, " Handling ad error"));
1201
1232
  adPlaying = false;
1202
1233
  setAdPlayingFlag(false);
@@ -1247,6 +1278,7 @@ function createVastAdLayer(contentVideo, options) {
1247
1278
  adHls.loadSource(mediaFile.url);
1248
1279
  adHls.attachMedia(adVideoElement);
1249
1280
  adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
1281
+ if (!adPlaying) return;
1250
1282
  adVideoElement.play().catch(function(error) {
1251
1283
  console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
1252
1284
  handleAdError();
@@ -1880,6 +1912,7 @@ function createVastAdLayer(contentVideo, options) {
1880
1912
  return 1;
1881
1913
  },
1882
1914
  showPlaceholder: function showPlaceholder() {
1915
+ if (singleElementMode) return;
1883
1916
  contentVideo.style.opacity = "0";
1884
1917
  contentVideo.style.visibility = "hidden";
1885
1918
  if (!adContainerEl) {
@@ -3576,7 +3609,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3576
3609
  }
3577
3610
  _this.adLayer.cancelPreload(token);
3578
3611
  } else {
3579
- _this.showPlaceholderLayer();
3612
+ if (!_this.config.singlePipelineMode) {
3613
+ _this.showPlaceholderLayer();
3614
+ }
3580
3615
  _this.adLayer.showPlaceholder();
3581
3616
  _this.isInAdTransition = true;
3582
3617
  setTimeout(function() {
@@ -3600,7 +3635,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3600
3635
  console.log("[StormcloudVideoPlayer] content_resume: skip pending bids, only", remainingNow1, "ms left");
3601
3636
  }
3602
3637
  } else {
3603
- _this.showPlaceholderLayer();
3638
+ if (!_this.config.singlePipelineMode) {
3639
+ _this.showPlaceholderLayer();
3640
+ }
3604
3641
  _this.adLayer.showPlaceholder();
3605
3642
  _this.isInAdTransition = true;
3606
3643
  setTimeout(function() {
@@ -3959,12 +3996,17 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3959
3996
  }
3960
3997
  }
3961
3998
  if (this.inAdBreak) {
3962
- if (this.expectedAdBreakDurationMs == null && marker.durationSeconds != null) {
3963
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
3964
- if (this.config.debugAdTiming) {
3965
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(this.expectedAdBreakDurationMs, "ms"));
3999
+ if (marker.durationSeconds != null) {
4000
+ var newDurationMs = marker.durationSeconds * 1e3;
4001
+ if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4002
+ this.expectedAdBreakDurationMs = newDurationMs;
4003
+ var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4004
+ var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4005
+ this.scheduleAdStopCountdown(remainingMs);
4006
+ if (this.config.debugAdTiming) {
4007
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4008
+ }
3966
4009
  }
3967
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
3968
4010
  }
3969
4011
  return;
3970
4012
  }
@@ -4045,9 +4087,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4045
4087
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4046
4088
  }
4047
4089
  if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4048
- var elapsedMs = Date.now() - this.currentAdBreakStartWallClockMs;
4049
- var remainingMs = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs);
4050
- this.scheduleAdStopCountdown(remainingMs);
4090
+ var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4091
+ var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4092
+ this.scheduleAdStopCountdown(remainingMs1);
4051
4093
  }
4052
4094
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4053
4095
  var bids = this.pendingNextAdBids;
@@ -4968,7 +5010,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4968
5010
  if (!this.config.disableFiller) this.showAds = true;
4969
5011
  if (adBreakDurationMs != null) {
4970
5012
  this.startFillerBreakTimer(adBreakDurationMs);
4971
- } else if (!this.config.disableFiller) {
5013
+ } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
4972
5014
  this.showPlaceholderLayer();
4973
5015
  }
4974
5016
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();