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.
@@ -40,6 +40,8 @@ declare class StormcloudVideoPlayer {
40
40
  private readonly maxTotalAdRequestsPerBreak;
41
41
  private pendingAdBreak;
42
42
  private prefetchTimerId;
43
+ private prefetchAdPromise;
44
+ private savedMutedStateBeforeScte;
43
45
  private consecutiveFailures;
44
46
  private readonly maxConsecutiveFailures;
45
47
  private lastAdRequestTime;
@@ -578,8 +578,8 @@ function createEmptyTrackingState() {
578
578
  complete: false
579
579
  };
580
580
  }
581
- function fireTrackingPixels(urls, sessionId, licenseKey) {
582
- var logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
581
+ function fireTrackingPixels(urls, sessionId) {
582
+ var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
583
583
  if (!urls || urls.length === 0) return;
584
584
  urls.forEach(function(url) {
585
585
  try {
@@ -587,10 +587,8 @@ function fireTrackingPixels(urls, sessionId, licenseKey) {
587
587
  if (sessionId) {
588
588
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
589
589
  }
590
- if (licenseKey) {
591
- trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "license_key=").concat(licenseKey);
592
- }
593
590
  var img = new Image(1, 1);
591
+ img.onerror = function() {};
594
592
  img.src = trackingUrl;
595
593
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
596
594
  } catch (error) {
@@ -991,7 +989,7 @@ function createPrebidController(contentVideo, options) {
991
989
  return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
992
990
  }
993
991
  function fireTrackingPixels2(urls) {
994
- fireTrackingPixels(urls, sessionId, licenseKey, LOG);
992
+ fireTrackingPixels(urls, sessionId, LOG);
995
993
  }
996
994
  function getMainStreamQuality() {
997
995
  if (!mainHlsInstance || !mainHlsInstance.levels) {
@@ -2728,6 +2726,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2728
2726
  this.totalAdRequestsInBreak = 0;
2729
2727
  this.maxTotalAdRequestsPerBreak = 20;
2730
2728
  this.pendingAdBreak = null;
2729
+ this.prefetchAdPromise = null;
2730
+ this.savedMutedStateBeforeScte = null;
2731
2731
  this.consecutiveFailures = 0;
2732
2732
  this.maxConsecutiveFailures = 5;
2733
2733
  this.lastAdRequestTime = 0;
@@ -3203,6 +3203,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3203
3203
  }
3204
3204
  }
3205
3205
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
3206
+ _this.adController.stop().catch(function() {});
3206
3207
  _this.handleAdFailure();
3207
3208
  });
3208
3209
  this.adController.on("content_pause", function() {
@@ -3265,6 +3266,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3265
3266
  {
3266
3267
  key: "recreateAdController",
3267
3268
  value: function recreateAdController() {
3269
+ this.prefetchAdPromise = null;
3268
3270
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3269
3271
  if (shouldShowPlaceholder && this.adController) {
3270
3272
  this.showPlaceholderLayer();
@@ -3593,6 +3595,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3593
3595
  if (marker.type === "start") {
3594
3596
  var _this_config_immediateManifestAds;
3595
3597
  var _this_pendingAdBreak;
3598
+ this.savedMutedStateBeforeScte = {
3599
+ muted: this.video.muted,
3600
+ volume: this.video.volume
3601
+ };
3602
+ this.adController.updateOriginalMutedState(this.video.muted, this.video.volume);
3596
3603
  if (!this.video.muted) {
3597
3604
  this.video.muted = true;
3598
3605
  this.video.volume = 0;
@@ -4034,6 +4041,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4034
4041
  {
4035
4042
  key: "startAdPrefetch",
4036
4043
  value: function startAdPrefetch(marker, fragmentSn) {
4044
+ var _this = this;
4037
4045
  if (this.pendingAdBreak || this.inAdBreak) {
4038
4046
  return;
4039
4047
  }
@@ -4045,8 +4053,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4045
4053
  isFetching: false,
4046
4054
  fetchStartTime: Date.now()
4047
4055
  });
4056
+ this.prefetchAdPromise = this.adController.requestAds().catch(function() {
4057
+ if (_this.config.debugAdTiming) {
4058
+ console.log("[PREFETCH] Prebid auction prefetch failed, will request at playback time");
4059
+ }
4060
+ });
4048
4061
  if (this.config.debugAdTiming) {
4049
- console.log("[PREFETCH] Ad break marker registered, auction runs at playback time via controller");
4062
+ console.log("[PREFETCH] Ad break marker registered, auction prefetch started");
4050
4063
  }
4051
4064
  }
4052
4065
  },
@@ -4057,6 +4070,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4057
4070
  clearTimeout(this.prefetchTimerId);
4058
4071
  this.prefetchTimerId = void 0;
4059
4072
  }
4073
+ this.prefetchAdPromise = null;
4060
4074
  this.pendingAdBreak = null;
4061
4075
  }
4062
4076
  },
@@ -4064,7 +4078,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4064
4078
  key: "handleAdStart",
4065
4079
  value: function handleAdStart(_marker) {
4066
4080
  return _async_to_generator(function() {
4067
- var adBreakDurationMs, mode, currentMuted, currentVolume, adLoadedInfo, adVolume, error;
4081
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, unused, unused1, adLoadedInfo, adVolume, error;
4068
4082
  return _ts_generator(this, function(_state) {
4069
4083
  switch(_state.label){
4070
4084
  case 0:
@@ -4077,9 +4091,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4077
4091
  this.continuousFetchingActive = true;
4078
4092
  this.isShowingPlaceholder = false;
4079
4093
  this.totalAdRequestsInBreak = 0;
4080
- currentMuted = this.video.muted;
4081
- currentVolume = this.video.volume;
4082
- this.adController.updateOriginalMutedState(currentMuted, currentVolume);
4094
+ state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4095
+ muted: this.video.muted,
4096
+ volume: this.video.volume
4097
+ };
4098
+ this.adController.updateOriginalMutedState(state.muted, state.volume);
4099
+ this.savedMutedStateBeforeScte = null;
4083
4100
  if (!this.video.muted) {
4084
4101
  this.video.muted = true;
4085
4102
  this.video.volume = 0;
@@ -4098,25 +4115,94 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4098
4115
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4099
4116
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4100
4117
  }
4101
- this.clearPendingAdBreak();
4102
4118
  if (this.config.debugAdTiming) {
4103
- console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction via requestAds()");
4119
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction (prefetch or requestAds)");
4104
4120
  }
4105
4121
  _state.label = 1;
4106
4122
  case 1:
4107
4123
  _state.trys.push([
4108
4124
  1,
4109
- 4,
4125
+ 6,
4110
4126
  ,
4111
- 6
4127
+ 12
4112
4128
  ]);
4113
4129
  this.lastAdRequestTime = Date.now();
4130
+ if (!this.prefetchAdPromise) return [
4131
+ 3,
4132
+ 3
4133
+ ];
4114
4134
  return [
4115
4135
  4,
4116
- this.adController.requestAds()
4136
+ this.prefetchAdPromise
4117
4137
  ];
4118
4138
  case 2:
4119
4139
  _state.sent();
4140
+ this.prefetchAdPromise = null;
4141
+ return [
4142
+ 3,
4143
+ 5
4144
+ ];
4145
+ case 3:
4146
+ return [
4147
+ 4,
4148
+ this.adController.requestAds()
4149
+ ];
4150
+ case 4:
4151
+ _state.sent();
4152
+ _state.label = 5;
4153
+ case 5:
4154
+ return [
4155
+ 3,
4156
+ 12
4157
+ ];
4158
+ case 6:
4159
+ unused = _state.sent();
4160
+ _state.label = 7;
4161
+ case 7:
4162
+ _state.trys.push([
4163
+ 7,
4164
+ 9,
4165
+ ,
4166
+ 11
4167
+ ]);
4168
+ return [
4169
+ 4,
4170
+ this.adController.requestAds()
4171
+ ];
4172
+ case 8:
4173
+ _state.sent();
4174
+ return [
4175
+ 3,
4176
+ 11
4177
+ ];
4178
+ case 9:
4179
+ unused1 = _state.sent();
4180
+ this.clearPendingAdBreak();
4181
+ this.consecutiveFailures++;
4182
+ return [
4183
+ 4,
4184
+ this.tryNextAvailableAdWithRateLimit()
4185
+ ];
4186
+ case 10:
4187
+ _state.sent();
4188
+ return [
4189
+ 2
4190
+ ];
4191
+ case 11:
4192
+ return [
4193
+ 3,
4194
+ 12
4195
+ ];
4196
+ case 12:
4197
+ this.clearPendingAdBreak();
4198
+ _state.label = 13;
4199
+ case 13:
4200
+ _state.trys.push([
4201
+ 13,
4202
+ 15,
4203
+ ,
4204
+ 17
4205
+ ]);
4120
4206
  if (this.config.licenseKey) {
4121
4207
  adLoadedInfo = {
4122
4208
  source: this.getAdSource(),
@@ -4133,19 +4219,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4133
4219
  4,
4134
4220
  this.adController.play()
4135
4221
  ];
4136
- case 3:
4222
+ case 14:
4137
4223
  _state.sent();
4138
4224
  if (this.expectedAdBreakDurationMs != null) {
4139
4225
  this.currentAdBreakStartWallClockMs = Date.now();
4140
4226
  this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4141
4227
  }
4142
- adVolume = currentMuted ? 0 : currentVolume;
4228
+ adVolume = state.muted ? 0 : state.volume;
4143
4229
  this.adController.setAdVolume(adVolume);
4144
4230
  return [
4145
4231
  3,
4146
- 6
4232
+ 17
4147
4233
  ];
4148
- case 4:
4234
+ case 15:
4149
4235
  error = _state.sent();
4150
4236
  if (this.config.debugAdTiming) {
4151
4237
  console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
@@ -4155,13 +4241,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4155
4241
  4,
4156
4242
  this.tryNextAvailableAdWithRateLimit()
4157
4243
  ];
4158
- case 5:
4244
+ case 16:
4159
4245
  _state.sent();
4160
4246
  return [
4161
4247
  3,
4162
- 6
4248
+ 17
4163
4249
  ];
4164
- case 6:
4250
+ case 17:
4165
4251
  return [
4166
4252
  2
4167
4253
  ];