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.cjs CHANGED
@@ -708,8 +708,8 @@ function createEmptyTrackingState() {
708
708
  complete: false
709
709
  };
710
710
  }
711
- function fireTrackingPixels(urls, sessionId, licenseKey) {
712
- var logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
711
+ function fireTrackingPixels(urls, sessionId) {
712
+ var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
713
713
  if (!urls || urls.length === 0) return;
714
714
  urls.forEach(function(url) {
715
715
  try {
@@ -717,10 +717,8 @@ function fireTrackingPixels(urls, sessionId, licenseKey) {
717
717
  if (sessionId) {
718
718
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
719
719
  }
720
- if (licenseKey) {
721
- trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "license_key=").concat(licenseKey);
722
- }
723
720
  var img = new Image(1, 1);
721
+ img.onerror = function() {};
724
722
  img.src = trackingUrl;
725
723
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
726
724
  } catch (error) {
@@ -1121,7 +1119,7 @@ function createPrebidController(contentVideo, options) {
1121
1119
  return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
1122
1120
  }
1123
1121
  function fireTrackingPixels2(urls) {
1124
- fireTrackingPixels(urls, sessionId, licenseKey, LOG);
1122
+ fireTrackingPixels(urls, sessionId, LOG);
1125
1123
  }
1126
1124
  function getMainStreamQuality() {
1127
1125
  if (!mainHlsInstance || !mainHlsInstance.levels) {
@@ -2883,6 +2881,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2883
2881
  this.totalAdRequestsInBreak = 0;
2884
2882
  this.maxTotalAdRequestsPerBreak = 20;
2885
2883
  this.pendingAdBreak = null;
2884
+ this.prefetchAdPromise = null;
2885
+ this.savedMutedStateBeforeScte = null;
2886
2886
  this.consecutiveFailures = 0;
2887
2887
  this.maxConsecutiveFailures = 5;
2888
2888
  this.lastAdRequestTime = 0;
@@ -3358,6 +3358,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3358
3358
  }
3359
3359
  }
3360
3360
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
3361
+ _this.adController.stop().catch(function() {});
3361
3362
  _this.handleAdFailure();
3362
3363
  });
3363
3364
  this.adController.on("content_pause", function() {
@@ -3420,6 +3421,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3420
3421
  {
3421
3422
  key: "recreateAdController",
3422
3423
  value: function recreateAdController() {
3424
+ this.prefetchAdPromise = null;
3423
3425
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
3424
3426
  if (shouldShowPlaceholder && this.adController) {
3425
3427
  this.showPlaceholderLayer();
@@ -3748,6 +3750,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3748
3750
  if (marker.type === "start") {
3749
3751
  var _this_config_immediateManifestAds;
3750
3752
  var _this_pendingAdBreak;
3753
+ this.savedMutedStateBeforeScte = {
3754
+ muted: this.video.muted,
3755
+ volume: this.video.volume
3756
+ };
3757
+ this.adController.updateOriginalMutedState(this.video.muted, this.video.volume);
3751
3758
  if (!this.video.muted) {
3752
3759
  this.video.muted = true;
3753
3760
  this.video.volume = 0;
@@ -4189,6 +4196,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4189
4196
  {
4190
4197
  key: "startAdPrefetch",
4191
4198
  value: function startAdPrefetch(marker, fragmentSn) {
4199
+ var _this = this;
4192
4200
  if (this.pendingAdBreak || this.inAdBreak) {
4193
4201
  return;
4194
4202
  }
@@ -4200,8 +4208,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4200
4208
  isFetching: false,
4201
4209
  fetchStartTime: Date.now()
4202
4210
  });
4211
+ this.prefetchAdPromise = this.adController.requestAds().catch(function() {
4212
+ if (_this.config.debugAdTiming) {
4213
+ console.log("[PREFETCH] Prebid auction prefetch failed, will request at playback time");
4214
+ }
4215
+ });
4203
4216
  if (this.config.debugAdTiming) {
4204
- console.log("[PREFETCH] Ad break marker registered, auction runs at playback time via controller");
4217
+ console.log("[PREFETCH] Ad break marker registered, auction prefetch started");
4205
4218
  }
4206
4219
  }
4207
4220
  },
@@ -4212,6 +4225,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4212
4225
  clearTimeout(this.prefetchTimerId);
4213
4226
  this.prefetchTimerId = void 0;
4214
4227
  }
4228
+ this.prefetchAdPromise = null;
4215
4229
  this.pendingAdBreak = null;
4216
4230
  }
4217
4231
  },
@@ -4219,7 +4233,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4219
4233
  key: "handleAdStart",
4220
4234
  value: function handleAdStart(_marker) {
4221
4235
  return _async_to_generator(function() {
4222
- var adBreakDurationMs, mode, currentMuted, currentVolume, adLoadedInfo, adVolume, error;
4236
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, unused, unused1, adLoadedInfo, adVolume, error;
4223
4237
  return _ts_generator(this, function(_state) {
4224
4238
  switch(_state.label){
4225
4239
  case 0:
@@ -4232,9 +4246,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4232
4246
  this.continuousFetchingActive = true;
4233
4247
  this.isShowingPlaceholder = false;
4234
4248
  this.totalAdRequestsInBreak = 0;
4235
- currentMuted = this.video.muted;
4236
- currentVolume = this.video.volume;
4237
- this.adController.updateOriginalMutedState(currentMuted, currentVolume);
4249
+ state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4250
+ muted: this.video.muted,
4251
+ volume: this.video.volume
4252
+ };
4253
+ this.adController.updateOriginalMutedState(state.muted, state.volume);
4254
+ this.savedMutedStateBeforeScte = null;
4238
4255
  if (!this.video.muted) {
4239
4256
  this.video.muted = true;
4240
4257
  this.video.volume = 0;
@@ -4253,25 +4270,94 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4253
4270
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4254
4271
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4255
4272
  }
4256
- this.clearPendingAdBreak();
4257
4273
  if (this.config.debugAdTiming) {
4258
- console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction via requestAds()");
4274
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDCCB Prebid auction (prefetch or requestAds)");
4259
4275
  }
4260
4276
  _state.label = 1;
4261
4277
  case 1:
4262
4278
  _state.trys.push([
4263
4279
  1,
4264
- 4,
4280
+ 6,
4265
4281
  ,
4266
- 6
4282
+ 12
4267
4283
  ]);
4268
4284
  this.lastAdRequestTime = Date.now();
4285
+ if (!this.prefetchAdPromise) return [
4286
+ 3,
4287
+ 3
4288
+ ];
4269
4289
  return [
4270
4290
  4,
4271
- this.adController.requestAds()
4291
+ this.prefetchAdPromise
4272
4292
  ];
4273
4293
  case 2:
4274
4294
  _state.sent();
4295
+ this.prefetchAdPromise = null;
4296
+ return [
4297
+ 3,
4298
+ 5
4299
+ ];
4300
+ case 3:
4301
+ return [
4302
+ 4,
4303
+ this.adController.requestAds()
4304
+ ];
4305
+ case 4:
4306
+ _state.sent();
4307
+ _state.label = 5;
4308
+ case 5:
4309
+ return [
4310
+ 3,
4311
+ 12
4312
+ ];
4313
+ case 6:
4314
+ unused = _state.sent();
4315
+ _state.label = 7;
4316
+ case 7:
4317
+ _state.trys.push([
4318
+ 7,
4319
+ 9,
4320
+ ,
4321
+ 11
4322
+ ]);
4323
+ return [
4324
+ 4,
4325
+ this.adController.requestAds()
4326
+ ];
4327
+ case 8:
4328
+ _state.sent();
4329
+ return [
4330
+ 3,
4331
+ 11
4332
+ ];
4333
+ case 9:
4334
+ unused1 = _state.sent();
4335
+ this.clearPendingAdBreak();
4336
+ this.consecutiveFailures++;
4337
+ return [
4338
+ 4,
4339
+ this.tryNextAvailableAdWithRateLimit()
4340
+ ];
4341
+ case 10:
4342
+ _state.sent();
4343
+ return [
4344
+ 2
4345
+ ];
4346
+ case 11:
4347
+ return [
4348
+ 3,
4349
+ 12
4350
+ ];
4351
+ case 12:
4352
+ this.clearPendingAdBreak();
4353
+ _state.label = 13;
4354
+ case 13:
4355
+ _state.trys.push([
4356
+ 13,
4357
+ 15,
4358
+ ,
4359
+ 17
4360
+ ]);
4275
4361
  if (this.config.licenseKey) {
4276
4362
  adLoadedInfo = {
4277
4363
  source: this.getAdSource(),
@@ -4288,19 +4374,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4288
4374
  4,
4289
4375
  this.adController.play()
4290
4376
  ];
4291
- case 3:
4377
+ case 14:
4292
4378
  _state.sent();
4293
4379
  if (this.expectedAdBreakDurationMs != null) {
4294
4380
  this.currentAdBreakStartWallClockMs = Date.now();
4295
4381
  this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4296
4382
  }
4297
- adVolume = currentMuted ? 0 : currentVolume;
4383
+ adVolume = state.muted ? 0 : state.volume;
4298
4384
  this.adController.setAdVolume(adVolume);
4299
4385
  return [
4300
4386
  3,
4301
- 6
4387
+ 17
4302
4388
  ];
4303
- case 4:
4389
+ case 15:
4304
4390
  error = _state.sent();
4305
4391
  if (this.config.debugAdTiming) {
4306
4392
  console.warn("[CONTINUOUS-FETCH] \u26A0\uFE0F First ad request failed:", error);
@@ -4310,13 +4396,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4310
4396
  4,
4311
4397
  this.tryNextAvailableAdWithRateLimit()
4312
4398
  ];
4313
- case 5:
4399
+ case 16:
4314
4400
  _state.sent();
4315
4401
  return [
4316
4402
  3,
4317
- 6
4403
+ 17
4318
4404
  ];
4319
- case 6:
4405
+ case 17:
4320
4406
  return [
4321
4407
  2
4322
4408
  ];