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.
@@ -1029,6 +1029,7 @@ function createVastAdLayer(contentVideo, options) {
1029
1029
  var destroyed = false;
1030
1030
  var tornDown = false;
1031
1031
  var trackingFired = createEmptyTrackingState();
1032
+ var adStallTimerId;
1032
1033
  var currentAdEventHandlers;
1033
1034
  var preloadSlots = /* @__PURE__ */ new Map();
1034
1035
  function emit(event, payload) {
@@ -1102,6 +1103,14 @@ function createVastAdLayer(contentVideo, options) {
1102
1103
  } else if (debug) {
1103
1104
  console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
1104
1105
  }
1106
+ } else {
1107
+ var mp4Only1 = candidates.filter(function(f) {
1108
+ return !isHlsMediaFile(f);
1109
+ });
1110
+ if (mp4Only1.length > 0) {
1111
+ candidates = mp4Only1;
1112
+ if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
1113
+ }
1105
1114
  }
1106
1115
  var firstFile = candidates[0];
1107
1116
  if (candidates.length === 1) return firstFile;
@@ -1144,7 +1153,14 @@ function createVastAdLayer(contentVideo, options) {
1144
1153
  video.volume = 1;
1145
1154
  return video;
1146
1155
  }
1156
+ function clearAdStallTimer() {
1157
+ if (adStallTimerId != null) {
1158
+ clearTimeout(adStallTimerId);
1159
+ adStallTimerId = void 0;
1160
+ }
1161
+ }
1147
1162
  function removeAdEventListeners() {
1163
+ clearAdStallTimer();
1148
1164
  if (!currentAdEventHandlers || !adVideoElement) return;
1149
1165
  var el = adVideoElement;
1150
1166
  el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
@@ -1154,6 +1170,7 @@ function createVastAdLayer(contentVideo, options) {
1154
1170
  el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
1155
1171
  el.removeEventListener("pause", currentAdEventHandlers.pause);
1156
1172
  el.removeEventListener("play", currentAdEventHandlers.play);
1173
+ el.removeEventListener("waiting", currentAdEventHandlers.waiting);
1157
1174
  currentAdEventHandlers = void 0;
1158
1175
  }
1159
1176
  function setupAdEventListeners() {
@@ -1178,6 +1195,7 @@ function createVastAdLayer(contentVideo, options) {
1178
1195
  }
1179
1196
  },
1180
1197
  playing: function playing() {
1198
+ clearAdStallTimer();
1181
1199
  var ad = currentAd;
1182
1200
  if (!ad || trackingFired.start) return;
1183
1201
  trackingFired.start = true;
@@ -1214,6 +1232,16 @@ function createVastAdLayer(contentVideo, options) {
1214
1232
  if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
1215
1233
  fireTrackingPixels2(currentAd.trackingUrls.resume);
1216
1234
  }
1235
+ },
1236
+ waiting: function waiting() {
1237
+ clearAdStallTimer();
1238
+ adStallTimerId = setTimeout(function() {
1239
+ adStallTimerId = void 0;
1240
+ if (adPlaying) {
1241
+ if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
1242
+ handleAdError();
1243
+ }
1244
+ }, 8e3);
1217
1245
  }
1218
1246
  };
1219
1247
  adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
@@ -1223,6 +1251,7 @@ function createVastAdLayer(contentVideo, options) {
1223
1251
  adVideoElement.addEventListener("volumechange", handlers.volumechange);
1224
1252
  adVideoElement.addEventListener("pause", handlers.pause);
1225
1253
  adVideoElement.addEventListener("play", handlers.play);
1254
+ adVideoElement.addEventListener("waiting", handlers.waiting);
1226
1255
  currentAdEventHandlers = handlers;
1227
1256
  }
1228
1257
  function setAdPlayingFlag(isPlaying) {
@@ -1234,6 +1263,7 @@ function createVastAdLayer(contentVideo, options) {
1234
1263
  }
1235
1264
  function handleAdComplete() {
1236
1265
  if (tornDown) return;
1266
+ clearAdStallTimer();
1237
1267
  if (debug) console.log("".concat(LOG, " Handling ad completion"));
1238
1268
  adPlaying = false;
1239
1269
  setAdPlayingFlag(false);
@@ -1247,6 +1277,7 @@ function createVastAdLayer(contentVideo, options) {
1247
1277
  function handleAdError() {
1248
1278
  if (tornDown) return;
1249
1279
  if (!adPlaying) return;
1280
+ clearAdStallTimer();
1250
1281
  if (debug) console.log("".concat(LOG, " Handling ad error"));
1251
1282
  adPlaying = false;
1252
1283
  setAdPlayingFlag(false);
@@ -1297,6 +1328,7 @@ function createVastAdLayer(contentVideo, options) {
1297
1328
  adHls.loadSource(mediaFile.url);
1298
1329
  adHls.attachMedia(adVideoElement);
1299
1330
  adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
1331
+ if (!adPlaying) return;
1300
1332
  adVideoElement.play().catch(function(error) {
1301
1333
  console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
1302
1334
  handleAdError();
@@ -1930,6 +1962,7 @@ function createVastAdLayer(contentVideo, options) {
1930
1962
  return 1;
1931
1963
  },
1932
1964
  showPlaceholder: function showPlaceholder() {
1965
+ if (singleElementMode) return;
1933
1966
  contentVideo.style.opacity = "0";
1934
1967
  contentVideo.style.visibility = "hidden";
1935
1968
  if (!adContainerEl) {
@@ -3626,7 +3659,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3626
3659
  }
3627
3660
  _this.adLayer.cancelPreload(token);
3628
3661
  } else {
3629
- _this.showPlaceholderLayer();
3662
+ if (!_this.config.singlePipelineMode) {
3663
+ _this.showPlaceholderLayer();
3664
+ }
3630
3665
  _this.adLayer.showPlaceholder();
3631
3666
  _this.isInAdTransition = true;
3632
3667
  setTimeout(function() {
@@ -3650,7 +3685,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3650
3685
  console.log("[StormcloudVideoPlayer] content_resume: skip pending bids, only", remainingNow1, "ms left");
3651
3686
  }
3652
3687
  } else {
3653
- _this.showPlaceholderLayer();
3688
+ if (!_this.config.singlePipelineMode) {
3689
+ _this.showPlaceholderLayer();
3690
+ }
3654
3691
  _this.adLayer.showPlaceholder();
3655
3692
  _this.isInAdTransition = true;
3656
3693
  setTimeout(function() {
@@ -4009,12 +4046,17 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4009
4046
  }
4010
4047
  }
4011
4048
  if (this.inAdBreak) {
4012
- if (this.expectedAdBreakDurationMs == null && marker.durationSeconds != null) {
4013
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4014
- if (this.config.debugAdTiming) {
4015
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(this.expectedAdBreakDurationMs, "ms"));
4049
+ if (marker.durationSeconds != null) {
4050
+ var newDurationMs = marker.durationSeconds * 1e3;
4051
+ if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4052
+ this.expectedAdBreakDurationMs = newDurationMs;
4053
+ var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4054
+ var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4055
+ this.scheduleAdStopCountdown(remainingMs);
4056
+ if (this.config.debugAdTiming) {
4057
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4058
+ }
4016
4059
  }
4017
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4018
4060
  }
4019
4061
  return;
4020
4062
  }
@@ -4095,9 +4137,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4095
4137
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4096
4138
  }
4097
4139
  if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4098
- var elapsedMs = Date.now() - this.currentAdBreakStartWallClockMs;
4099
- var remainingMs = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs);
4100
- this.scheduleAdStopCountdown(remainingMs);
4140
+ var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4141
+ var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4142
+ this.scheduleAdStopCountdown(remainingMs1);
4101
4143
  }
4102
4144
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4103
4145
  var bids = this.pendingNextAdBids;
@@ -5018,7 +5060,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5018
5060
  if (!this.config.disableFiller) this.showAds = true;
5019
5061
  if (adBreakDurationMs != null) {
5020
5062
  this.startFillerBreakTimer(adBreakDurationMs);
5021
- } else if (!this.config.disableFiller) {
5063
+ } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
5022
5064
  this.showPlaceholderLayer();
5023
5065
  }
5024
5066
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();