stormcloud-video-player 0.6.10 → 0.6.12

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.js CHANGED
@@ -671,7 +671,8 @@ function fireTrackingPixels(urls, sessionId) {
671
671
  });
672
672
  }
673
673
  // src/sdk/vastManager.ts
674
- var VAST_TAG_URL = "https://pubads.g.doubleclick.net/gampad/ads?iu=/21821455290/Airy-Android&description_url=http%3A%2F%2Fairy.tv&tfcd=0&npa=0&sz=1x1%7C300x250%7C400x300%7C640x480&gdfp_req=1&unviewed_position_start=1&correlator=[placeholder]&vpos=preroll&output=vast&env=vp&vpmute=0&vpa=click";
674
+ var VAST_TAG_URL_FALLBACK = "https://pubads.g.doubleclick.net/gampad/ads?iu=/21821455290/Airy-Android&description_url=http%3A%2F%2Fairy.tv&tfcd=0&npa=0&sz=1x1%7C300x250%7C400x300%7C640x480&gdfp_req=1&unviewed_position_start=1&correlator=[placeholder]&vpos=preroll&output=vast&env=vp&vpmute=0&vpa=click";
675
+ var ADSTORM_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/ads/web";
675
676
  var DEFAULT_TIMEOUT_MS = 5e3;
676
677
  var MAX_RETRIES = 3;
677
678
  var RETRY_BACKOFF_MS = 1500;
@@ -679,6 +680,7 @@ function createVastManager() {
679
680
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
680
681
  var _options_debug;
681
682
  var initialized = false;
683
+ var vastTagUrl = VAST_TAG_URL_FALLBACK;
682
684
  var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
683
685
  function log() {
684
686
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
@@ -700,17 +702,97 @@ function createVastManager() {
700
702
  "[VastManager]"
701
703
  ].concat(_to_consumable_array(args)));
702
704
  }
705
+ function fetchVastUrlFromApi() {
706
+ return _async_to_generator(function() {
707
+ var apiUrl, _data_response_ima_publisherdeskima, _data_response_ima, _data_response, res, data, payload, err;
708
+ return _ts_generator(this, function(_state) {
709
+ switch(_state.label){
710
+ case 0:
711
+ apiUrl = options.adstormApiUrl || ADSTORM_API_URL;
712
+ _state.label = 1;
713
+ case 1:
714
+ _state.trys.push([
715
+ 1,
716
+ 4,
717
+ ,
718
+ 5
719
+ ]);
720
+ return [
721
+ 4,
722
+ fetch(apiUrl, {
723
+ method: "GET",
724
+ headers: {
725
+ Authorization: "Bearer ".concat(options.licenseKey),
726
+ Accept: "application/json"
727
+ }
728
+ })
729
+ ];
730
+ case 2:
731
+ res = _state.sent();
732
+ if (!res.ok) {
733
+ warn("Failed to fetch VAST URL from API (HTTP ".concat(res.status, "), using fallback"));
734
+ return [
735
+ 2
736
+ ];
737
+ }
738
+ return [
739
+ 4,
740
+ res.json()
741
+ ];
742
+ case 3:
743
+ data = _state.sent();
744
+ payload = data === null || data === void 0 ? void 0 : (_data_response = data.response) === null || _data_response === void 0 ? void 0 : (_data_response_ima = _data_response.ima) === null || _data_response_ima === void 0 ? void 0 : (_data_response_ima_publisherdeskima = _data_response_ima["publisherdesk.ima"]) === null || _data_response_ima_publisherdeskima === void 0 ? void 0 : _data_response_ima_publisherdeskima.payload;
745
+ if (payload) {
746
+ vastTagUrl = payload;
747
+ log("VAST tag URL fetched from API:", vastTagUrl.split("?")[0]);
748
+ } else {
749
+ log("API response had no VAST payload, using fallback URL");
750
+ }
751
+ return [
752
+ 3,
753
+ 5
754
+ ];
755
+ case 4:
756
+ err = _state.sent();
757
+ warn("Error fetching VAST URL from API, using fallback:", err);
758
+ return [
759
+ 3,
760
+ 5
761
+ ];
762
+ case 5:
763
+ return [
764
+ 2
765
+ ];
766
+ }
767
+ });
768
+ })();
769
+ }
703
770
  function initialize() {
704
771
  return _async_to_generator(function() {
705
772
  return _ts_generator(this, function(_state) {
706
- if (initialized) return [
707
- 2
708
- ];
709
- initialized = true;
710
- log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
711
- return [
712
- 2
713
- ];
773
+ switch(_state.label){
774
+ case 0:
775
+ if (initialized) return [
776
+ 2
777
+ ];
778
+ initialized = true;
779
+ if (!options.licenseKey) return [
780
+ 3,
781
+ 2
782
+ ];
783
+ return [
784
+ 4,
785
+ fetchVastUrlFromApi()
786
+ ];
787
+ case 1:
788
+ _state.sent();
789
+ _state.label = 2;
790
+ case 2:
791
+ log("Initialized, VAST tag URL:", vastTagUrl.split("?")[0]);
792
+ return [
793
+ 2
794
+ ];
795
+ }
714
796
  });
715
797
  })();
716
798
  }
@@ -724,7 +806,7 @@ function createVastManager() {
724
806
  throw new Error("VastManager not initialized. Call initialize() first.");
725
807
  }
726
808
  correlator = Math.floor(Math.random() * 1e12).toString();
727
- url = VAST_TAG_URL.replace("[placeholder]", correlator);
809
+ url = vastTagUrl.replace("[placeholder]", correlator);
728
810
  log("Fetching VAST tag, correlator:", correlator);
729
811
  controller = typeof AbortController !== "undefined" ? new AbortController() : null;
730
812
  timeoutId = setTimeout(function() {
@@ -918,6 +1000,7 @@ function createVastManager() {
918
1000
  }
919
1001
  function destroy() {
920
1002
  initialized = false;
1003
+ vastTagUrl = VAST_TAG_URL_FALLBACK;
921
1004
  log("Destroyed");
922
1005
  }
923
1006
  return {
@@ -1947,6 +2030,85 @@ function createVastAdLayer(contentVideo, options) {
1947
2030
  }
1948
2031
  };
1949
2032
  }
2033
+ // src/utils/mqttClient.ts
2034
+ import mqtt from "mqtt";
2035
+ var LOG2 = "[StormcloudVideoPlayer][MQTT]";
2036
+ var client = null;
2037
+ var status = "disconnected";
2038
+ var brokerUrl = "";
2039
+ function getMQTTStatus() {
2040
+ return status;
2041
+ }
2042
+ function isMQTTConnected() {
2043
+ return status === "connected" && client !== null && client.connected;
2044
+ }
2045
+ function isMQTTConfigured() {
2046
+ return client !== null;
2047
+ }
2048
+ function initMQTTClient(url) {
2049
+ var _topicPrefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "adstorm";
2050
+ if (client) return;
2051
+ brokerUrl = url;
2052
+ status = "connecting";
2053
+ var clientId = "stormcloud-vp-".concat(Math.random().toString(36).slice(2, 9));
2054
+ try {
2055
+ client = mqtt.connect(url, {
2056
+ clientId: clientId,
2057
+ keepalive: 60,
2058
+ clean: true,
2059
+ reconnectPeriod: 5e3,
2060
+ connectTimeout: 1e4,
2061
+ queueQoSZero: false
2062
+ });
2063
+ } catch (err) {
2064
+ status = "error";
2065
+ console.warn("".concat(LOG2, " connect() threw:"), err);
2066
+ return;
2067
+ }
2068
+ client.on("connect", function() {
2069
+ status = "connected";
2070
+ console.info("".concat(LOG2, " connected to ").concat(url));
2071
+ });
2072
+ client.on("reconnect", function() {
2073
+ status = "connecting";
2074
+ console.info("".concat(LOG2, " reconnecting…"));
2075
+ });
2076
+ client.on("offline", function() {
2077
+ status = "disconnected";
2078
+ console.warn("".concat(LOG2, " offline"));
2079
+ });
2080
+ client.on("error", function(err) {
2081
+ status = "error";
2082
+ console.warn("".concat(LOG2, " error:"), err.message);
2083
+ });
2084
+ client.on("close", function() {
2085
+ if (status === "connected") {
2086
+ status = "disconnected";
2087
+ }
2088
+ });
2089
+ }
2090
+ function publishMQTT(topic, payload) {
2091
+ if (!client) {
2092
+ return false;
2093
+ }
2094
+ try {
2095
+ client.publish(topic, JSON.stringify(payload), {
2096
+ qos: 1
2097
+ });
2098
+ return true;
2099
+ } catch (err) {
2100
+ console.warn("".concat(LOG2, " publish failed on ").concat(topic, ":"), err);
2101
+ return false;
2102
+ }
2103
+ }
2104
+ function disconnectMQTT() {
2105
+ if (client) {
2106
+ client.end(true);
2107
+ client = null;
2108
+ status = "disconnected";
2109
+ brokerUrl = "";
2110
+ }
2111
+ }
1950
2112
  // src/utils/tracking.ts
1951
2113
  var cachedBrowserId = null;
1952
2114
  function getClientInfo() {
@@ -1978,8 +2140,8 @@ function getClientInfo() {
1978
2140
  os = "webOS";
1979
2141
  isSmartTV = true;
1980
2142
  deviceType = "tv";
1981
- var webosMatch = ua.match(/Web0S\/([^\s]+)/);
1982
- model = webosMatch ? "webOS ".concat(webosMatch[1]) : "webOS TV";
2143
+ var m = ua.match(/Web0S\/([^\s]+)/);
2144
+ model = m ? "webOS ".concat(m[1]) : "webOS TV";
1983
2145
  } else if (ua.includes("Tizen")) {
1984
2146
  brand = "Samsung";
1985
2147
  os = "Tizen";
@@ -2023,23 +2185,19 @@ function getClientInfo() {
2023
2185
  isAndroid = true;
2024
2186
  os = "Android";
2025
2187
  deviceType = /Mobile/.test(ua) ? "mobile" : "tablet";
2026
- if (ua.includes("Android") && (maxTouchPoints === 0 || ua.includes("Google TV") || ua.includes("XiaoMi"))) {
2188
+ if (maxTouchPoints === 0 || ua.includes("Google TV") || ua.includes("XiaoMi")) {
2027
2189
  deviceType = "tv";
2028
2190
  isSmartTV = true;
2029
2191
  brand = brand === "Unknown" ? "Android TV" : brand;
2030
2192
  }
2031
2193
  var androidModelMatch = ua.match(/\(([^)]*Android[^)]*)\)/);
2032
- if (androidModelMatch && androidModelMatch[1]) {
2033
- model = androidModelMatch[1];
2034
- }
2194
+ if (androidModelMatch === null || androidModelMatch === void 0 ? void 0 : androidModelMatch[1]) model = androidModelMatch[1];
2035
2195
  }
2036
2196
  if (/iPad|iPhone|iPod/.test(ua)) {
2037
2197
  os = "iOS";
2038
2198
  deviceType = "mobile";
2039
2199
  brand = "Apple";
2040
- if (navigator.maxTouchPoints > 1 && /iPad/.test(ua)) {
2041
- deviceType = "tablet";
2042
- }
2200
+ if (navigator.maxTouchPoints > 1 && /iPad/.test(ua)) deviceType = "tablet";
2043
2201
  }
2044
2202
  if (!isAndroid && !isSmartTV && !/Mobile/.test(ua)) {
2045
2203
  if (ua.includes("Windows")) {
@@ -2060,9 +2218,7 @@ function getClientInfo() {
2060
2218
  if (vendor.includes("Samsung") || ua.includes("SM-")) brand = "Samsung";
2061
2219
  }
2062
2220
  isWebView = /wv|WebView|Linux; U;/.test(ua);
2063
- if (((_window = window) === null || _window === void 0 ? void 0 : _window.outerHeight) === 0 && ((_window1 = window) === null || _window1 === void 0 ? void 0 : _window1.outerWidth) === 0) {
2064
- isWebView = true;
2065
- }
2221
+ if (((_window = window) === null || _window === void 0 ? void 0 : _window.outerHeight) === 0 && ((_window1 = window) === null || _window1 === void 0 ? void 0 : _window1.outerWidth) === 0) isWebView = true;
2066
2222
  isWebApp = window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === true || ((_window_screen = window.screen) === null || _window_screen === void 0 ? void 0 : (_window_screen_orientation = _window_screen.orientation) === null || _window_screen_orientation === void 0 ? void 0 : _window_screen_orientation.angle) !== void 0;
2067
2223
  return {
2068
2224
  brand: brand,
@@ -2093,18 +2249,16 @@ function getClientInfo() {
2093
2249
  }
2094
2250
  function getBrowserID(clientInfo) {
2095
2251
  return _async_to_generator(function() {
2096
- var fingerprintString, encodedData, utf8, buffer, i, hashBuffer, hashArray, hashHex, error, hash, i1, char, fallbackHash, timestamp, random;
2252
+ var _crypto_subtle, fingerprintString, encodedData, utf8, buffer, i, hashBuffer, hashHex, unused, hash, i1, char, fallbackHash, timestamp, random;
2097
2253
  return _ts_generator(this, function(_state) {
2098
2254
  switch(_state.label){
2099
2255
  case 0:
2100
- if (cachedBrowserId) {
2101
- return [
2102
- 2,
2103
- cachedBrowserId
2104
- ];
2105
- }
2256
+ if (cachedBrowserId) return [
2257
+ 2,
2258
+ cachedBrowserId
2259
+ ];
2106
2260
  fingerprintString = JSON.stringify(clientInfo);
2107
- if (!(typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest)) return [
2261
+ if (!(typeof crypto !== "undefined" && ((_crypto_subtle = crypto.subtle) === null || _crypto_subtle === void 0 ? void 0 : _crypto_subtle.digest))) return [
2108
2262
  3,
2109
2263
  5
2110
2264
  ];
@@ -2131,9 +2285,7 @@ function getBrowserID(clientInfo) {
2131
2285
  } else {
2132
2286
  utf8 = unescape(encodeURIComponent(fingerprintString));
2133
2287
  buffer = new Uint8Array(utf8.length);
2134
- for(i = 0; i < utf8.length; i++){
2135
- buffer[i] = utf8.charCodeAt(i);
2136
- }
2288
+ for(i = 0; i < utf8.length; i++)buffer[i] = utf8.charCodeAt(i);
2137
2289
  encodedData = buffer;
2138
2290
  }
2139
2291
  return [
@@ -2142,8 +2294,7 @@ function getBrowserID(clientInfo) {
2142
2294
  ];
2143
2295
  case 3:
2144
2296
  hashBuffer = _state.sent();
2145
- hashArray = Array.from(new Uint8Array(hashBuffer));
2146
- hashHex = hashArray.map(function(b) {
2297
+ hashHex = Array.from(new Uint8Array(hashBuffer)).map(function(b) {
2147
2298
  return b.toString(16).padStart(2, "0");
2148
2299
  }).join("");
2149
2300
  cachedBrowserId = hashHex;
@@ -2152,8 +2303,8 @@ function getBrowserID(clientInfo) {
2152
2303
  hashHex
2153
2304
  ];
2154
2305
  case 4:
2155
- error = _state.sent();
2156
- console.warn("[StormcloudVideoPlayer] crypto.subtle.digest not supported, using fallback hash");
2306
+ unused = _state.sent();
2307
+ console.warn("[StormcloudVideoPlayer] crypto.subtle not supported, using fallback hash");
2157
2308
  return [
2158
2309
  3,
2159
2310
  5
@@ -2177,6 +2328,10 @@ function getBrowserID(clientInfo) {
2177
2328
  });
2178
2329
  })();
2179
2330
  }
2331
+ var mqttTopicPrefix = "adstorm";
2332
+ function setMQTTTopicPrefix(prefix) {
2333
+ mqttTopicPrefix = prefix || "adstorm";
2334
+ }
2180
2335
  var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2181
2336
  var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2182
2337
  var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
@@ -2185,43 +2340,9 @@ function buildHeaders(licenseKey) {
2185
2340
  var headers = {
2186
2341
  "Content-Type": "application/json"
2187
2342
  };
2188
- if (licenseKey) {
2189
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2190
- }
2343
+ if (licenseKey) headers["Authorization"] = "Bearer ".concat(licenseKey);
2191
2344
  return headers;
2192
2345
  }
2193
- function sendTrackRequest(licenseKey, body) {
2194
- return _async_to_generator(function() {
2195
- var response;
2196
- return _ts_generator(this, function(_state) {
2197
- switch(_state.label){
2198
- case 0:
2199
- return [
2200
- 4,
2201
- fetch(TRACK_URL, {
2202
- method: "POST",
2203
- headers: buildHeaders(licenseKey),
2204
- body: JSON.stringify(body)
2205
- })
2206
- ];
2207
- case 1:
2208
- response = _state.sent();
2209
- if (!response.ok) {
2210
- throw new Error("HTTP error! status: ".concat(response.status));
2211
- }
2212
- return [
2213
- 4,
2214
- response.json()
2215
- ];
2216
- case 2:
2217
- _state.sent();
2218
- return [
2219
- 2
2220
- ];
2221
- }
2222
- });
2223
- })();
2224
- }
2225
2346
  function postJson(url, licenseKey, body) {
2226
2347
  return _async_to_generator(function() {
2227
2348
  var response;
@@ -2238,9 +2359,7 @@ function postJson(url, licenseKey, body) {
2238
2359
  ];
2239
2360
  case 1:
2240
2361
  response = _state.sent();
2241
- if (!response.ok) {
2242
- throw new Error("HTTP error! status: ".concat(response.status));
2243
- }
2362
+ if (!response.ok) throw new Error("HTTP error! status: ".concat(response.status));
2244
2363
  return [
2245
2364
  4,
2246
2365
  response.json()
@@ -2290,9 +2409,33 @@ function buildPlayerMetricEvent(_0) {
2290
2409
  });
2291
2410
  }).apply(this, arguments);
2292
2411
  }
2412
+ function publishOrPost(mqttTopic, httpUrl, licenseKey, body) {
2413
+ return _async_to_generator(function() {
2414
+ return _ts_generator(this, function(_state) {
2415
+ switch(_state.label){
2416
+ case 0:
2417
+ if (isMQTTConfigured()) {
2418
+ publishMQTT(mqttTopic, body);
2419
+ return [
2420
+ 2
2421
+ ];
2422
+ }
2423
+ return [
2424
+ 4,
2425
+ postJson(httpUrl, licenseKey, body)
2426
+ ];
2427
+ case 1:
2428
+ _state.sent();
2429
+ return [
2430
+ 2
2431
+ ];
2432
+ }
2433
+ });
2434
+ })();
2435
+ }
2293
2436
  function sendInitialTracking(_0) {
2294
2437
  return _async_to_generator(function(licenseKey) {
2295
- var context, clientInfo, browserId, trackingData, error;
2438
+ var context, clientInfo, browserId, captureAt, trackingData, metricsBody, error;
2296
2439
  var _arguments = arguments;
2297
2440
  return _ts_generator(this, function(_state) {
2298
2441
  switch(_state.label){
@@ -2313,26 +2456,28 @@ function sendInitialTracking(_0) {
2313
2456
  ];
2314
2457
  case 2:
2315
2458
  browserId = _state.sent();
2459
+ captureAt = /* @__PURE__ */ new Date().toISOString();
2316
2460
  trackingData = _object_spread({
2317
2461
  browserId: browserId
2318
2462
  }, clientInfo);
2463
+ metricsBody = {
2464
+ events: [
2465
+ {
2466
+ player_id: browserId,
2467
+ device_type: clientInfo.deviceType,
2468
+ input_stream_type: context.inputStreamType,
2469
+ os: clientInfo.os,
2470
+ ad_loaded: false,
2471
+ ad_detect: false,
2472
+ license_key: licenseKey,
2473
+ capture_at: captureAt
2474
+ }
2475
+ ],
2476
+ trackingData: trackingData
2477
+ };
2319
2478
  return [
2320
2479
  4,
2321
- sendTrackRequest(licenseKey, {
2322
- events: [
2323
- {
2324
- player_id: browserId,
2325
- device_type: clientInfo.deviceType,
2326
- input_stream_type: context.inputStreamType,
2327
- os: clientInfo.os,
2328
- ad_loaded: false,
2329
- ad_detect: false,
2330
- license_key: licenseKey,
2331
- capture_at: /* @__PURE__ */ new Date().toISOString()
2332
- }
2333
- ],
2334
- trackingData: trackingData
2335
- })
2480
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/metrics"), TRACK_URL, licenseKey, metricsBody)
2336
2481
  ];
2337
2482
  case 3:
2338
2483
  _state.sent();
@@ -2445,7 +2590,7 @@ function sendAdLoadedTracking(_0, _1) {
2445
2590
  }
2446
2591
  function sendAdImpressionTracking(_0, _1) {
2447
2592
  return _async_to_generator(function(licenseKey, adImpressionInfo) {
2448
- var context, metricEvent, error;
2593
+ var context, metricEvent, heartbeatBody, impressionsBody, error;
2449
2594
  var _arguments = arguments;
2450
2595
  return _ts_generator(this, function(_state) {
2451
2596
  switch(_state.label){
@@ -2467,21 +2612,23 @@ function sendAdImpressionTracking(_0, _1) {
2467
2612
  ];
2468
2613
  case 2:
2469
2614
  metricEvent = _state.sent();
2615
+ heartbeatBody = metricEvent;
2616
+ impressionsBody = {
2617
+ events: [
2618
+ {
2619
+ player_id: metricEvent.player_id,
2620
+ ad_played_count: 1,
2621
+ ad_url: adImpressionInfo.adUrl,
2622
+ license_key: licenseKey,
2623
+ capture_at: adImpressionInfo.timestamp
2624
+ }
2625
+ ]
2626
+ };
2470
2627
  return [
2471
2628
  4,
2472
2629
  Promise.all([
2473
- postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2474
- postJson(IMPRESSIONS_URL, licenseKey, {
2475
- events: [
2476
- {
2477
- player_id: metricEvent.player_id,
2478
- ad_played_count: 1,
2479
- ad_url: adImpressionInfo.adUrl,
2480
- license_key: licenseKey,
2481
- capture_at: adImpressionInfo.timestamp
2482
- }
2483
- ]
2484
- })
2630
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/heartbeat"), HEARTBEAT_URL, licenseKey, heartbeatBody),
2631
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/impressions"), IMPRESSIONS_URL, licenseKey, impressionsBody)
2485
2632
  ])
2486
2633
  ];
2487
2634
  case 3:
@@ -2529,7 +2676,7 @@ function sendHeartbeat(_0) {
2529
2676
  heartbeatData = _state.sent();
2530
2677
  return [
2531
2678
  4,
2532
- postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2679
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/heartbeat"), HEARTBEAT_URL, licenseKey, heartbeatData)
2533
2680
  ];
2534
2681
  case 3:
2535
2682
  _state.sent();
@@ -3133,9 +3280,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3133
3280
  this.video = config.videoElement;
3134
3281
  this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
3135
3282
  logBrowserInfo(config.debugAdTiming);
3136
- this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
3137
- debug: !!config.debugAdTiming
3138
- } : {});
3283
+ this.vastManager = createVastManager(_object_spread({
3284
+ debug: config.debugAdTiming !== void 0 ? !!config.debugAdTiming : false
3285
+ }, config.licenseKey ? {
3286
+ licenseKey: config.licenseKey
3287
+ } : {}));
3139
3288
  var browserForAdLayer = detectBrowser();
3140
3289
  var isSinglePipeline = browserForAdLayer.isSmartTV || !!this.config.singlePipelineMode;
3141
3290
  this.adLayer = createVastAdLayer(this.video, {
@@ -3186,6 +3335,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3186
3335
  this.attach();
3187
3336
  }
3188
3337
  this.initializeTracking();
3338
+ if (!this.config.disableAds) {
3339
+ this.vastManager.initialize().catch(function() {});
3340
+ }
3189
3341
  if (!this.shouldUseNativeHls()) return [
3190
3342
  3,
3191
3343
  3
@@ -4481,6 +4633,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4481
4633
  key: "initializeTracking",
4482
4634
  value: function initializeTracking() {
4483
4635
  var _this = this;
4636
+ if (this.config.mqttBrokerUrl) {
4637
+ var topicPrefix = "adstorm";
4638
+ setMQTTTopicPrefix(topicPrefix);
4639
+ initMQTTClient(this.config.mqttBrokerUrl, topicPrefix);
4640
+ }
4484
4641
  sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4485
4642
  _this.heartbeatInterval = window.setInterval(function() {
4486
4643
  _this.sendHeartbeatIfNeeded();
@@ -6160,6 +6317,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6160
6317
  clearInterval(this.heartbeatInterval);
6161
6318
  this.heartbeatInterval = void 0;
6162
6319
  }
6320
+ if (this.config.mqttBrokerUrl) {
6321
+ disconnectMQTT();
6322
+ }
6163
6323
  (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.destroy();
6164
6324
  (_this_adLayer = this.adLayer) === null || _this_adLayer === void 0 ? void 0 : _this_adLayer.destroy();
6165
6325
  this.consecutiveFailures = 0;
@@ -6181,7 +6341,7 @@ var CRITICAL_PROPS = [
6181
6341
  var CONTROLS_HIDE_DELAY = 3e3;
6182
6342
  var DEFAULT_PLAYER_ASPECT_RATIO = 16 / 9;
6183
6343
  var StormcloudVideoPlayerComponent = React.memo(function(props) {
6184
- var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay, disableAds = props.disableAds, disableFiller = props.disableFiller, restVideoAttrs = _object_without_properties(props, [
6344
+ var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay, disableAds = props.disableAds, disableFiller = props.disableFiller, mqttBrokerUrl = props.mqttBrokerUrl, restVideoAttrs = _object_without_properties(props, [
6185
6345
  "src",
6186
6346
  "autoplay",
6187
6347
  "muted",
@@ -6208,7 +6368,8 @@ var StormcloudVideoPlayerComponent = React.memo(function(props) {
6208
6368
  "licenseKey",
6209
6369
  "minSegmentsBeforePlay",
6210
6370
  "disableAds",
6211
- "disableFiller"
6371
+ "disableFiller",
6372
+ "mqttBrokerUrl"
6212
6373
  ]);
6213
6374
  var videoRef = useRef(null);
6214
6375
  var playerRef = useRef(null);
@@ -6368,6 +6529,7 @@ var StormcloudVideoPlayerComponent = React.memo(function(props) {
6368
6529
  if (minSegmentsBeforePlay !== void 0) cfg.minSegmentsBeforePlay = minSegmentsBeforePlay;
6369
6530
  if (disableAds !== void 0) cfg.disableAds = disableAds;
6370
6531
  cfg.disableFiller = disableFiller !== null && disableFiller !== void 0 ? disableFiller : true;
6532
+ if (mqttBrokerUrl !== void 0) cfg.mqttBrokerUrl = mqttBrokerUrl;
6371
6533
  var player = new StormcloudVideoPlayer(cfg);
6372
6534
  playerRef.current = player;
6373
6535
  player.load().then(function() {
@@ -8602,5 +8764,5 @@ var createStormcloudPlayer = function createStormcloudPlayer(playerList, fallbac
8602
8764
  };
8603
8765
  var StormcloudPlayer = createStormcloudPlayer(players_default, players_default[players_default.length - 1]);
8604
8766
  var StormcloudPlayer_default = StormcloudPlayer;
8605
- export { IS_BROWSER, IS_GLOBAL, IS_IOS, IS_SAFARI, SUPPORTS_DASH, SUPPORTS_HLS, StormcloudPlayer_default as StormcloudPlayer, StormcloudVideoPlayer, StormcloudVideoPlayerComponent, canPlay, createStormcloudPlayer, createVastAdLayer, createVastManager, StormcloudVideoPlayerComponent as default, detectBrowser, getBrowserConfigOverrides, getBrowserID, getClientInfo, initializePolyfills, isMediaStream, lazy, logBrowserInfo, merge, omit, parseQuery, players_default as players, randomString, sendHeartbeat, sendInitialTracking, supportsFeature, supportsModernJS, supportsWebKitPresentationMode };
8767
+ export { IS_BROWSER, IS_GLOBAL, IS_IOS, IS_SAFARI, SUPPORTS_DASH, SUPPORTS_HLS, StormcloudPlayer_default as StormcloudPlayer, StormcloudVideoPlayer, StormcloudVideoPlayerComponent, canPlay, createStormcloudPlayer, createVastAdLayer, createVastManager, StormcloudVideoPlayerComponent as default, detectBrowser, disconnectMQTT, getBrowserConfigOverrides, getBrowserID, getClientInfo, getMQTTStatus, initMQTTClient, initializePolyfills, isMQTTConfigured, isMQTTConnected, isMediaStream, lazy, logBrowserInfo, merge, omit, parseQuery, players_default as players, publishMQTT, randomString, sendHeartbeat, sendInitialTracking, supportsFeature, supportsModernJS, supportsWebKitPresentationMode };
8606
8768
  //# sourceMappingURL=index.js.map