stormcloud-video-player 0.5.7 → 0.5.9

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.d.cts CHANGED
@@ -154,6 +154,8 @@ declare class StormcloudVideoPlayer {
154
154
  private readonly maxTotalAdRequestsPerBreak;
155
155
  private pendingAdBreak;
156
156
  private prefetchTimerId;
157
+ private prefetchAdPromise;
158
+ private savedMutedStateBeforeScte;
157
159
  private consecutiveFailures;
158
160
  private readonly maxConsecutiveFailures;
159
161
  private lastAdRequestTime;
package/lib/index.d.ts CHANGED
@@ -154,6 +154,8 @@ declare class StormcloudVideoPlayer {
154
154
  private readonly maxTotalAdRequestsPerBreak;
155
155
  private pendingAdBreak;
156
156
  private prefetchTimerId;
157
+ private prefetchAdPromise;
158
+ private savedMutedStateBeforeScte;
157
159
  private consecutiveFailures;
158
160
  private readonly maxConsecutiveFailures;
159
161
  private lastAdRequestTime;
package/lib/index.js CHANGED
@@ -548,8 +548,8 @@ function createEmptyTrackingState() {
548
548
  complete: false
549
549
  };
550
550
  }
551
- function fireTrackingPixels(urls, sessionId, licenseKey) {
552
- var logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
551
+ function fireTrackingPixels(urls, sessionId) {
552
+ var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
553
553
  if (!urls || urls.length === 0) return;
554
554
  urls.forEach(function(url) {
555
555
  try {
@@ -557,10 +557,8 @@ function fireTrackingPixels(urls, sessionId, licenseKey) {
557
557
  if (sessionId) {
558
558
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
559
559
  }
560
- if (licenseKey) {
561
- trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "license_key=").concat(licenseKey);
562
- }
563
560
  var img = new Image(1, 1);
561
+ img.onerror = function() {};
564
562
  img.src = trackingUrl;
565
563
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
566
564
  } catch (error) {
@@ -961,7 +959,7 @@ function createPrebidController(contentVideo, options) {
961
959
  return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
962
960
  }
963
961
  function fireTrackingPixels2(urls) {
964
- fireTrackingPixels(urls, sessionId, licenseKey, LOG);
962
+ fireTrackingPixels(urls, sessionId, LOG);
965
963
  }
966
964
  function getMainStreamQuality() {
967
965
  if (!mainHlsInstance || !mainHlsInstance.levels) {
@@ -2726,6 +2724,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2726
2724
  this.totalAdRequestsInBreak = 0;
2727
2725
  this.maxTotalAdRequestsPerBreak = 20;
2728
2726
  this.pendingAdBreak = null;
2727
+ this.prefetchAdPromise = null;
2728
+ this.savedMutedStateBeforeScte = null;
2729
2729
  this.consecutiveFailures = 0;
2730
2730
  this.maxConsecutiveFailures = 5;
2731
2731
  this.lastAdRequestTime = 0;
@@ -3201,6 +3201,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3201
3201
  }
3202
3202
  }
3203
3203
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
3204
+ _this.adController.stop().catch(function() {});
3204
3205
  _this.handleAdFailure();
3205
3206
  });
3206
3207
  this.adController.on("content_pause", function() {
@@ -3243,6 +3244,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3243
3244
  _this.activeAdRequestToken = null;
3244
3245
  _this.showAds = false;
3245
3246
  if (!_this.inAdBreak) {
3247
+ if (_this.config.debugAdTiming) {
3248
+ console.log("[StormcloudVideoPlayer] content_resume: break already ended (e.g. by CUE-IN or handleAdPodComplete), skipping next-ad path");
3249
+ }
3246
3250
  return;
3247
3251
  }
3248
3252
  _this.consecutiveFailures = 0;
@@ -3255,6 +3259,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3255
3259
  if (remaining > 500) {
3256
3260
  _this.tryNextAvailableAdWithRateLimit();
3257
3261
  } else {
3262
+ if (_this.config.debugAdTiming) {
3263
+ console.log("[StormcloudVideoPlayer] content_resume: remaining time too low to try next ad, ending ad pod");
3264
+ }
3258
3265
  _this.handleAdPodComplete();
3259
3266
  }
3260
3267
  });
@@ -3263,6 +3270,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3263
3270
  {
3264
3271
  key: "recreateAdController",
3265
3272
  value: function recreateAdController() {
3273
+ this.prefetchAdPromise = null;
3266
3274
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3267
3275
  if (shouldShowPlaceholder && this.adController) {
3268
3276
  this.showPlaceholderLayer();
@@ -3591,6 +3599,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3591
3599
  if (marker.type === "start") {
3592
3600
  var _this_config_immediateManifestAds;
3593
3601
  var _this_pendingAdBreak;
3602
+ this.savedMutedStateBeforeScte = {
3603
+ muted: this.video.muted,
3604
+ volume: this.video.volume
3605
+ };
3606
+ this.adController.updateOriginalMutedState(this.video.muted, this.video.volume);
3594
3607
  if (!this.video.muted) {
3595
3608
  this.video.muted = true;
3596
3609
  this.video.volume = 0;
@@ -3713,9 +3726,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3713
3726
  activeAdRequest: this.activeAdRequestToken !== null
3714
3727
  });
3715
3728
  }
3716
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
3729
+ if (adPlaying || remaining > 500) {
3717
3730
  if (this.config.debugAdTiming) {
3718
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
3731
+ console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active or time remaining");
3719
3732
  }
3720
3733
  return;
3721
3734
  }
@@ -4032,6 +4045,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4032
4045
  {
4033
4046
  key: "startAdPrefetch",
4034
4047
  value: function startAdPrefetch(marker, fragmentSn) {
4048
+ var _this = this;
4035
4049
  if (this.pendingAdBreak || this.inAdBreak) {
4036
4050
  return;
4037
4051
  }
@@ -4043,8 +4057,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4043
4057
  isFetching: false,
4044
4058
  fetchStartTime: Date.now()
4045
4059
  });
4060
+ this.prefetchAdPromise = this.adController.requestAds().catch(function() {
4061
+ if (_this.config.debugAdTiming) {
4062
+ console.log("[PREFETCH] Prebid auction prefetch failed, will request at playback time");
4063
+ }
4064
+ });
4046
4065
  if (this.config.debugAdTiming) {
4047
- console.log("[PREFETCH] Ad break marker registered, auction runs at playback time via controller");
4066
+ console.log("[PREFETCH] Ad break marker registered, auction prefetch started");
4048
4067
  }
4049
4068
  }
4050
4069
  },
@@ -4055,6 +4074,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4055
4074
  clearTimeout(this.prefetchTimerId);
4056
4075
  this.prefetchTimerId = void 0;
4057
4076
  }
4077
+ this.prefetchAdPromise = null;
4058
4078
  this.pendingAdBreak = null;
4059
4079
  }
4060
4080
  },
@@ -4062,7 +4082,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4062
4082
  key: "handleAdStart",
4063
4083
  value: function handleAdStart(_marker) {
4064
4084
  return _async_to_generator(function() {
4065
- var adBreakDurationMs, mode, currentMuted, currentVolume, adLoadedInfo, adVolume, error;
4085
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, unused, unused1, adLoadedInfo, adVolume, error;
4066
4086
  return _ts_generator(this, function(_state) {
4067
4087
  switch(_state.label){
4068
4088
  case 0:
@@ -4075,9 +4095,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4075
4095
  this.continuousFetchingActive = true;
4076
4096
  this.isShowingPlaceholder = false;
4077
4097
  this.totalAdRequestsInBreak = 0;
4078
- currentMuted = this.video.muted;
4079
- currentVolume = this.video.volume;
4080
- this.adController.updateOriginalMutedState(currentMuted, currentVolume);
4098
+ state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4099
+ muted: this.video.muted,
4100
+ volume: this.video.volume
4101
+ };
4102
+ this.adController.updateOriginalMutedState(state.muted, state.volume);
4103
+ this.savedMutedStateBeforeScte = null;
4081
4104
  if (!this.video.muted) {
4082
4105
  this.video.muted = true;
4083
4106
  this.video.volume = 0;
@@ -4096,25 +4119,94 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4096
4119
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4097
4120
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4098
4121
  }
4099
- this.clearPendingAdBreak();
4100
4122
  if (this.config.debugAdTiming) {
4101
- console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction via requestAds()");
4123
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction (prefetch or requestAds)");
4102
4124
  }
4103
4125
  _state.label = 1;
4104
4126
  case 1:
4105
4127
  _state.trys.push([
4106
4128
  1,
4107
- 4,
4129
+ 6,
4108
4130
  ,
4109
- 6
4131
+ 12
4110
4132
  ]);
4111
4133
  this.lastAdRequestTime = Date.now();
4134
+ if (!this.prefetchAdPromise) return [
4135
+ 3,
4136
+ 3
4137
+ ];
4112
4138
  return [
4113
4139
  4,
4114
- this.adController.requestAds()
4140
+ this.prefetchAdPromise
4115
4141
  ];
4116
4142
  case 2:
4117
4143
  _state.sent();
4144
+ this.prefetchAdPromise = null;
4145
+ return [
4146
+ 3,
4147
+ 5
4148
+ ];
4149
+ case 3:
4150
+ return [
4151
+ 4,
4152
+ this.adController.requestAds()
4153
+ ];
4154
+ case 4:
4155
+ _state.sent();
4156
+ _state.label = 5;
4157
+ case 5:
4158
+ return [
4159
+ 3,
4160
+ 12
4161
+ ];
4162
+ case 6:
4163
+ unused = _state.sent();
4164
+ _state.label = 7;
4165
+ case 7:
4166
+ _state.trys.push([
4167
+ 7,
4168
+ 9,
4169
+ ,
4170
+ 11
4171
+ ]);
4172
+ return [
4173
+ 4,
4174
+ this.adController.requestAds()
4175
+ ];
4176
+ case 8:
4177
+ _state.sent();
4178
+ return [
4179
+ 3,
4180
+ 11
4181
+ ];
4182
+ case 9:
4183
+ unused1 = _state.sent();
4184
+ this.clearPendingAdBreak();
4185
+ this.consecutiveFailures++;
4186
+ return [
4187
+ 4,
4188
+ this.tryNextAvailableAdWithRateLimit()
4189
+ ];
4190
+ case 10:
4191
+ _state.sent();
4192
+ return [
4193
+ 2
4194
+ ];
4195
+ case 11:
4196
+ return [
4197
+ 3,
4198
+ 12
4199
+ ];
4200
+ case 12:
4201
+ this.clearPendingAdBreak();
4202
+ _state.label = 13;
4203
+ case 13:
4204
+ _state.trys.push([
4205
+ 13,
4206
+ 15,
4207
+ ,
4208
+ 17
4209
+ ]);
4118
4210
  if (this.config.licenseKey) {
4119
4211
  adLoadedInfo = {
4120
4212
  source: this.getAdSource(),
@@ -4131,19 +4223,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4131
4223
  4,
4132
4224
  this.adController.play()
4133
4225
  ];
4134
- case 3:
4226
+ case 14:
4135
4227
  _state.sent();
4136
4228
  if (this.expectedAdBreakDurationMs != null) {
4137
4229
  this.currentAdBreakStartWallClockMs = Date.now();
4138
4230
  this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4139
4231
  }
4140
- adVolume = currentMuted ? 0 : currentVolume;
4232
+ adVolume = state.muted ? 0 : state.volume;
4141
4233
  this.adController.setAdVolume(adVolume);
4142
4234
  return [
4143
4235
  3,
4144
- 6
4236
+ 17
4145
4237
  ];
4146
- case 4:
4238
+ case 15:
4147
4239
  error = _state.sent();
4148
4240
  if (this.config.debugAdTiming) {
4149
4241
  console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
@@ -4153,13 +4245,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4153
4245
  4,
4154
4246
  this.tryNextAvailableAdWithRateLimit()
4155
4247
  ];
4156
- case 5:
4248
+ case 16:
4157
4249
  _state.sent();
4158
4250
  return [
4159
4251
  3,
4160
- 6
4252
+ 17
4161
4253
  ];
4162
- case 6:
4254
+ case 17:
4163
4255
  return [
4164
4256
  2
4165
4257
  ];