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.js CHANGED
@@ -963,6 +963,7 @@ function createVastAdLayer(contentVideo, options) {
963
963
  var destroyed = false;
964
964
  var tornDown = false;
965
965
  var trackingFired = createEmptyTrackingState();
966
+ var adStallTimerId;
966
967
  var currentAdEventHandlers;
967
968
  var preloadSlots = /* @__PURE__ */ new Map();
968
969
  function emit(event, payload) {
@@ -1036,6 +1037,14 @@ function createVastAdLayer(contentVideo, options) {
1036
1037
  } else if (debug) {
1037
1038
  console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
1038
1039
  }
1040
+ } else {
1041
+ var mp4Only1 = candidates.filter(function(f) {
1042
+ return !isHlsMediaFile(f);
1043
+ });
1044
+ if (mp4Only1.length > 0) {
1045
+ candidates = mp4Only1;
1046
+ if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
1047
+ }
1039
1048
  }
1040
1049
  var firstFile = candidates[0];
1041
1050
  if (candidates.length === 1) return firstFile;
@@ -1078,7 +1087,14 @@ function createVastAdLayer(contentVideo, options) {
1078
1087
  video.volume = 1;
1079
1088
  return video;
1080
1089
  }
1090
+ function clearAdStallTimer() {
1091
+ if (adStallTimerId != null) {
1092
+ clearTimeout(adStallTimerId);
1093
+ adStallTimerId = void 0;
1094
+ }
1095
+ }
1081
1096
  function removeAdEventListeners() {
1097
+ clearAdStallTimer();
1082
1098
  if (!currentAdEventHandlers || !adVideoElement) return;
1083
1099
  var el = adVideoElement;
1084
1100
  el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
@@ -1088,6 +1104,7 @@ function createVastAdLayer(contentVideo, options) {
1088
1104
  el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
1089
1105
  el.removeEventListener("pause", currentAdEventHandlers.pause);
1090
1106
  el.removeEventListener("play", currentAdEventHandlers.play);
1107
+ el.removeEventListener("waiting", currentAdEventHandlers.waiting);
1091
1108
  currentAdEventHandlers = void 0;
1092
1109
  }
1093
1110
  function setupAdEventListeners() {
@@ -1112,6 +1129,7 @@ function createVastAdLayer(contentVideo, options) {
1112
1129
  }
1113
1130
  },
1114
1131
  playing: function playing() {
1132
+ clearAdStallTimer();
1115
1133
  var ad = currentAd;
1116
1134
  if (!ad || trackingFired.start) return;
1117
1135
  trackingFired.start = true;
@@ -1148,6 +1166,16 @@ function createVastAdLayer(contentVideo, options) {
1148
1166
  if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
1149
1167
  fireTrackingPixels2(currentAd.trackingUrls.resume);
1150
1168
  }
1169
+ },
1170
+ waiting: function waiting() {
1171
+ clearAdStallTimer();
1172
+ adStallTimerId = setTimeout(function() {
1173
+ adStallTimerId = void 0;
1174
+ if (adPlaying) {
1175
+ if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
1176
+ handleAdError();
1177
+ }
1178
+ }, 8e3);
1151
1179
  }
1152
1180
  };
1153
1181
  adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
@@ -1157,6 +1185,7 @@ function createVastAdLayer(contentVideo, options) {
1157
1185
  adVideoElement.addEventListener("volumechange", handlers.volumechange);
1158
1186
  adVideoElement.addEventListener("pause", handlers.pause);
1159
1187
  adVideoElement.addEventListener("play", handlers.play);
1188
+ adVideoElement.addEventListener("waiting", handlers.waiting);
1160
1189
  currentAdEventHandlers = handlers;
1161
1190
  }
1162
1191
  function setAdPlayingFlag(isPlaying) {
@@ -1168,6 +1197,7 @@ function createVastAdLayer(contentVideo, options) {
1168
1197
  }
1169
1198
  function handleAdComplete() {
1170
1199
  if (tornDown) return;
1200
+ clearAdStallTimer();
1171
1201
  if (debug) console.log("".concat(LOG, " Handling ad completion"));
1172
1202
  adPlaying = false;
1173
1203
  setAdPlayingFlag(false);
@@ -1181,6 +1211,7 @@ function createVastAdLayer(contentVideo, options) {
1181
1211
  function handleAdError() {
1182
1212
  if (tornDown) return;
1183
1213
  if (!adPlaying) return;
1214
+ clearAdStallTimer();
1184
1215
  if (debug) console.log("".concat(LOG, " Handling ad error"));
1185
1216
  adPlaying = false;
1186
1217
  setAdPlayingFlag(false);
@@ -1231,6 +1262,7 @@ function createVastAdLayer(contentVideo, options) {
1231
1262
  adHls.loadSource(mediaFile.url);
1232
1263
  adHls.attachMedia(adVideoElement);
1233
1264
  adHls.on(Hls.Events.MANIFEST_PARSED, function() {
1265
+ if (!adPlaying) return;
1234
1266
  adVideoElement.play().catch(function(error) {
1235
1267
  console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
1236
1268
  handleAdError();
@@ -1864,6 +1896,7 @@ function createVastAdLayer(contentVideo, options) {
1864
1896
  return 1;
1865
1897
  },
1866
1898
  showPlaceholder: function showPlaceholder() {
1899
+ if (singleElementMode) return;
1867
1900
  contentVideo.style.opacity = "0";
1868
1901
  contentVideo.style.visibility = "hidden";
1869
1902
  if (!adContainerEl) {
@@ -3588,7 +3621,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3588
3621
  }
3589
3622
  _this.adLayer.cancelPreload(token);
3590
3623
  } else {
3591
- _this.showPlaceholderLayer();
3624
+ if (!_this.config.singlePipelineMode) {
3625
+ _this.showPlaceholderLayer();
3626
+ }
3592
3627
  _this.adLayer.showPlaceholder();
3593
3628
  _this.isInAdTransition = true;
3594
3629
  setTimeout(function() {
@@ -3612,7 +3647,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3612
3647
  console.log("[StormcloudVideoPlayer] content_resume: skip pending bids, only", remainingNow1, "ms left");
3613
3648
  }
3614
3649
  } else {
3615
- _this.showPlaceholderLayer();
3650
+ if (!_this.config.singlePipelineMode) {
3651
+ _this.showPlaceholderLayer();
3652
+ }
3616
3653
  _this.adLayer.showPlaceholder();
3617
3654
  _this.isInAdTransition = true;
3618
3655
  setTimeout(function() {
@@ -3971,12 +4008,17 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3971
4008
  }
3972
4009
  }
3973
4010
  if (this.inAdBreak) {
3974
- if (this.expectedAdBreakDurationMs == null && marker.durationSeconds != null) {
3975
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
3976
- if (this.config.debugAdTiming) {
3977
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(this.expectedAdBreakDurationMs, "ms"));
4011
+ if (marker.durationSeconds != null) {
4012
+ var newDurationMs = marker.durationSeconds * 1e3;
4013
+ if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4014
+ this.expectedAdBreakDurationMs = newDurationMs;
4015
+ var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4016
+ var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4017
+ this.scheduleAdStopCountdown(remainingMs);
4018
+ if (this.config.debugAdTiming) {
4019
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4020
+ }
3978
4021
  }
3979
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
3980
4022
  }
3981
4023
  return;
3982
4024
  }
@@ -4057,9 +4099,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4057
4099
  this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4058
4100
  }
4059
4101
  if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4060
- var elapsedMs = Date.now() - this.currentAdBreakStartWallClockMs;
4061
- var remainingMs = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs);
4062
- this.scheduleAdStopCountdown(remainingMs);
4102
+ var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4103
+ var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4104
+ this.scheduleAdStopCountdown(remainingMs1);
4063
4105
  }
4064
4106
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4065
4107
  var bids = this.pendingNextAdBids;
@@ -4980,7 +5022,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4980
5022
  if (!this.config.disableFiller) this.showAds = true;
4981
5023
  if (adBreakDurationMs != null) {
4982
5024
  this.startFillerBreakTimer(adBreakDurationMs);
4983
- } else if (!this.config.disableFiller) {
5025
+ } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
4984
5026
  this.showPlaceholderLayer();
4985
5027
  }
4986
5028
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();