stormcloud-video-player 0.8.64 → 0.8.65

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.
@@ -1309,6 +1309,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1309
1309
  this.adDetectSentForCurrentBreak = false;
1310
1310
  this.continuousFetchingActive = false;
1311
1311
  this.continuousFetchLoopRunning = false;
1312
+ this.breakFunnel = {};
1313
+ this.controllerCallInFlight = false;
1314
+ this.playbackStartedForCurrentRequest = false;
1315
+ this.opportunityEpoch = -1;
1312
1316
  this.adRequestQueue = [];
1313
1317
  this.adPodQueue = [];
1314
1318
  this.maxPlaceholderDurationMs = 5e3;
@@ -1361,7 +1365,25 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1361
1365
  adPlayer.on("ad_interaction", function(event) {
1362
1366
  if (event) _this.host.onAdInteraction(event);
1363
1367
  });
1368
+ adPlayer.on("ad_funnel", function(payload) {
1369
+ if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
1370
+ _this.countFunnelStage(payload.stage);
1371
+ if (payload.reason) {
1372
+ _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
1373
+ }
1374
+ if (payload.stage === "impression_fired" && payload.pixelCount != null) {
1375
+ _this.countFunnelStage("impression_urls", payload.pixelCount);
1376
+ }
1377
+ if (payload.visibilityState === "hidden") {
1378
+ _this.countFunnelStage("while_hidden");
1379
+ }
1380
+ });
1364
1381
  adPlayer.on("ad_impression", function() {
1382
+ _this.timing.consecutiveFailures = 0;
1383
+ if (!_this.playbackStartedForCurrentRequest) {
1384
+ _this.playbackStartedForCurrentRequest = true;
1385
+ _this.timing.markAdStarted();
1386
+ }
1365
1387
  sendAdImpressionTracking(_this.host.config.licenseKey, _object_spread_props(_object_spread({
1366
1388
  source: "hls",
1367
1389
  adIndex: _this.timing.currentAdIndex
@@ -1405,6 +1427,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1405
1427
  }
1406
1428
  }
1407
1429
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
1430
+ if (_this.controllerCallInFlight) {
1431
+ _this.timing.recordGamNoFill();
1432
+ return;
1433
+ }
1408
1434
  _this.handleAdFailure();
1409
1435
  });
1410
1436
  adPlayer.on("content_pause", function() {
@@ -1476,6 +1502,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1476
1502
  }
1477
1503
  var preservedMutedState = adPlayer.getOriginalMutedState();
1478
1504
  var preservedVolumeState = adPlayer.getOriginalVolume();
1505
+ this.playbackStartedForCurrentRequest = false;
1479
1506
  if (adPlayer) {
1480
1507
  try {
1481
1508
  adPlayer.destroy();
@@ -1565,9 +1592,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1565
1592
  if (this.timing.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
1566
1593
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
1567
1594
  }
1595
+ this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
1568
1596
  return [
1569
1597
  4,
1570
- this.startOptimizedPod(baseVastUrl, adBreakDurationMs, currentMuted, currentVolume)
1598
+ this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
1571
1599
  ];
1572
1600
  case 1:
1573
1601
  podPlayed = _state.sent();
@@ -1601,7 +1629,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1601
1629
  value: // ───────────────────────────────────────────────────────────────
1602
1630
  // Optimized pod (single multi-ad request)
1603
1631
  // ───────────────────────────────────────────────────────────────
1604
- function startOptimizedPod(baseVastUrl, breakDurationMs, currentMuted, currentVolume) {
1632
+ function startOptimizedPod(baseVastUrl, breakDurationMs) {
1605
1633
  return _async_to_generator(function() {
1606
1634
  var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
1607
1635
  return _ts_generator(this, function(_state) {
@@ -1640,10 +1668,13 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1640
1668
  case 2:
1641
1669
  _state.sent();
1642
1670
  this.timing.startAdRequestWatchdog(requestToken);
1643
- this.timing.lastAdRequestTime = Date.now();
1671
+ this.timing.noteAdRequestSent();
1672
+ this.beginFunnelRequest(adPlayer, requestToken);
1644
1673
  return [
1645
1674
  4,
1646
- adPlayer.requestAds(podUrl)
1675
+ this.callController(function() {
1676
+ return adPlayer.requestAds(podUrl);
1677
+ })
1647
1678
  ];
1648
1679
  case 3:
1649
1680
  _state.sent();
@@ -1672,16 +1703,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
1672
1703
  this.timing.startAdFailsafeTimer(requestToken);
1673
1704
  return [
1674
1705
  4,
1675
- adPlayer.play()
1706
+ this.callController(function() {
1707
+ return adPlayer.play();
1708
+ })
1676
1709
  ];
1677
1710
  case 4:
1678
1711
  _state.sent();
1679
- this.timing.markAdStarted();
1680
1712
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
1681
1713
  this.timing.scheduleAdStopAtBreakBoundary();
1682
1714
  }
1683
- adPlayer.setAdVolume(currentMuted ? 0 : currentVolume);
1684
- this.timing.consecutiveFailures = 0;
1715
+ adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
1685
1716
  this.continuousFetchingActive = true;
1686
1717
  this.startContinuousFetching(baseVastUrl);
1687
1718
  return [
@@ -2046,7 +2077,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2046
2077
  ];
2047
2078
  case 3:
2048
2079
  _state.sent();
2049
- this.timing.consecutiveFailures = 0;
2050
2080
  return [
2051
2081
  3,
2052
2082
  8
@@ -2059,6 +2089,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2059
2089
  3,
2060
2090
  6
2061
2091
  ];
2092
+ this.timing.consecutiveFailures++;
2062
2093
  return [
2063
2094
  4,
2064
2095
  this.tryNextAvailableAdWithRateLimit()
@@ -2150,11 +2181,137 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2150
2181
  }
2151
2182
  }
2152
2183
  },
2184
+ {
2185
+ key: "countFunnelStage",
2186
+ value: function countFunnelStage(stage) {
2187
+ var amount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
2188
+ var _this_breakFunnel_stage;
2189
+ this.breakFunnel[stage] = ((_this_breakFunnel_stage = this.breakFunnel[stage]) !== null && _this_breakFunnel_stage !== void 0 ? _this_breakFunnel_stage : 0) + amount;
2190
+ }
2191
+ },
2192
+ {
2193
+ key: "logOrchestratorFunnel",
2194
+ value: function logOrchestratorFunnel(stage) {
2195
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2196
+ this.countFunnelStage(stage);
2197
+ console.log("[AdBreak][FUNNEL] ".concat(stage), _object_spread({
2198
+ breakId: this.timing.adBreakEpoch,
2199
+ requestId: this.currentRequestId,
2200
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0
2201
+ }, extra));
2202
+ }
2203
+ },
2204
+ {
2205
+ key: "noteOpportunity",
2206
+ value: function noteOpportunity(source, breakKey) {
2207
+ if (breakKey && breakKey === this.opportunityBreakKey && this.opportunityEpoch === this.timing.adBreakEpoch) {
2208
+ this.logOrchestratorFunnel("duplicate_break_start", {
2209
+ source: source,
2210
+ breakKey: breakKey
2211
+ });
2212
+ return;
2213
+ }
2214
+ this.opportunityBreakKey = breakKey;
2215
+ this.opportunityEpoch = this.timing.adBreakEpoch;
2216
+ this.logOrchestratorFunnel("opportunity_created", {
2217
+ source: source,
2218
+ breakKey: breakKey,
2219
+ expectedDurationMs: this.timing.expectedAdBreakDurationMs
2220
+ });
2221
+ }
2222
+ },
2223
+ {
2224
+ key: "beginFunnelRequest",
2225
+ value: function beginFunnelRequest(adPlayer, requestToken) {
2226
+ var _adPlayer_setFunnelContext;
2227
+ if (this.controllerCallInFlight) {
2228
+ this.logOrchestratorFunnel("duplicate_request_detected", {
2229
+ newRequestId: requestToken
2230
+ });
2231
+ }
2232
+ this.currentRequestId = requestToken;
2233
+ this.requestStartedAt = Date.now();
2234
+ (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
2235
+ breakId: this.timing.adBreakEpoch,
2236
+ requestId: requestToken
2237
+ });
2238
+ }
2239
+ },
2240
+ {
2241
+ key: "isAdLoadingWithoutPlayback",
2242
+ value: function isAdLoadingWithoutPlayback() {
2243
+ return this.host.getAdPlayer().isAdPlaying() && !this.playbackStartedForCurrentRequest;
2244
+ }
2245
+ },
2246
+ {
2247
+ key: "noteStopBeforeStart",
2248
+ value: function noteStopBeforeStart(reason) {
2249
+ if (!this.isAdLoadingWithoutPlayback()) return;
2250
+ this.logOrchestratorFunnel("ad_stopped_before_start", {
2251
+ reason: reason,
2252
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
2253
+ });
2254
+ }
2255
+ },
2256
+ {
2257
+ key: "handleRequestWatchdogTimeout",
2258
+ value: function handleRequestWatchdogTimeout() {
2259
+ var adPlayer = this.host.getAdPlayer();
2260
+ if (this.controllerCallInFlight && adPlayer.abortPendingRequest) {
2261
+ this.logOrchestratorFunnel("request_aborted_timeout", {
2262
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
2263
+ });
2264
+ adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
2265
+ return;
2266
+ }
2267
+ this.handleAdFailure();
2268
+ }
2269
+ },
2270
+ {
2271
+ key: "callController",
2272
+ value: function callController(call) {
2273
+ return _async_to_generator(function() {
2274
+ return _ts_generator(this, function(_state) {
2275
+ switch(_state.label){
2276
+ case 0:
2277
+ this.controllerCallInFlight = true;
2278
+ _state.label = 1;
2279
+ case 1:
2280
+ _state.trys.push([
2281
+ 1,
2282
+ ,
2283
+ 3,
2284
+ 4
2285
+ ]);
2286
+ return [
2287
+ 4,
2288
+ call()
2289
+ ];
2290
+ case 2:
2291
+ _state.sent();
2292
+ return [
2293
+ 3,
2294
+ 4
2295
+ ];
2296
+ case 3:
2297
+ this.controllerCallInFlight = false;
2298
+ return [
2299
+ 7
2300
+ ];
2301
+ case 4:
2302
+ return [
2303
+ 2
2304
+ ];
2305
+ }
2306
+ });
2307
+ }).call(this);
2308
+ }
2309
+ },
2153
2310
  {
2154
2311
  key: "playSingleAd",
2155
2312
  value: function playSingleAd(vastTagUrl) {
2156
2313
  return _async_to_generator(function() {
2157
- var adPlayer, requestToken, ap, requestUrl, playError, error, errorMessage;
2314
+ var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
2158
2315
  return _ts_generator(this, function(_state) {
2159
2316
  switch(_state.label){
2160
2317
  case 0:
@@ -2196,13 +2353,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2196
2353
  case 2:
2197
2354
  _state.sent();
2198
2355
  this.timing.startAdRequestWatchdog(requestToken);
2199
- this.timing.lastAdRequestTime = Date.now();
2356
+ this.timing.noteAdRequestSent();
2200
2357
  ap = this.host.getAdPlayer();
2201
2358
  requestUrl = this.withCurrentPodBudget(vastTagUrl);
2202
2359
  this.currentVastUrl = requestUrl;
2360
+ this.beginFunnelRequest(ap, requestToken);
2203
2361
  return [
2204
2362
  4,
2205
- ap.requestAds(requestUrl)
2363
+ this.callController(function() {
2364
+ return ap.requestAds(requestUrl);
2365
+ })
2206
2366
  ];
2207
2367
  case 3:
2208
2368
  _state.sent();
@@ -2216,6 +2376,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2216
2376
  2
2217
2377
  ];
2218
2378
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
2379
+ ;
2380
+ adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
2381
+ remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
2382
+ this.logOrchestratorFunnel("discarded_budget", {
2383
+ vastUrl: requestUrl,
2384
+ adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
2385
+ remainingMs: remainingMs
2386
+ });
2219
2387
  this.timing.rejectLoadedAdForDuration(ap);
2220
2388
  this.recreateAdController();
2221
2389
  throw new Error("ad_duration_exceeds_budget");
@@ -2231,16 +2399,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2231
2399
  this.timing.startAdFailsafeTimer(requestToken);
2232
2400
  return [
2233
2401
  4,
2234
- ap.play()
2402
+ this.callController(function() {
2403
+ return ap.play();
2404
+ })
2235
2405
  ];
2236
2406
  case 5:
2237
2407
  _state.sent();
2238
- this.timing.markAdStarted();
2239
2408
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
2240
2409
  this.timing.scheduleAdStopAtBreakBoundary();
2241
2410
  }
2242
2411
  ap.setAdVolume(getAdAudioVolume(ap));
2243
- this.timing.consecutiveFailures = 0;
2244
2412
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
2245
2413
  return [
2246
2414
  3,
@@ -2404,7 +2572,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2404
2572
  ];
2405
2573
  case 5:
2406
2574
  _state.sent();
2407
- this.timing.consecutiveFailures = 0;
2408
2575
  return [
2409
2576
  3,
2410
2577
  10
@@ -2416,6 +2583,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2416
2583
  3,
2417
2584
  8
2418
2585
  ];
2586
+ this.timing.consecutiveFailures++;
2419
2587
  return [
2420
2588
  4,
2421
2589
  this.tryNextAvailableAdWithRateLimit()
@@ -2466,6 +2634,67 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2466
2634
  // ───────────────────────────────────────────────────────────────
2467
2635
  // Ad break completion
2468
2636
  // ───────────────────────────────────────────────────────────────
2637
+ key: "logBreakFunnel",
2638
+ value: function logBreakFunnel() {
2639
+ var funnel = this.breakFunnel;
2640
+ this.breakFunnel = {};
2641
+ if (Object.keys(funnel).length === 0) return;
2642
+ var count = function count(stage) {
2643
+ var _funnel_stage;
2644
+ return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
2645
+ };
2646
+ var breakId = this.opportunityEpoch;
2647
+ if (count("request_sent") > 0 && count("impression_fired") === 0) {
2648
+ console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
2649
+ breakId: breakId,
2650
+ requests: count("request_sent")
2651
+ });
2652
+ }
2653
+ console.log("[AdBreak][FUNNEL] Break summary", {
2654
+ breakId: breakId,
2655
+ opportunities: count("opportunity_created"),
2656
+ requests: count("request_sent"),
2657
+ duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
2658
+ filled: count("vast_received"),
2659
+ noFill: count("no_fill"),
2660
+ requestFailed: count("request_failed"),
2661
+ requestAbortedTimeout: count("request_aborted_timeout"),
2662
+ credentialsRetries: count("vast_credentials_retry"),
2663
+ wrapperFailures: count("wrapper_fetch:failure"),
2664
+ noSupportedMedia: count("vast_no_supported_media"),
2665
+ vpaidOnly: count("vast_no_supported_media:vpaid_only"),
2666
+ missingImpression: count("vast_missing_impression"),
2667
+ discardedBudget: count("discarded_budget"),
2668
+ mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
2669
+ mediaRejected: count("media_candidate:rejected"),
2670
+ mediaFallbacks: count("media_fallback"),
2671
+ playCalled: count("play_called"),
2672
+ playRejected: count("play_rejected"),
2673
+ mutedRetry: count("muted_retry"),
2674
+ startTimeouts: count("play_resolved_but_never_started"),
2675
+ impressions: count("impression_fired"),
2676
+ impressionUrls: count("impression_urls"),
2677
+ trackingRequests: count("tracking_request_created"),
2678
+ trackingNotLoaded: count("tracking_request_settled:error") + count("tracking_request_settled:timeout"),
2679
+ trackingUnexpandedMacros: count("tracking_url_unexpanded_macro"),
2680
+ trackingInvalidUrls: count("tracking_url_invalid"),
2681
+ vastAdFallbacks: count("vast_ad_fallback"),
2682
+ mediaEvents: count("media_event"),
2683
+ quartile25: count("first_quartile"),
2684
+ quartile50: count("midpoint"),
2685
+ quartile75: count("third_quartile"),
2686
+ complete: count("complete"),
2687
+ stoppedBeforeStart: count("stopped_before_start"),
2688
+ stoppedBeforeStartByBreakEnd: count("ad_stopped_before_start"),
2689
+ unexpectedUnmutes: count("unexpected_unmute"),
2690
+ unmuteBlocked: count("unmute_blocked_without_gesture"),
2691
+ visibilityHidden: count("while_hidden"),
2692
+ playbackFailures: count("play_failed") + count("media_error") + count("hls_fatal") + count("stall") + count("decode_failure") + count("media_unsupported"),
2693
+ stages: funnel
2694
+ });
2695
+ }
2696
+ },
2697
+ {
2469
2698
  key: "handleAdPodComplete",
2470
2699
  value: function handleAdPodComplete() {
2471
2700
  if (this.debug) {
@@ -2486,6 +2715,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2486
2715
  this.adPodQueue = [];
2487
2716
  this.showAds = false;
2488
2717
  this.host.getAdPlayer().stop().catch(function() {});
2718
+ this.logBreakFunnel();
2489
2719
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
2490
2720
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
2491
2721
  if (this.host.video.muted !== restoredMuted) {