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.
package/lib/index.cjs CHANGED
@@ -1123,6 +1123,7 @@ function createVastAdLayer(contentVideo, options) {
1123
1123
  var destroyed = false;
1124
1124
  var tornDown = false;
1125
1125
  var trackingFired = createEmptyTrackingState();
1126
+ var adStallTimerId;
1126
1127
  var currentAdEventHandlers;
1127
1128
  var preloadSlots = /* @__PURE__ */ new Map();
1128
1129
  function emit(event, payload) {
@@ -1196,6 +1197,14 @@ function createVastAdLayer(contentVideo, options) {
1196
1197
  } else if (debug) {
1197
1198
  console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
1198
1199
  }
1200
+ } else {
1201
+ var mp4Only1 = candidates.filter(function(f) {
1202
+ return !isHlsMediaFile(f);
1203
+ });
1204
+ if (mp4Only1.length > 0) {
1205
+ candidates = mp4Only1;
1206
+ if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
1207
+ }
1199
1208
  }
1200
1209
  var firstFile = candidates[0];
1201
1210
  if (candidates.length === 1) return firstFile;
@@ -1238,7 +1247,14 @@ function createVastAdLayer(contentVideo, options) {
1238
1247
  video.volume = 1;
1239
1248
  return video;
1240
1249
  }
1250
+ function clearAdStallTimer() {
1251
+ if (adStallTimerId != null) {
1252
+ clearTimeout(adStallTimerId);
1253
+ adStallTimerId = void 0;
1254
+ }
1255
+ }
1241
1256
  function removeAdEventListeners() {
1257
+ clearAdStallTimer();
1242
1258
  if (!currentAdEventHandlers || !adVideoElement) return;
1243
1259
  var el = adVideoElement;
1244
1260
  el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
@@ -1248,6 +1264,7 @@ function createVastAdLayer(contentVideo, options) {
1248
1264
  el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
1249
1265
  el.removeEventListener("pause", currentAdEventHandlers.pause);
1250
1266
  el.removeEventListener("play", currentAdEventHandlers.play);
1267
+ el.removeEventListener("waiting", currentAdEventHandlers.waiting);
1251
1268
  currentAdEventHandlers = void 0;
1252
1269
  }
1253
1270
  function setupAdEventListeners() {
@@ -1272,6 +1289,7 @@ function createVastAdLayer(contentVideo, options) {
1272
1289
  }
1273
1290
  },
1274
1291
  playing: function playing() {
1292
+ clearAdStallTimer();
1275
1293
  var ad = currentAd;
1276
1294
  if (!ad || trackingFired.start) return;
1277
1295
  trackingFired.start = true;
@@ -1308,6 +1326,16 @@ function createVastAdLayer(contentVideo, options) {
1308
1326
  if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
1309
1327
  fireTrackingPixels2(currentAd.trackingUrls.resume);
1310
1328
  }
1329
+ },
1330
+ waiting: function waiting() {
1331
+ clearAdStallTimer();
1332
+ adStallTimerId = setTimeout(function() {
1333
+ adStallTimerId = void 0;
1334
+ if (adPlaying) {
1335
+ if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
1336
+ handleAdError();
1337
+ }
1338
+ }, 8e3);
1311
1339
  }
1312
1340
  };
1313
1341
  adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
@@ -1317,6 +1345,7 @@ function createVastAdLayer(contentVideo, options) {
1317
1345
  adVideoElement.addEventListener("volumechange", handlers.volumechange);
1318
1346
  adVideoElement.addEventListener("pause", handlers.pause);
1319
1347
  adVideoElement.addEventListener("play", handlers.play);
1348
+ adVideoElement.addEventListener("waiting", handlers.waiting);
1320
1349
  currentAdEventHandlers = handlers;
1321
1350
  }
1322
1351
  function setAdPlayingFlag(isPlaying) {
@@ -1328,6 +1357,7 @@ function createVastAdLayer(contentVideo, options) {
1328
1357
  }
1329
1358
  function handleAdComplete() {
1330
1359
  if (tornDown) return;
1360
+ clearAdStallTimer();
1331
1361
  if (debug) console.log("".concat(LOG, " Handling ad completion"));
1332
1362
  adPlaying = false;
1333
1363
  setAdPlayingFlag(false);
@@ -1341,6 +1371,7 @@ function createVastAdLayer(contentVideo, options) {
1341
1371
  function handleAdError() {
1342
1372
  if (tornDown) return;
1343
1373
  if (!adPlaying) return;
1374
+ clearAdStallTimer();
1344
1375
  if (debug) console.log("".concat(LOG, " Handling ad error"));
1345
1376
  adPlaying = false;
1346
1377
  setAdPlayingFlag(false);
@@ -1391,6 +1422,7 @@ function createVastAdLayer(contentVideo, options) {
1391
1422
  adHls.loadSource(mediaFile.url);
1392
1423
  adHls.attachMedia(adVideoElement);
1393
1424
  adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
1425
+ if (!adPlaying) return;
1394
1426
  adVideoElement.play().catch(function(error) {
1395
1427
  console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
1396
1428
  handleAdError();
@@ -2024,6 +2056,7 @@ function createVastAdLayer(contentVideo, options) {
2024
2056
  return 1;
2025
2057
  },
2026
2058
  showPlaceholder: function showPlaceholder() {
2059
+ if (singleElementMode) return;
2027
2060
  contentVideo.style.opacity = "0";
2028
2061
  contentVideo.style.visibility = "hidden";
2029
2062
  if (!adContainerEl) {
@@ -3745,7 +3778,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3745
3778
  }
3746
3779
  _this.adLayer.cancelPreload(token);
3747
3780
  } else {
3748
- _this.showPlaceholderLayer();
3781
+ if (!_this.config.singlePipelineMode) {
3782
+ _this.showPlaceholderLayer();
3783
+ }
3749
3784
  _this.adLayer.showPlaceholder();
3750
3785
  _this.isInAdTransition = true;
3751
3786
  setTimeout(function() {
@@ -3769,7 +3804,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3769
3804
  console.log("[StormcloudVideoPlayer] content_resume: skip pending bids, only", remainingNow1, "ms left");
3770
3805
  }
3771
3806
  } else {
3772
- _this.showPlaceholderLayer();
3807
+ if (!_this.config.singlePipelineMode) {
3808
+ _this.showPlaceholderLayer();
3809
+ }
3773
3810
  _this.adLayer.showPlaceholder();
3774
3811
  _this.isInAdTransition = true;
3775
3812
  setTimeout(function() {
@@ -4128,12 +4165,17 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4128
4165
  }
4129
4166
  }
4130
4167
  if (this.inAdBreak) {
4131
- if (this.expectedAdBreakDurationMs == null && marker.durationSeconds != null) {
4132
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4133
- if (this.config.debugAdTiming) {
4134
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(this.expectedAdBreakDurationMs, "ms"));
4168
+ if (marker.durationSeconds != null) {
4169
+ var newDurationMs = marker.durationSeconds * 1e3;
4170
+ if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4171
+ this.expectedAdBreakDurationMs = newDurationMs;
4172
+ var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4173
+ var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4174
+ this.scheduleAdStopCountdown(remainingMs);
4175
+ if (this.config.debugAdTiming) {
4176
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4177
+ }
4135
4178
  }
4136
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4137
4179
  }
4138
4180
  return;
4139
4181
  }
@@ -4214,9 +4256,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4214
4256
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4215
4257
  }
4216
4258
  if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4217
- var elapsedMs = Date.now() - this.currentAdBreakStartWallClockMs;
4218
- var remainingMs = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs);
4219
- this.scheduleAdStopCountdown(remainingMs);
4259
+ var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4260
+ var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4261
+ this.scheduleAdStopCountdown(remainingMs1);
4220
4262
  }
4221
4263
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4222
4264
  var bids = this.pendingNextAdBids;
@@ -5137,7 +5179,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5137
5179
  if (!this.config.disableFiller) this.showAds = true;
5138
5180
  if (adBreakDurationMs != null) {
5139
5181
  this.startFillerBreakTimer(adBreakDurationMs);
5140
- } else if (!this.config.disableFiller) {
5182
+ } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
5141
5183
  this.showPlaceholderLayer();
5142
5184
  }
5143
5185
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();