stormcloud-video-player 0.7.12 → 0.7.13

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.
@@ -3679,6 +3679,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3679
3679
  if (this.config.debugAdTiming) {
3680
3680
  console.log("[PREFETCH] First VAST request returned no ad, aborting prefetch");
3681
3681
  }
3682
+ this.clearPendingAdBreak();
3682
3683
  return [
3683
3684
  2
3684
3685
  ];
@@ -3912,7 +3913,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3912
3913
  key: "fetchAdInsertionPoint",
3913
3914
  value: function fetchAdInsertionPoint() {
3914
3915
  return _async_to_generator(function() {
3915
- var _this_lastAdInsertionPoint, resp, data, isNew, unused;
3916
+ var _this_lastAdInsertionPoint, _this_lastAdInsertionPoint1, resp, data, prevSegment, isNew, segmentChanged, unused;
3916
3917
  return _ts_generator(this, function(_state) {
3917
3918
  switch(_state.label){
3918
3919
  case 0:
@@ -3942,7 +3943,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3942
3943
  ];
3943
3944
  case 3:
3944
3945
  data = _state.sent();
3945
- isNew = data.updated_at !== ((_this_lastAdInsertionPoint = this.lastAdInsertionPoint) === null || _this_lastAdInsertionPoint === void 0 ? void 0 : _this_lastAdInsertionPoint.updated_at);
3946
+ prevSegment = (_this_lastAdInsertionPoint = this.lastAdInsertionPoint) === null || _this_lastAdInsertionPoint === void 0 ? void 0 : _this_lastAdInsertionPoint.segment_ts_name;
3947
+ isNew = data.updated_at !== ((_this_lastAdInsertionPoint1 = this.lastAdInsertionPoint) === null || _this_lastAdInsertionPoint1 === void 0 ? void 0 : _this_lastAdInsertionPoint1.updated_at);
3948
+ segmentChanged = prevSegment !== data.segment_ts_name;
3946
3949
  this.lastAdInsertionPoint = data;
3947
3950
  if (isNew) {
3948
3951
  this.pushAdInsertionDebug("api_response", data.segment_ts_name, {
@@ -3950,6 +3953,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3950
3953
  updatedAt: data.updated_at,
3951
3954
  detail: "project=".concat(data.project_id)
3952
3955
  });
3956
+ if (segmentChanged && (this.pendingAdBreak || this.adInsertionOffsetTimerId != null)) {
3957
+ this.clearAdInsertionOffsetTimer();
3958
+ this.clearPendingAdBreak();
3959
+ this.cancelAndClearPreloadedTokens();
3960
+ if (this.config.debugAdTiming) {
3961
+ console.log("[StormcloudVideoPlayer] Insertion segment changed (".concat(prevSegment, " → ").concat(data.segment_ts_name, "), stale pending state cleared"));
3962
+ }
3963
+ }
3964
+ this.checkAdInsertionInManifest();
3953
3965
  }
3954
3966
  if (this.config.debugAdTiming) {
3955
3967
  console.log("[StormcloudVideoPlayer] Ad insertion point API response:", data);
@@ -3979,6 +3991,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3979
3991
  {
3980
3992
  key: "checkAdInsertionInManifest",
3981
3993
  value: function checkAdInsertionInManifest() {
3994
+ var _this = this;
3982
3995
  var _this_hls;
3983
3996
  if (!this.lastAdInsertionPoint) return;
3984
3997
  if (this.inAdBreak || this.pendingAdBreak) return;
@@ -3998,14 +4011,42 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3998
4011
  for(var _iterator1 = fragments[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3999
4012
  var frag = _step1.value;
4000
4013
  if (this.fragmentMatchesSegment(frag, segmentName)) {
4001
- var _ref;
4014
+ var _frag_start, _frag_duration, _ref;
4015
+ var currentTime = this.video.currentTime;
4016
+ var fragStart = (_frag_start = frag.start) !== null && _frag_start !== void 0 ? _frag_start : 0;
4017
+ var fragDuration = (_frag_duration = frag.duration) !== null && _frag_duration !== void 0 ? _frag_duration : 0;
4018
+ var isCurrentlyPlaying = fragDuration > 0 && currentTime >= fragStart && currentTime < fragStart + fragDuration;
4002
4019
  this.pushAdInsertionDebug("segment_found", segmentName, {
4003
- detail: "sn=".concat((_ref = frag === null || frag === void 0 ? void 0 : frag.sn) !== null && _ref !== void 0 ? _ref : "?")
4020
+ detail: "sn=".concat((_ref = frag === null || frag === void 0 ? void 0 : frag.sn) !== null && _ref !== void 0 ? _ref : "?", " ").concat(isCurrentlyPlaying ? "(playing)" : "(future)")
4004
4021
  });
4005
4022
  if (this.config.debugAdTiming) {
4006
- console.log('[StormcloudVideoPlayer] Ad insertion segment "'.concat(segmentName, '" found in manifest — starting pre-fetch'));
4023
+ console.log('[StormcloudVideoPlayer] Ad insertion segment "'.concat(segmentName, '" found in manifest — ') + (isCurrentlyPlaying ? "currently playing, scheduling directly" : "starting pre-fetch"));
4007
4024
  }
4008
4025
  this.startAdPrefetch(60, frag === null || frag === void 0 ? void 0 : frag.sn);
4026
+ if (isCurrentlyPlaying && !this.inAdBreak) {
4027
+ var _this_lastAdInsertionPoint_offset_seconds, _ref1;
4028
+ this.processedAdInsertionUpdatedAt = this.lastAdInsertionPoint.updated_at;
4029
+ var rawOffsetMs = ((_this_lastAdInsertionPoint_offset_seconds = this.lastAdInsertionPoint.offset_seconds) !== null && _this_lastAdInsertionPoint_offset_seconds !== void 0 ? _this_lastAdInsertionPoint_offset_seconds : 0) * 1e3;
4030
+ var elapsedInFragMs = (currentTime - fragStart) * 1e3;
4031
+ var remainingOffsetMs = Math.max(0, rawOffsetMs - elapsedInFragMs);
4032
+ this.pushAdInsertionDebug("segment_playing", segmentName, {
4033
+ offsetSeconds: this.lastAdInsertionPoint.offset_seconds,
4034
+ detail: "sn=".concat((_ref1 = frag === null || frag === void 0 ? void 0 : frag.sn) !== null && _ref1 !== void 0 ? _ref1 : "?", " (caught in manifest check)")
4035
+ });
4036
+ this.pushAdInsertionDebug("ad_scheduled", segmentName, {
4037
+ offsetSeconds: this.lastAdInsertionPoint.offset_seconds,
4038
+ detail: "in ".concat(remainingOffsetMs, "ms (adjusted for elapsed ").concat(Math.round(elapsedInFragMs), "ms)")
4039
+ });
4040
+ this.clearAdInsertionOffsetTimer();
4041
+ this.adInsertionOffsetTimerId = window.setTimeout(function() {
4042
+ _this.adInsertionOffsetTimerId = void 0;
4043
+ if (_this.inAdBreak) return;
4044
+ _this.pushAdInsertionDebug("ad_triggered", segmentName, {
4045
+ detail: "ad break started (60s, via manifest-check path)"
4046
+ });
4047
+ void _this.handleAdStart(60);
4048
+ }, remainingOffsetMs);
4049
+ }
4009
4050
  return;
4010
4051
  }
4011
4052
  }