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.
@@ -614,8 +614,8 @@ function createEmptyTrackingState() {
614
614
  complete: false
615
615
  };
616
616
  }
617
- function fireTrackingPixels(urls, sessionId, licenseKey) {
618
- var logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
617
+ function fireTrackingPixels(urls, sessionId) {
618
+ var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
619
619
  if (!urls || urls.length === 0) return;
620
620
  urls.forEach(function(url) {
621
621
  try {
@@ -623,10 +623,8 @@ function fireTrackingPixels(urls, sessionId, licenseKey) {
623
623
  if (sessionId) {
624
624
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
625
625
  }
626
- if (licenseKey) {
627
- trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "license_key=").concat(licenseKey);
628
- }
629
626
  var img = new Image(1, 1);
627
+ img.onerror = function() {};
630
628
  img.src = trackingUrl;
631
629
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
632
630
  } catch (error) {
@@ -1027,7 +1025,7 @@ function createPrebidController(contentVideo, options) {
1027
1025
  return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
1028
1026
  }
1029
1027
  function fireTrackingPixels2(urls) {
1030
- fireTrackingPixels(urls, sessionId, licenseKey, LOG);
1028
+ fireTrackingPixels(urls, sessionId, LOG);
1031
1029
  }
1032
1030
  function getMainStreamQuality() {
1033
1031
  if (!mainHlsInstance || !mainHlsInstance.levels) {
@@ -2764,6 +2762,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2764
2762
  this.totalAdRequestsInBreak = 0;
2765
2763
  this.maxTotalAdRequestsPerBreak = 20;
2766
2764
  this.pendingAdBreak = null;
2765
+ this.prefetchAdPromise = null;
2766
+ this.savedMutedStateBeforeScte = null;
2767
2767
  this.consecutiveFailures = 0;
2768
2768
  this.maxConsecutiveFailures = 5;
2769
2769
  this.lastAdRequestTime = 0;
@@ -3239,6 +3239,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3239
3239
  }
3240
3240
  }
3241
3241
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
3242
+ _this.adController.stop().catch(function() {});
3242
3243
  _this.handleAdFailure();
3243
3244
  });
3244
3245
  this.adController.on("content_pause", function() {
@@ -3281,6 +3282,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3281
3282
  _this.activeAdRequestToken = null;
3282
3283
  _this.showAds = false;
3283
3284
  if (!_this.inAdBreak) {
3285
+ if (_this.config.debugAdTiming) {
3286
+ console.log("[StormcloudVideoPlayer] content_resume: break already ended (e.g. by CUE-IN or handleAdPodComplete), skipping next-ad path");
3287
+ }
3284
3288
  return;
3285
3289
  }
3286
3290
  _this.consecutiveFailures = 0;
@@ -3293,6 +3297,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3293
3297
  if (remaining > 500) {
3294
3298
  _this.tryNextAvailableAdWithRateLimit();
3295
3299
  } else {
3300
+ if (_this.config.debugAdTiming) {
3301
+ console.log("[StormcloudVideoPlayer] content_resume: remaining time too low to try next ad, ending ad pod");
3302
+ }
3296
3303
  _this.handleAdPodComplete();
3297
3304
  }
3298
3305
  });
@@ -3301,6 +3308,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3301
3308
  {
3302
3309
  key: "recreateAdController",
3303
3310
  value: function recreateAdController() {
3311
+ this.prefetchAdPromise = null;
3304
3312
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3305
3313
  if (shouldShowPlaceholder && this.adController) {
3306
3314
  this.showPlaceholderLayer();
@@ -3629,6 +3637,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3629
3637
  if (marker.type === "start") {
3630
3638
  var _this_config_immediateManifestAds;
3631
3639
  var _this_pendingAdBreak;
3640
+ this.savedMutedStateBeforeScte = {
3641
+ muted: this.video.muted,
3642
+ volume: this.video.volume
3643
+ };
3644
+ this.adController.updateOriginalMutedState(this.video.muted, this.video.volume);
3632
3645
  if (!this.video.muted) {
3633
3646
  this.video.muted = true;
3634
3647
  this.video.volume = 0;
@@ -3751,9 +3764,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3751
3764
  activeAdRequest: this.activeAdRequestToken !== null
3752
3765
  });
3753
3766
  }
3754
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
3767
+ if (adPlaying || remaining > 500) {
3755
3768
  if (this.config.debugAdTiming) {
3756
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
3769
+ console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active or time remaining");
3757
3770
  }
3758
3771
  return;
3759
3772
  }
@@ -4070,6 +4083,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4070
4083
  {
4071
4084
  key: "startAdPrefetch",
4072
4085
  value: function startAdPrefetch(marker, fragmentSn) {
4086
+ var _this = this;
4073
4087
  if (this.pendingAdBreak || this.inAdBreak) {
4074
4088
  return;
4075
4089
  }
@@ -4081,8 +4095,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4081
4095
  isFetching: false,
4082
4096
  fetchStartTime: Date.now()
4083
4097
  });
4098
+ this.prefetchAdPromise = this.adController.requestAds().catch(function() {
4099
+ if (_this.config.debugAdTiming) {
4100
+ console.log("[PREFETCH] Prebid auction prefetch failed, will request at playback time");
4101
+ }
4102
+ });
4084
4103
  if (this.config.debugAdTiming) {
4085
- console.log("[PREFETCH] Ad break marker registered, auction runs at playback time via controller");
4104
+ console.log("[PREFETCH] Ad break marker registered, auction prefetch started");
4086
4105
  }
4087
4106
  }
4088
4107
  },
@@ -4093,6 +4112,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4093
4112
  clearTimeout(this.prefetchTimerId);
4094
4113
  this.prefetchTimerId = void 0;
4095
4114
  }
4115
+ this.prefetchAdPromise = null;
4096
4116
  this.pendingAdBreak = null;
4097
4117
  }
4098
4118
  },
@@ -4100,7 +4120,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4100
4120
  key: "handleAdStart",
4101
4121
  value: function handleAdStart(_marker) {
4102
4122
  return _async_to_generator(function() {
4103
- var adBreakDurationMs, mode, currentMuted, currentVolume, adLoadedInfo, adVolume, error;
4123
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, unused, unused1, adLoadedInfo, adVolume, error;
4104
4124
  return _ts_generator(this, function(_state) {
4105
4125
  switch(_state.label){
4106
4126
  case 0:
@@ -4113,9 +4133,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4113
4133
  this.continuousFetchingActive = true;
4114
4134
  this.isShowingPlaceholder = false;
4115
4135
  this.totalAdRequestsInBreak = 0;
4116
- currentMuted = this.video.muted;
4117
- currentVolume = this.video.volume;
4118
- this.adController.updateOriginalMutedState(currentMuted, currentVolume);
4136
+ state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4137
+ muted: this.video.muted,
4138
+ volume: this.video.volume
4139
+ };
4140
+ this.adController.updateOriginalMutedState(state.muted, state.volume);
4141
+ this.savedMutedStateBeforeScte = null;
4119
4142
  if (!this.video.muted) {
4120
4143
  this.video.muted = true;
4121
4144
  this.video.volume = 0;
@@ -4134,25 +4157,94 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4134
4157
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4135
4158
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4136
4159
  }
4137
- this.clearPendingAdBreak();
4138
4160
  if (this.config.debugAdTiming) {
4139
- console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction via requestAds()");
4161
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction (prefetch or requestAds)");
4140
4162
  }
4141
4163
  _state.label = 1;
4142
4164
  case 1:
4143
4165
  _state.trys.push([
4144
4166
  1,
4145
- 4,
4167
+ 6,
4146
4168
  ,
4147
- 6
4169
+ 12
4148
4170
  ]);
4149
4171
  this.lastAdRequestTime = Date.now();
4172
+ if (!this.prefetchAdPromise) return [
4173
+ 3,
4174
+ 3
4175
+ ];
4150
4176
  return [
4151
4177
  4,
4152
- this.adController.requestAds()
4178
+ this.prefetchAdPromise
4153
4179
  ];
4154
4180
  case 2:
4155
4181
  _state.sent();
4182
+ this.prefetchAdPromise = null;
4183
+ return [
4184
+ 3,
4185
+ 5
4186
+ ];
4187
+ case 3:
4188
+ return [
4189
+ 4,
4190
+ this.adController.requestAds()
4191
+ ];
4192
+ case 4:
4193
+ _state.sent();
4194
+ _state.label = 5;
4195
+ case 5:
4196
+ return [
4197
+ 3,
4198
+ 12
4199
+ ];
4200
+ case 6:
4201
+ unused = _state.sent();
4202
+ _state.label = 7;
4203
+ case 7:
4204
+ _state.trys.push([
4205
+ 7,
4206
+ 9,
4207
+ ,
4208
+ 11
4209
+ ]);
4210
+ return [
4211
+ 4,
4212
+ this.adController.requestAds()
4213
+ ];
4214
+ case 8:
4215
+ _state.sent();
4216
+ return [
4217
+ 3,
4218
+ 11
4219
+ ];
4220
+ case 9:
4221
+ unused1 = _state.sent();
4222
+ this.clearPendingAdBreak();
4223
+ this.consecutiveFailures++;
4224
+ return [
4225
+ 4,
4226
+ this.tryNextAvailableAdWithRateLimit()
4227
+ ];
4228
+ case 10:
4229
+ _state.sent();
4230
+ return [
4231
+ 2
4232
+ ];
4233
+ case 11:
4234
+ return [
4235
+ 3,
4236
+ 12
4237
+ ];
4238
+ case 12:
4239
+ this.clearPendingAdBreak();
4240
+ _state.label = 13;
4241
+ case 13:
4242
+ _state.trys.push([
4243
+ 13,
4244
+ 15,
4245
+ ,
4246
+ 17
4247
+ ]);
4156
4248
  if (this.config.licenseKey) {
4157
4249
  adLoadedInfo = {
4158
4250
  source: this.getAdSource(),
@@ -4169,19 +4261,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4169
4261
  4,
4170
4262
  this.adController.play()
4171
4263
  ];
4172
- case 3:
4264
+ case 14:
4173
4265
  _state.sent();
4174
4266
  if (this.expectedAdBreakDurationMs != null) {
4175
4267
  this.currentAdBreakStartWallClockMs = Date.now();
4176
4268
  this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4177
4269
  }
4178
- adVolume = currentMuted ? 0 : currentVolume;
4270
+ adVolume = state.muted ? 0 : state.volume;
4179
4271
  this.adController.setAdVolume(adVolume);
4180
4272
  return [
4181
4273
  3,
4182
- 6
4274
+ 17
4183
4275
  ];
4184
- case 4:
4276
+ case 15:
4185
4277
  error = _state.sent();
4186
4278
  if (this.config.debugAdTiming) {
4187
4279
  console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
@@ -4191,13 +4283,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4191
4283
  4,
4192
4284
  this.tryNextAvailableAdWithRateLimit()
4193
4285
  ];
4194
- case 5:
4286
+ case 16:
4195
4287
  _state.sent();
4196
4288
  return [
4197
4289
  3,
4198
- 6
4290
+ 17
4199
4291
  ];
4200
- case 6:
4292
+ case 17:
4201
4293
  return [
4202
4294
  2
4203
4295
  ];