stormcloud-video-player 0.5.7 → 0.5.8

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() {
@@ -3263,6 +3264,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3263
3264
  {
3264
3265
  key: "recreateAdController",
3265
3266
  value: function recreateAdController() {
3267
+ this.prefetchAdPromise = null;
3266
3268
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3267
3269
  if (shouldShowPlaceholder && this.adController) {
3268
3270
  this.showPlaceholderLayer();
@@ -3591,6 +3593,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3591
3593
  if (marker.type === "start") {
3592
3594
  var _this_config_immediateManifestAds;
3593
3595
  var _this_pendingAdBreak;
3596
+ this.savedMutedStateBeforeScte = {
3597
+ muted: this.video.muted,
3598
+ volume: this.video.volume
3599
+ };
3600
+ this.adController.updateOriginalMutedState(this.video.muted, this.video.volume);
3594
3601
  if (!this.video.muted) {
3595
3602
  this.video.muted = true;
3596
3603
  this.video.volume = 0;
@@ -4032,6 +4039,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4032
4039
  {
4033
4040
  key: "startAdPrefetch",
4034
4041
  value: function startAdPrefetch(marker, fragmentSn) {
4042
+ var _this = this;
4035
4043
  if (this.pendingAdBreak || this.inAdBreak) {
4036
4044
  return;
4037
4045
  }
@@ -4043,8 +4051,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4043
4051
  isFetching: false,
4044
4052
  fetchStartTime: Date.now()
4045
4053
  });
4054
+ this.prefetchAdPromise = this.adController.requestAds().catch(function() {
4055
+ if (_this.config.debugAdTiming) {
4056
+ console.log("[PREFETCH] Prebid auction prefetch failed, will request at playback time");
4057
+ }
4058
+ });
4046
4059
  if (this.config.debugAdTiming) {
4047
- console.log("[PREFETCH] Ad break marker registered, auction runs at playback time via controller");
4060
+ console.log("[PREFETCH] Ad break marker registered, auction prefetch started");
4048
4061
  }
4049
4062
  }
4050
4063
  },
@@ -4055,6 +4068,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4055
4068
  clearTimeout(this.prefetchTimerId);
4056
4069
  this.prefetchTimerId = void 0;
4057
4070
  }
4071
+ this.prefetchAdPromise = null;
4058
4072
  this.pendingAdBreak = null;
4059
4073
  }
4060
4074
  },
@@ -4062,7 +4076,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4062
4076
  key: "handleAdStart",
4063
4077
  value: function handleAdStart(_marker) {
4064
4078
  return _async_to_generator(function() {
4065
- var adBreakDurationMs, mode, currentMuted, currentVolume, adLoadedInfo, adVolume, error;
4079
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, unused, unused1, adLoadedInfo, adVolume, error;
4066
4080
  return _ts_generator(this, function(_state) {
4067
4081
  switch(_state.label){
4068
4082
  case 0:
@@ -4075,9 +4089,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4075
4089
  this.continuousFetchingActive = true;
4076
4090
  this.isShowingPlaceholder = false;
4077
4091
  this.totalAdRequestsInBreak = 0;
4078
- currentMuted = this.video.muted;
4079
- currentVolume = this.video.volume;
4080
- this.adController.updateOriginalMutedState(currentMuted, currentVolume);
4092
+ state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4093
+ muted: this.video.muted,
4094
+ volume: this.video.volume
4095
+ };
4096
+ this.adController.updateOriginalMutedState(state.muted, state.volume);
4097
+ this.savedMutedStateBeforeScte = null;
4081
4098
  if (!this.video.muted) {
4082
4099
  this.video.muted = true;
4083
4100
  this.video.volume = 0;
@@ -4096,25 +4113,94 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4096
4113
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4097
4114
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4098
4115
  }
4099
- this.clearPendingAdBreak();
4100
4116
  if (this.config.debugAdTiming) {
4101
- console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction via requestAds()");
4117
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction (prefetch or requestAds)");
4102
4118
  }
4103
4119
  _state.label = 1;
4104
4120
  case 1:
4105
4121
  _state.trys.push([
4106
4122
  1,
4107
- 4,
4123
+ 6,
4108
4124
  ,
4109
- 6
4125
+ 12
4110
4126
  ]);
4111
4127
  this.lastAdRequestTime = Date.now();
4128
+ if (!this.prefetchAdPromise) return [
4129
+ 3,
4130
+ 3
4131
+ ];
4112
4132
  return [
4113
4133
  4,
4114
- this.adController.requestAds()
4134
+ this.prefetchAdPromise
4115
4135
  ];
4116
4136
  case 2:
4117
4137
  _state.sent();
4138
+ this.prefetchAdPromise = null;
4139
+ return [
4140
+ 3,
4141
+ 5
4142
+ ];
4143
+ case 3:
4144
+ return [
4145
+ 4,
4146
+ this.adController.requestAds()
4147
+ ];
4148
+ case 4:
4149
+ _state.sent();
4150
+ _state.label = 5;
4151
+ case 5:
4152
+ return [
4153
+ 3,
4154
+ 12
4155
+ ];
4156
+ case 6:
4157
+ unused = _state.sent();
4158
+ _state.label = 7;
4159
+ case 7:
4160
+ _state.trys.push([
4161
+ 7,
4162
+ 9,
4163
+ ,
4164
+ 11
4165
+ ]);
4166
+ return [
4167
+ 4,
4168
+ this.adController.requestAds()
4169
+ ];
4170
+ case 8:
4171
+ _state.sent();
4172
+ return [
4173
+ 3,
4174
+ 11
4175
+ ];
4176
+ case 9:
4177
+ unused1 = _state.sent();
4178
+ this.clearPendingAdBreak();
4179
+ this.consecutiveFailures++;
4180
+ return [
4181
+ 4,
4182
+ this.tryNextAvailableAdWithRateLimit()
4183
+ ];
4184
+ case 10:
4185
+ _state.sent();
4186
+ return [
4187
+ 2
4188
+ ];
4189
+ case 11:
4190
+ return [
4191
+ 3,
4192
+ 12
4193
+ ];
4194
+ case 12:
4195
+ this.clearPendingAdBreak();
4196
+ _state.label = 13;
4197
+ case 13:
4198
+ _state.trys.push([
4199
+ 13,
4200
+ 15,
4201
+ ,
4202
+ 17
4203
+ ]);
4118
4204
  if (this.config.licenseKey) {
4119
4205
  adLoadedInfo = {
4120
4206
  source: this.getAdSource(),
@@ -4131,19 +4217,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4131
4217
  4,
4132
4218
  this.adController.play()
4133
4219
  ];
4134
- case 3:
4220
+ case 14:
4135
4221
  _state.sent();
4136
4222
  if (this.expectedAdBreakDurationMs != null) {
4137
4223
  this.currentAdBreakStartWallClockMs = Date.now();
4138
4224
  this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4139
4225
  }
4140
- adVolume = currentMuted ? 0 : currentVolume;
4226
+ adVolume = state.muted ? 0 : state.volume;
4141
4227
  this.adController.setAdVolume(adVolume);
4142
4228
  return [
4143
4229
  3,
4144
- 6
4230
+ 17
4145
4231
  ];
4146
- case 4:
4232
+ case 15:
4147
4233
  error = _state.sent();
4148
4234
  if (this.config.debugAdTiming) {
4149
4235
  console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
@@ -4153,13 +4239,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4153
4239
  4,
4154
4240
  this.tryNextAvailableAdWithRateLimit()
4155
4241
  ];
4156
- case 5:
4242
+ case 16:
4157
4243
  _state.sent();
4158
4244
  return [
4159
4245
  3,
4160
- 6
4246
+ 17
4161
4247
  ];
4162
- case 6:
4248
+ case 17:
4163
4249
  return [
4164
4250
  2
4165
4251
  ];