stormcloud-video-player 0.8.44 → 0.8.46

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.
@@ -1,4 +1,4 @@
1
- import { S as StormcloudVideoPlayerConfig } from '../types-iDjS8f_7.cjs';
1
+ import { a as StormcloudVideoPlayerConfig } from '../types-cTqIKw_D.cjs';
2
2
 
3
3
  declare class StormcloudVideoPlayer {
4
4
  private readonly video;
@@ -1,4 +1,4 @@
1
- import { a as Scte35Marker } from '../types-iDjS8f_7.cjs';
1
+ import { S as Scte35Marker } from '../types-cTqIKw_D.cjs';
2
2
 
3
3
  type Scte35CueSource = "manifest" | "id3" | "ts";
4
4
  type Scte35CueReadiness = "early" | "playback";
@@ -1256,16 +1256,34 @@ function createHlsAdPlayer(contentVideo, options) {
1256
1256
  }
1257
1257
  }, STALL_CHECK_INTERVAL_MS);
1258
1258
  }
1259
+ function releaseAdDecoder() {
1260
+ if (adHls) {
1261
+ adHls.destroy();
1262
+ adHls = void 0;
1263
+ }
1264
+ if (adVideoElement) {
1265
+ adVideoElement.pause();
1266
+ adVideoElement.removeAttribute("src");
1267
+ try {
1268
+ adVideoElement.load();
1269
+ } catch (error) {
1270
+ console.warn("[HlsAdPlayer] adVideoElement.load() threw after src removal:", error);
1271
+ }
1272
+ adVideoElement.remove();
1273
+ adVideoElement = void 0;
1274
+ }
1275
+ if (adContainerEl) {
1276
+ adContainerEl.style.display = "none";
1277
+ adContainerEl.style.pointerEvents = "none";
1278
+ }
1279
+ }
1259
1280
  function handleAdComplete() {
1260
1281
  console.log("[HlsAdPlayer] Handling ad completion");
1261
1282
  clearStallWatchdog();
1262
1283
  adPlaying = false;
1263
1284
  setAdPlayingFlag(false);
1264
1285
  contentVideo.muted = true;
1265
- if (adContainerEl) {
1266
- adContainerEl.style.display = "none";
1267
- adContainerEl.style.pointerEvents = "none";
1268
- }
1286
+ releaseAdDecoder();
1269
1287
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1270
1288
  contentVideo.style.visibility = "visible";
1271
1289
  contentVideo.style.opacity = "1";
@@ -1273,7 +1291,9 @@ function createHlsAdPlayer(contentVideo, options) {
1273
1291
  if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1274
1292
  if (contentVideo.paused) {
1275
1293
  console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback");
1276
- contentVideo.play().catch(function() {});
1294
+ contentVideo.play().catch(function(error) {
1295
+ console.error("[HlsAdPlayer] Error resuming content playback in live mode:", error);
1296
+ });
1277
1297
  } else {
1278
1298
  console.log("[HlsAdPlayer] Content video already playing in live mode");
1279
1299
  }
@@ -1286,10 +1306,7 @@ function createHlsAdPlayer(contentVideo, options) {
1286
1306
  adPlaying = false;
1287
1307
  setAdPlayingFlag(false);
1288
1308
  contentVideo.muted = true;
1289
- if (adContainerEl) {
1290
- adContainerEl.style.display = "none";
1291
- adContainerEl.style.pointerEvents = "none";
1292
- }
1309
+ releaseAdDecoder();
1293
1310
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1294
1311
  contentVideo.style.visibility = "visible";
1295
1312
  contentVideo.style.opacity = "1";
@@ -1498,29 +1515,17 @@ function createHlsAdPlayer(contentVideo, options) {
1498
1515
  contentVideo.muted = originalMutedState;
1499
1516
  contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1500
1517
  console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState, ", volume: ").concat(contentVideo.volume));
1501
- if (adContainerEl) {
1502
- adContainerEl.style.display = "none";
1503
- adContainerEl.style.pointerEvents = "none";
1504
- }
1518
+ releaseAdDecoder();
1505
1519
  contentVideo.style.visibility = "visible";
1506
1520
  contentVideo.style.opacity = "1";
1507
1521
  if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1508
1522
  if (contentVideo.paused) {
1509
1523
  console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback on stop");
1510
- contentVideo.play().catch(function() {});
1524
+ contentVideo.play().catch(function(error) {
1525
+ console.error("[HlsAdPlayer] Error resuming content playback in live mode on stop:", error);
1526
+ });
1511
1527
  }
1512
1528
  }
1513
- if (adHls) {
1514
- adHls.destroy();
1515
- adHls = void 0;
1516
- }
1517
- if (adVideoElement) {
1518
- adVideoElement.pause();
1519
- adVideoElement.removeAttribute("src");
1520
- try {
1521
- adVideoElement.load();
1522
- } catch (unused) {}
1523
- }
1524
1529
  currentAd = void 0;
1525
1530
  podAds = [];
1526
1531
  podIndex = 0;
@@ -1559,19 +1564,7 @@ function createHlsAdPlayer(contentVideo, options) {
1559
1564
  setAdPlayingFlag(false);
1560
1565
  contentVideo.muted = originalMutedState;
1561
1566
  contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1562
- if (adHls) {
1563
- adHls.destroy();
1564
- adHls = void 0;
1565
- }
1566
- if (adVideoElement) {
1567
- adVideoElement.pause();
1568
- adVideoElement.removeAttribute("src");
1569
- try {
1570
- adVideoElement.load();
1571
- } catch (unused) {}
1572
- adVideoElement.remove();
1573
- adVideoElement = void 0;
1574
- }
1567
+ releaseAdDecoder();
1575
1568
  if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
1576
1569
  adContainerEl.parentElement.removeChild(adContainerEl);
1577
1570
  }
@@ -6731,6 +6724,21 @@ var HlsEngine = /*#__PURE__*/ function() {
6731
6724
  }
6732
6725
  }
6733
6726
  },
6727
+ {
6728
+ key: "recoverMediaError",
6729
+ value: function recoverMediaError() {
6730
+ if (!this.hls) {
6731
+ return;
6732
+ }
6733
+ try {
6734
+ this.hls.recoverMediaError();
6735
+ } catch (error) {
6736
+ if (this.debug) {
6737
+ console.warn("[StormcloudVideoPlayer] recoverMediaError() failed:", error);
6738
+ }
6739
+ }
6740
+ }
6741
+ },
6734
6742
  {
6735
6743
  key: "reloadLiveStream",
6736
6744
  value: function reloadLiveStream() {
@@ -6748,7 +6756,9 @@ var HlsEngine = /*#__PURE__*/ function() {
6748
6756
  try {
6749
6757
  this.video.removeAttribute("src");
6750
6758
  this.video.load();
6751
- } catch (unused) {}
6759
+ } catch (error) {
6760
+ console.warn("[StormcloudVideoPlayer] video.load() threw after src removal:", error);
6761
+ }
6752
6762
  hls.attachMedia(this.video);
6753
6763
  } catch (error) {
6754
6764
  this.reloadingLiveStream = false;
@@ -8132,8 +8142,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8132
8142
  var pollIntervalMs = 1e3;
8133
8143
  var graceMs = 5e3;
8134
8144
  var recoveryCooldownMs = 5e3;
8135
- var maxRecoveries = 2;
8136
- var maxMonitorMs = 3e4;
8145
+ var maxRecoveries = 3;
8146
+ var maxMonitorMs = 45e3;
8137
8147
  var startTime = Date.now();
8138
8148
  var baseline = resumeBaseline;
8139
8149
  var recoveries = 0;
@@ -8245,8 +8255,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8245
8255
  if (canRecover) {
8246
8256
  recoveries++;
8247
8257
  lastRecoveryAt = Date.now();
8248
- var isFinalAttempt = recoveries >= maxRecoveries;
8249
- if (!isFinalAttempt) {
8258
+ if (recoveries === 1) {
8259
+ if (_this.debug) {
8260
+ console.warn("[StormcloudVideoPlayer] Content wedged after ad break — calling recoverMediaError() (recovery ".concat(recoveries, "/").concat(maxRecoveries, ") — ").concat(_this.describeVideoState()));
8261
+ }
8262
+ _this.host.recoverMediaError();
8263
+ } else if (recoveries === 2) {
8250
8264
  var liveSyncPos = _this.host.getLiveSyncPosition();
8251
8265
  var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8252
8266
  if (_this.debug) {
@@ -8278,17 +8292,41 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8278
8292
  value: function resumeContentPlayback() {
8279
8293
  var _this = this;
8280
8294
  var attempt = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
8281
- var maxAttempts = 3;
8282
- if (!this.host.video.paused) {
8295
+ var maxAttempts = 5;
8296
+ var video = this.host.video;
8297
+ if (!video.paused) {
8283
8298
  if (this.debug && attempt === 0) {
8284
8299
  console.log("[StormcloudVideoPlayer] Content video already playing after ads");
8285
8300
  }
8286
8301
  return;
8287
8302
  }
8288
8303
  if (this.debug) {
8289
- console.log("[StormcloudVideoPlayer] Resuming content playback after ads (attempt ".concat(attempt + 1, "/").concat(maxAttempts, ")"));
8304
+ console.log("[StormcloudVideoPlayer] Resuming content playback after ads (attempt ".concat(attempt + 1, "/").concat(maxAttempts, ", readyState=").concat(video.readyState, ")"));
8290
8305
  }
8291
- var playResult = this.host.video.play();
8306
+ if (video.readyState < 3) {
8307
+ if (attempt + 1 >= maxAttempts) {
8308
+ var _video_play;
8309
+ if (this.debug) {
8310
+ console.warn("[StormcloudVideoPlayer] readyState never reached HAVE_FUTURE_DATA, forcing play()");
8311
+ }
8312
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8313
+ return;
8314
+ }
8315
+ var onReady = function onReady1() {
8316
+ video.removeEventListener("canplay", onReady);
8317
+ _this.resumeContentPlayback(attempt + 1);
8318
+ };
8319
+ video.addEventListener("canplay", onReady);
8320
+ var backoffMs = 500 * (attempt + 1);
8321
+ window.setTimeout(function() {
8322
+ video.removeEventListener("canplay", onReady);
8323
+ if (video.paused) {
8324
+ _this.resumeContentPlayback(attempt + 1);
8325
+ }
8326
+ }, backoffMs);
8327
+ return;
8328
+ }
8329
+ var playResult = video.play();
8292
8330
  if (playResult && typeof playResult.catch === "function") {
8293
8331
  playResult.catch(function(error) {
8294
8332
  if (attempt + 1 >= maxAttempts) {
@@ -8427,6 +8465,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8427
8465
  reloadLiveStream: function reloadLiveStream() {
8428
8466
  return _this.hlsEngine.reloadLiveStream();
8429
8467
  },
8468
+ recoverMediaError: function recoverMediaError() {
8469
+ return _this.hlsEngine.recoverMediaError();
8470
+ },
8430
8471
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8431
8472
  return _this.generatePodVastUrl(base, breakDurationMs);
8432
8473
  }