stormcloud-video-player 0.8.63 → 0.8.64

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.
@@ -31,6 +31,7 @@ declare class AdBreakOrchestrator {
31
31
  adDetectSentForCurrentBreak: boolean;
32
32
  private continuousFetchingActive;
33
33
  private continuousFetchLoopRunning;
34
+ private currentVastUrl;
34
35
  adRequestQueue: string[];
35
36
  adPodQueue: string[];
36
37
  private readonly maxPlaceholderDurationMs;
@@ -61,6 +62,7 @@ declare class AdBreakOrchestrator {
61
62
  stopContinuousFetching(): void;
62
63
  tryNextAvailableAdWithRateLimit(): Promise<void>;
63
64
  private tryNextAvailableAd;
65
+ private withCurrentPodBudget;
64
66
  playSingleAd(vastTagUrl: string): Promise<void>;
65
67
  private showPlaceholderAndWaitForAds;
66
68
  handleAdPodComplete(): void;
@@ -700,6 +700,7 @@ function parseProgressOffset(offset) {
700
700
  } : void 0;
701
701
  }
702
702
  var MAX_VAST_WRAPPER_DEPTH = 5;
703
+ var VAST_REQUEST_TIMEOUT_MS = 5e3;
703
704
  var BEACON_TIMEOUT_MS = 3e4;
704
705
  var inFlightBeacons = /* @__PURE__ */ new Set();
705
706
  var VAST_ERROR_MEDIA_DISPLAY = 405;
@@ -1258,70 +1259,104 @@ function createHlsAdPlayer(contentVideo, options) {
1258
1259
  function fetchVastXml(vastTagUrl) {
1259
1260
  var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1260
1261
  return _async_to_generator(function() {
1261
- var requestVast, response, error;
1262
+ var controller, timeoutId, requestVast, response, error, error1;
1262
1263
  return _ts_generator(this, function(_state) {
1263
1264
  switch(_state.label){
1264
1265
  case 0:
1266
+ controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1267
+ timeoutId = controller ? setTimeout(function() {
1268
+ return controller.abort();
1269
+ }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1265
1270
  requestVast = function requestVast(creds) {
1266
- return fetch(vastTagUrl, {
1271
+ return fetch(vastTagUrl, _object_spread({
1267
1272
  mode: "cors",
1268
1273
  credentials: creds,
1269
1274
  headers: {
1270
1275
  "Accept": "application/xml, text/xml, */*"
1271
1276
  },
1272
1277
  referrerPolicy: "no-referrer-when-downgrade"
1273
- });
1278
+ }, controller ? {
1279
+ signal: controller.signal
1280
+ } : {}));
1274
1281
  };
1275
1282
  _state.label = 1;
1276
1283
  case 1:
1277
1284
  _state.trys.push([
1278
1285
  1,
1279
- 3,
1286
+ 10,
1287
+ 11,
1288
+ 12
1289
+ ]);
1290
+ _state.label = 2;
1291
+ case 2:
1292
+ _state.trys.push([
1293
+ 2,
1294
+ 4,
1280
1295
  ,
1281
- 7
1296
+ 8
1282
1297
  ]);
1283
1298
  return [
1284
1299
  4,
1285
1300
  requestVast(credentials)
1286
1301
  ];
1287
- case 2:
1302
+ case 3:
1288
1303
  response = _state.sent();
1289
1304
  return [
1290
1305
  3,
1291
- 7
1306
+ 8
1292
1307
  ];
1293
- case 3:
1308
+ case 4:
1294
1309
  error = _state.sent();
1295
- if (!(credentials !== "omit")) return [
1310
+ if (!(credentials !== "omit" && !(controller === null || controller === void 0 ? void 0 : controller.signal.aborted))) return [
1296
1311
  3,
1297
- 5
1312
+ 6
1298
1313
  ];
1299
1314
  console.warn('[HlsAdPlayer] VAST fetch failed with credentials="'.concat(credentials, '", retrying without credentials:'), error);
1300
1315
  return [
1301
1316
  4,
1302
1317
  requestVast("omit")
1303
1318
  ];
1304
- case 4:
1319
+ case 5:
1305
1320
  response = _state.sent();
1306
1321
  return [
1307
1322
  3,
1308
- 6
1323
+ 7
1309
1324
  ];
1310
- case 5:
1311
- throw error;
1312
1325
  case 6:
1326
+ throw error;
1327
+ case 7:
1313
1328
  return [
1314
1329
  3,
1315
- 7
1330
+ 8
1316
1331
  ];
1317
- case 7:
1332
+ case 8:
1318
1333
  if (!response.ok) {
1319
1334
  throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1320
1335
  }
1321
1336
  return [
1322
- 2,
1337
+ 4,
1323
1338
  response.text()
1324
1339
  ];
1340
+ case 9:
1341
+ return [
1342
+ 2,
1343
+ _state.sent()
1344
+ ];
1345
+ case 10:
1346
+ error1 = _state.sent();
1347
+ if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1348
+ throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1349
+ }
1350
+ throw error1;
1351
+ case 11:
1352
+ if (timeoutId !== void 0) clearTimeout(timeoutId);
1353
+ return [
1354
+ 7
1355
+ ];
1356
+ case 12:
1357
+ return [
1358
+ 2
1359
+ ];
1325
1360
  }
1326
1361
  });
1327
1362
  })();
@@ -1407,7 +1442,7 @@ function createHlsAdPlayer(contentVideo, options) {
1407
1442
  }
1408
1443
  function fetchAndParsePod(vastTagUrl) {
1409
1444
  return _async_to_generator(function() {
1410
- var _root_getAttribute, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute1, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, adElement, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, adElement1, ad1, err;
1445
+ var _root_getAttribute, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute1, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, resolveAll, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, ad1, err;
1411
1446
  return _ts_generator(this, function(_state) {
1412
1447
  switch(_state.label){
1413
1448
  case 0:
@@ -1488,6 +1523,13 @@ function createHlsAdPlayer(contentVideo, options) {
1488
1523
  buffet = adElements.filter(function(el) {
1489
1524
  return getAdSequence(el) === void 0;
1490
1525
  });
1526
+ resolveAll = function resolveAll(elements) {
1527
+ return Promise.all(elements.map(function(el) {
1528
+ return resolveAd(el).catch(function() {
1529
+ return null;
1530
+ });
1531
+ }));
1532
+ };
1491
1533
  ads = [];
1492
1534
  if (!(podElements.length === 0)) return [
1493
1535
  3,
@@ -1502,27 +1544,26 @@ function createHlsAdPlayer(contentVideo, options) {
1502
1544
  8,
1503
1545
  9
1504
1546
  ]);
1505
- _iterator = buffet[Symbol.iterator]();
1506
- _state.label = 3;
1547
+ return [
1548
+ 4,
1549
+ resolveAll(buffet)
1550
+ ];
1507
1551
  case 3:
1552
+ _iterator = _state.sent()[Symbol.iterator]();
1553
+ _state.label = 4;
1554
+ case 4:
1508
1555
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1509
1556
  3,
1510
1557
  6
1511
1558
  ];
1512
- adElement = _step.value;
1513
- return [
1514
- 4,
1515
- resolveAd(adElement)
1516
- ];
1517
- case 4:
1518
- ad = _state.sent();
1559
+ ad = _step.value;
1519
1560
  if (ad) ads.push(ad);
1520
1561
  _state.label = 5;
1521
1562
  case 5:
1522
1563
  _iteratorNormalCompletion = true;
1523
1564
  return [
1524
1565
  3,
1525
- 3
1566
+ 4
1526
1567
  ];
1527
1568
  case 6:
1528
1569
  return [
@@ -1565,20 +1606,19 @@ function createHlsAdPlayer(contentVideo, options) {
1565
1606
  20,
1566
1607
  21
1567
1608
  ]);
1568
- _iterator1 = podElements[Symbol.iterator]();
1569
- _state.label = 12;
1609
+ return [
1610
+ 4,
1611
+ resolveAll(podElements)
1612
+ ];
1570
1613
  case 12:
1614
+ _iterator1 = _state.sent()[Symbol.iterator]();
1615
+ _state.label = 13;
1616
+ case 13:
1571
1617
  if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
1572
1618
  3,
1573
1619
  18
1574
1620
  ];
1575
- adElement1 = _step1.value;
1576
- return [
1577
- 4,
1578
- resolveAd(adElement1)
1579
- ];
1580
- case 13:
1581
- ad1 = _state.sent();
1621
+ ad1 = _step1.value;
1582
1622
  _state.label = 14;
1583
1623
  case 14:
1584
1624
  if (!(!ad1 && buffet.length > 0)) return [
@@ -1587,7 +1627,9 @@ function createHlsAdPlayer(contentVideo, options) {
1587
1627
  ];
1588
1628
  return [
1589
1629
  4,
1590
- resolveAd(buffet.shift())
1630
+ resolveAd(buffet.shift()).catch(function() {
1631
+ return null;
1632
+ })
1591
1633
  ];
1592
1634
  case 15:
1593
1635
  ad1 = _state.sent();
@@ -1602,7 +1644,7 @@ function createHlsAdPlayer(contentVideo, options) {
1602
1644
  _iteratorNormalCompletion1 = true;
1603
1645
  return [
1604
1646
  3,
1605
- 12
1647
+ 13
1606
1648
  ];
1607
1649
  case 18:
1608
1650
  return [
@@ -8075,12 +8117,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8075
8117
  adPlayer.on("ad_interaction", function(event) {
8076
8118
  if (event) _this.host.onAdInteraction(event);
8077
8119
  });
8078
- adPlayer.on("all_ads_completed", function() {
8079
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8120
+ adPlayer.on("ad_impression", function() {
8121
+ sendAdImpressionTracking(_this.host.config.licenseKey, _object_spread_props(_object_spread({
8080
8122
  source: "hls",
8081
- adIndex: _this.timing.currentAdIndex,
8123
+ adIndex: _this.timing.currentAdIndex
8124
+ }, _this.currentVastUrl ? {
8125
+ adUrl: _this.currentVastUrl
8126
+ } : {}), {
8082
8127
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8083
- }, _this.analyticsContext).catch(function() {});
8128
+ }), _this.analyticsContext).catch(function() {});
8129
+ });
8130
+ adPlayer.on("all_ads_completed", function() {
8084
8131
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8085
8132
  var remaining = _this.timing.getRemainingAdMs();
8086
8133
  _this.timing.consecutiveFailures = 0;
@@ -8138,11 +8185,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8138
8185
  }
8139
8186
  });
8140
8187
  adPlayer.on("content_resume", function() {
8141
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8142
- source: "hls",
8143
- adIndex: _this.timing.currentAdIndex,
8144
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
8145
- }, _this.analyticsContext).catch(function() {});
8146
8188
  if (!_this.host.video.muted) {
8147
8189
  _this.host.video.muted = true;
8148
8190
  if (_this.debug) {
@@ -8338,7 +8380,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8338
8380
  adPlayer = this.host.getAdPlayer();
8339
8381
  requestToken = ++this.timing.adRequestTokenCounter;
8340
8382
  this.timing.activeAdRequestToken = requestToken;
8341
- this.timing.startAdRequestWatchdog(requestToken);
8383
+ this.currentVastUrl = podUrl;
8342
8384
  _state.label = 1;
8343
8385
  case 1:
8344
8386
  _state.trys.push([
@@ -8353,6 +8395,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8353
8395
  ];
8354
8396
  case 2:
8355
8397
  _state.sent();
8398
+ this.timing.startAdRequestWatchdog(requestToken);
8356
8399
  this.timing.lastAdRequestTime = Date.now();
8357
8400
  return [
8358
8401
  4,
@@ -8841,13 +8884,33 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8841
8884
  }
8842
8885
  },
8843
8886
  {
8844
- key: "playSingleAd",
8845
- value: // ───────────────────────────────────────────────────────────────
8887
+ // ───────────────────────────────────────────────────────────────
8846
8888
  // Single ad playback
8847
8889
  // ───────────────────────────────────────────────────────────────
8848
- function playSingleAd(vastTagUrl) {
8890
+ key: "withCurrentPodBudget",
8891
+ value: function withCurrentPodBudget(vastTagUrl) {
8892
+ var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
8893
+ if (!(remaining > 0)) return vastTagUrl;
8894
+ try {
8895
+ var url = new URL(vastTagUrl);
8896
+ if (!url.searchParams.has("pmxd")) return vastTagUrl;
8897
+ var maxMs = Math.round(remaining);
8898
+ url.searchParams.set("pmxd", String(maxMs));
8899
+ var minMs = Number(url.searchParams.get("pmnd"));
8900
+ if (Number.isFinite(minMs) && minMs > maxMs) {
8901
+ url.searchParams.set("pmnd", String(maxMs));
8902
+ }
8903
+ return url.toString();
8904
+ } catch (unused) {
8905
+ return vastTagUrl;
8906
+ }
8907
+ }
8908
+ },
8909
+ {
8910
+ key: "playSingleAd",
8911
+ value: function playSingleAd(vastTagUrl) {
8849
8912
  return _async_to_generator(function() {
8850
- var adPlayer, requestToken, ap, playError, error, errorMessage;
8913
+ var adPlayer, requestToken, ap, requestUrl, playError, error, errorMessage;
8851
8914
  return _ts_generator(this, function(_state) {
8852
8915
  switch(_state.label){
8853
8916
  case 0:
@@ -8874,7 +8937,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8874
8937
  this.recreateAdController();
8875
8938
  requestToken = ++this.timing.adRequestTokenCounter;
8876
8939
  this.timing.activeAdRequestToken = requestToken;
8877
- this.timing.startAdRequestWatchdog(requestToken);
8878
8940
  _state.label = 1;
8879
8941
  case 1:
8880
8942
  _state.trys.push([
@@ -8889,17 +8951,20 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8889
8951
  ];
8890
8952
  case 2:
8891
8953
  _state.sent();
8954
+ this.timing.startAdRequestWatchdog(requestToken);
8892
8955
  this.timing.lastAdRequestTime = Date.now();
8893
8956
  ap = this.host.getAdPlayer();
8957
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
8958
+ this.currentVastUrl = requestUrl;
8894
8959
  return [
8895
8960
  4,
8896
- ap.requestAds(vastTagUrl)
8961
+ ap.requestAds(requestUrl)
8897
8962
  ];
8898
8963
  case 3:
8899
8964
  _state.sent();
8900
8965
  sendAdLoadedTracking(this.host.config.licenseKey, {
8901
8966
  source: "hls",
8902
- vastUrl: vastTagUrl,
8967
+ vastUrl: requestUrl,
8903
8968
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8904
8969
  }, this.analyticsContext).catch(function() {});
8905
8970
  this.timing.clearAdRequestWatchdog();