stormcloud-video-player 0.8.35 → 0.8.37

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
@@ -1337,7 +1337,7 @@ function createHlsAdPlayer(contentVideo, options) {
1337
1337
  adHls.destroy();
1338
1338
  }
1339
1339
  adHls = new import_hls.default({
1340
- enableWorker: true,
1340
+ enableWorker: typeof globalThis !== "undefined",
1341
1341
  lowLatencyMode: false
1342
1342
  });
1343
1343
  adHls.loadSource(mediaFile.url);
@@ -3722,7 +3722,7 @@ function removeBrokenAppNameOrphans(params, appName) {
3722
3722
  try {
3723
3723
  for(var _iterator = appName.split("&").slice(1)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3724
3724
  var suffix = _step.value;
3725
- var trimmed = suffix.trimStart();
3725
+ var trimmed = suffix.replace(/^\s+/, "");
3726
3726
  if (!trimmed) continue;
3727
3727
  toDelete.push(suffix, " ".concat(trimmed), trimmed);
3728
3728
  }
@@ -3776,7 +3776,7 @@ function normalizeVastTagUrl(raw) {
3776
3776
  });
3777
3777
  if (orphanFragments.length > 0) {
3778
3778
  var reconstructed = [
3779
- anValue.trimEnd()
3779
+ anValue.replace(/\s+$/, "")
3780
3780
  ].concat(_to_consumable_array(orphanFragments)).filter(Boolean).join(" & ");
3781
3781
  url.searchParams.forEach(function(_value, key) {
3782
3782
  if (key && INVALID_VAST_PARAM_KEY.test(key)) {
@@ -5311,6 +5311,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
5311
5311
  ];
5312
5312
  case 4:
5313
5313
  data = _state.sent();
5314
+ this.applyMqttConfigFromResponse(data);
5314
5315
  imaPayload = (_data_response = data.response) === null || _data_response === void 0 ? void 0 : (_data_response_ima = _data_response.ima) === null || _data_response_ima === void 0 ? void 0 : (_data_response_ima_publisherdeskima = _data_response_ima["publisherdesk.ima"]) === null || _data_response_ima_publisherdeskima === void 0 ? void 0 : _data_response_ima_publisherdeskima.payload;
5315
5316
  if (imaPayload) {
5316
5317
  decodedPayload = imaPayload;
@@ -5344,6 +5345,20 @@ var AdConfigManager = /*#__PURE__*/ function() {
5344
5345
  }).call(this);
5345
5346
  }
5346
5347
  },
5348
+ {
5349
+ key: "applyMqttConfigFromResponse",
5350
+ value: function applyMqttConfigFromResponse(data) {
5351
+ var _data_response;
5352
+ var mqttConfig2 = (_data_response = data.response) === null || _data_response === void 0 ? void 0 : _data_response.mqtt_config;
5353
+ if (!mqttConfig2 || (typeof mqttConfig2 === "undefined" ? "undefined" : _type_of(mqttConfig2)) !== "object") {
5354
+ return;
5355
+ }
5356
+ applyMQTTConfig(mqttConfig2);
5357
+ if (this.debug) {
5358
+ console.log("[StormcloudVideoPlayer] Applied MQTT config from /ads/web:", mqttConfig2);
5359
+ }
5360
+ }
5361
+ },
5347
5362
  {
5348
5363
  key: "fetchAndParseVmap",
5349
5364
  value: function fetchAndParseVmap(vmapUrl) {
@@ -6472,7 +6487,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6472
6487
  value: function setupHls() {
6473
6488
  var _this = this;
6474
6489
  this.hls = new import_hls2.default(_object_spread_props(_object_spread({
6475
- enableWorker: true,
6490
+ enableWorker: typeof globalThis !== "undefined",
6476
6491
  backBufferLength: 30,
6477
6492
  liveDurationInfinity: true,
6478
6493
  lowLatencyMode: !!this.config.lowLatencyMode,
@@ -6861,6 +6876,22 @@ var HlsEngine = /*#__PURE__*/ function() {
6861
6876
  return typeof pos === "number" && Number.isFinite(pos) ? pos : void 0;
6862
6877
  }
6863
6878
  },
6879
+ {
6880
+ key: "restartLoadAt",
6881
+ value: function restartLoadAt(position) {
6882
+ if (!this.hls) {
6883
+ return;
6884
+ }
6885
+ try {
6886
+ this.hls.stopLoad();
6887
+ this.hls.startLoad(position);
6888
+ } catch (error) {
6889
+ if (this.debug) {
6890
+ console.warn("[StormcloudVideoPlayer] Failed to restart HLS load at live edge:", error);
6891
+ }
6892
+ }
6893
+ }
6894
+ },
6864
6895
  {
6865
6896
  key: "destroy",
6866
6897
  value: function destroy() {
@@ -8177,11 +8208,56 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8177
8208
  console.log("[StormcloudVideoPlayer] Live break end — snapping to live edge: ".concat(this.host.video.currentTime.toFixed(2), "s → ").concat(liveSyncPos.toFixed(2), "s"));
8178
8209
  }
8179
8210
  this.host.video.currentTime = liveSyncPos;
8211
+ this.host.restartHlsLoad(liveSyncPos);
8180
8212
  }
8213
+ this.resumeContentPlayback();
8214
+ this.monitorLiveResumeStall(0, this.host.video.currentTime);
8215
+ return;
8181
8216
  }
8182
8217
  this.resumeContentPlayback();
8183
8218
  }
8184
8219
  },
8220
+ {
8221
+ key: "monitorLiveResumeStall",
8222
+ value: function monitorLiveResumeStall(attempt, lastTime) {
8223
+ var _this = this;
8224
+ var maxAttempts = 3;
8225
+ var checkDelayMs = 2500;
8226
+ window.setTimeout(function() {
8227
+ if (_this.inAdBreak) {
8228
+ return;
8229
+ }
8230
+ var currentTime = _this.host.video.currentTime;
8231
+ var advanced = currentTime > lastTime + 0.25;
8232
+ if (advanced && !_this.host.video.paused) {
8233
+ if (_this.debug) {
8234
+ console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8235
+ }
8236
+ return;
8237
+ }
8238
+ if (attempt >= maxAttempts) {
8239
+ if (_this.debug) {
8240
+ console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8241
+ }
8242
+ return;
8243
+ }
8244
+ if (_this.debug) {
8245
+ console.warn("[StormcloudVideoPlayer] Content stalled after ad break (t=".concat(currentTime.toFixed(2), "s) — forcing HLS reload at live edge (attempt ").concat(attempt + 1, "/").concat(maxAttempts, ")"));
8246
+ }
8247
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8248
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8249
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8250
+ _this.host.video.currentTime = liveSyncPos;
8251
+ }
8252
+ _this.host.restartHlsLoad(reloadPos);
8253
+ if (_this.host.video.paused) {
8254
+ var _this_host_video_play;
8255
+ (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8256
+ }
8257
+ _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8258
+ }, checkDelayMs);
8259
+ }
8260
+ },
8185
8261
  {
8186
8262
  key: "resumeContentPlayback",
8187
8263
  value: function resumeContentPlayback() {
@@ -8330,6 +8406,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8330
8406
  getLiveSyncPosition: function getLiveSyncPosition() {
8331
8407
  return _this.hlsEngine.getLiveSyncPosition();
8332
8408
  },
8409
+ restartHlsLoad: function restartHlsLoad(position) {
8410
+ return _this.hlsEngine.restartLoadAt(position);
8411
+ },
8333
8412
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8334
8413
  return _this.generatePodVastUrl(base, breakDurationMs);
8335
8414
  }