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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StormcloudVideoPlayer } from '../player/StormcloudVideoPlayer.cjs';
3
- import { S as StormcloudVideoPlayerConfig } from '../types-DSKC4ySr.cjs';
3
+ import { S as StormcloudVideoPlayerConfig } from '../types-FjAlGhAL.cjs';
4
4
 
5
5
  type StormcloudVideoPlayerProps = Omit<StormcloudVideoPlayerConfig, "videoElement"> & React.VideoHTMLAttributes<HTMLVideoElement> & {
6
6
  onReady?: (player: StormcloudVideoPlayer) => void;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ function _type_of(obj) {
3
+ "@swc/helpers - typeof";
4
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
+ }
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = function __export(target, all) {
13
+ for(var name in all)__defProp(target, name, {
14
+ get: all[name],
15
+ enumerable: true
16
+ });
17
+ };
18
+ var __copyProps = function __copyProps(to, from, except, desc) {
19
+ if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
20
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
21
+ try {
22
+ var _loop = function() {
23
+ var key = _step.value;
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: function get() {
26
+ return from[key];
27
+ },
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ };
31
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
32
+ } catch (err) {
33
+ _didIteratorError = true;
34
+ _iteratorError = err;
35
+ } finally{
36
+ try {
37
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
38
+ _iterator.return();
39
+ }
40
+ } finally{
41
+ if (_didIteratorError) {
42
+ throw _iteratorError;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = function __toESM(mod, isNodeMode, target) {
50
+ return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
55
+ value: mod,
56
+ enumerable: true
57
+ }) : target, mod);
58
+ };
59
+ var __toCommonJS = function __toCommonJS(mod) {
60
+ return __copyProps(__defProp({}, "__esModule", {
61
+ value: true
62
+ }), mod);
63
+ };
64
+ // src/utils/mqttClient.ts
65
+ var mqttClient_exports = {};
66
+ __export(mqttClient_exports, {
67
+ disconnectMQTT: function disconnectMQTT1() {
68
+ return disconnectMQTT;
69
+ },
70
+ getMQTTStatus: function getMQTTStatus1() {
71
+ return getMQTTStatus;
72
+ },
73
+ initMQTTClient: function initMQTTClient1() {
74
+ return initMQTTClient;
75
+ },
76
+ isMQTTConfigured: function isMQTTConfigured1() {
77
+ return isMQTTConfigured;
78
+ },
79
+ isMQTTConnected: function isMQTTConnected1() {
80
+ return isMQTTConnected;
81
+ },
82
+ publishMQTT: function publishMQTT1() {
83
+ return publishMQTT;
84
+ }
85
+ });
86
+ module.exports = __toCommonJS(mqttClient_exports);
87
+ var import_mqtt = __toESM(require("mqtt"), 1);
88
+ var LOG = "[StormcloudVideoPlayer][MQTT]";
89
+ var client = null;
90
+ var status = "disconnected";
91
+ var brokerUrl = "";
92
+ function getMQTTStatus() {
93
+ return status;
94
+ }
95
+ function isMQTTConnected() {
96
+ return status === "connected" && client !== null && client.connected;
97
+ }
98
+ function isMQTTConfigured() {
99
+ return client !== null;
100
+ }
101
+ function initMQTTClient(url) {
102
+ var _topicPrefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "adstorm";
103
+ if (client) return;
104
+ brokerUrl = url;
105
+ status = "connecting";
106
+ var clientId = "stormcloud-vp-".concat(Math.random().toString(36).slice(2, 9));
107
+ try {
108
+ client = import_mqtt.default.connect(url, {
109
+ clientId: clientId,
110
+ keepalive: 60,
111
+ clean: true,
112
+ reconnectPeriod: 5e3,
113
+ connectTimeout: 1e4,
114
+ queueQoSZero: false
115
+ });
116
+ } catch (err) {
117
+ status = "error";
118
+ console.warn("".concat(LOG, " connect() threw:"), err);
119
+ return;
120
+ }
121
+ client.on("connect", function() {
122
+ status = "connected";
123
+ console.info("".concat(LOG, " connected to ").concat(url));
124
+ });
125
+ client.on("reconnect", function() {
126
+ status = "connecting";
127
+ console.info("".concat(LOG, " reconnecting…"));
128
+ });
129
+ client.on("offline", function() {
130
+ status = "disconnected";
131
+ console.warn("".concat(LOG, " offline"));
132
+ });
133
+ client.on("error", function(err) {
134
+ status = "error";
135
+ console.warn("".concat(LOG, " error:"), err.message);
136
+ });
137
+ client.on("close", function() {
138
+ if (status === "connected") {
139
+ status = "disconnected";
140
+ }
141
+ });
142
+ }
143
+ function publishMQTT(topic, payload) {
144
+ if (!client) {
145
+ return false;
146
+ }
147
+ try {
148
+ client.publish(topic, JSON.stringify(payload), {
149
+ qos: 1
150
+ });
151
+ return true;
152
+ } catch (err) {
153
+ console.warn("".concat(LOG, " publish failed on ").concat(topic, ":"), err);
154
+ return false;
155
+ }
156
+ }
157
+ function disconnectMQTT() {
158
+ if (client) {
159
+ client.end(true);
160
+ client = null;
161
+ status = "disconnected";
162
+ brokerUrl = "";
163
+ }
164
+ }
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ disconnectMQTT: disconnectMQTT,
168
+ getMQTTStatus: getMQTTStatus,
169
+ initMQTTClient: initMQTTClient,
170
+ isMQTTConfigured: isMQTTConfigured,
171
+ isMQTTConnected: isMQTTConnected,
172
+ publishMQTT: publishMQTT
173
+ });
174
+ //# sourceMappingURL=mqttClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/ubuntu24-new/Dev/stormcloud-vp/lib/utils/mqttClient.cjs","../../src/utils/mqttClient.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","__getProtoOf","getOwnPropertyNames","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","mqttClient_exports","disconnectMQTT","getMQTTStatus","initMQTTClient","isMQTTConfigured","isMQTTConnected","publishMQTT","module","exports","import_mqtt","require","LOG","client","status","brokerUrl","connected","url","_topicPrefix","clientId","Math","random","toString","slice","mqtt","connect","keepalive","clean","reconnectPeriod","connectTimeout","queueQoSZero","err","console","warn","on","info"],"mappings":"AAAA;;;;;;;;;AACA,IAAIA,WAAWC,IAAAA,GAAOC,IAAAA,EAAM,YAAA;AAC5B,IAAIC,YAAYF,GAAAA,IAAOG,GAAAA,SAAAA,CAAAA,CAAc,aAAA;AACrC,IAAIC,WAAAA,kBAAAA,OAAmBJ,CAAAA,MAAOK,wBAAwB;IACtD,EAAIC,EAAAA,IAAAA,QAAAA,IACAC,CADoBP,OAAOQ,EAC3BD,KAAeP,GAAAA,IAAOS,EAAAA,GADwB;QACxBA,KAAAA,GAAAA,CAAAA,CAAc,IAAA;QAAA,YAAA;IAAA;AACxC,IAAIC,eAAeV,OAAOW,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,GAAA,qBAAA,IAAA,MAAA,IAACC,IAAAA,IAAQC;MACtB,EAAA,EAAK,IAAIC,EAAAA,CAAAA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S;uBACTkB,QAAQG,IAAA,CAAK,GAAuBlB,OAApBL,KAAG,kBAAoB,OAAHK;KACtC","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/utils/mqttClient.ts\nvar mqttClient_exports = {};\n__export(mqttClient_exports, {\n disconnectMQTT: () => disconnectMQTT,\n getMQTTStatus: () => getMQTTStatus,\n initMQTTClient: () => initMQTTClient,\n isMQTTConfigured: () => isMQTTConfigured,\n isMQTTConnected: () => isMQTTConnected,\n publishMQTT: () => publishMQTT\n});\nmodule.exports = __toCommonJS(mqttClient_exports);\nvar import_mqtt = __toESM(require(\"mqtt\"), 1);\nvar LOG = \"[StormcloudVideoPlayer][MQTT]\";\nvar client = null;\nvar status = \"disconnected\";\nvar brokerUrl = \"\";\nfunction getMQTTStatus() {\n return status;\n}\nfunction isMQTTConnected() {\n return status === \"connected\" && client !== null && client.connected;\n}\nfunction isMQTTConfigured() {\n return client !== null;\n}\nfunction initMQTTClient(url, _topicPrefix = \"adstorm\") {\n if (client) return;\n brokerUrl = url;\n status = \"connecting\";\n const clientId = `stormcloud-vp-${Math.random().toString(36).slice(2, 9)}`;\n try {\n client = import_mqtt.default.connect(url, {\n clientId,\n keepalive: 60,\n clean: true,\n reconnectPeriod: 5e3,\n connectTimeout: 1e4,\n queueQoSZero: false\n });\n } catch (err) {\n status = \"error\";\n console.warn(`${LOG} connect() threw:`, err);\n return;\n }\n client.on(\"connect\", () => {\n status = \"connected\";\n console.info(`${LOG} connected to ${url}`);\n });\n client.on(\"reconnect\", () => {\n status = \"connecting\";\n console.info(`${LOG} reconnecting\\u2026`);\n });\n client.on(\"offline\", () => {\n status = \"disconnected\";\n console.warn(`${LOG} offline`);\n });\n client.on(\"error\", (err) => {\n status = \"error\";\n console.warn(`${LOG} error:`, err.message);\n });\n client.on(\"close\", () => {\n if (status === \"connected\") {\n status = \"disconnected\";\n }\n });\n}\nfunction publishMQTT(topic, payload) {\n if (!client) {\n return false;\n }\n try {\n client.publish(topic, JSON.stringify(payload), { qos: 1 });\n return true;\n } catch (err) {\n console.warn(`${LOG} publish failed on ${topic}:`, err);\n return false;\n }\n}\nfunction disconnectMQTT() {\n if (client) {\n client.end(true);\n client = null;\n status = \"disconnected\";\n brokerUrl = \"\";\n }\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n disconnectMQTT,\n getMQTTStatus,\n initMQTTClient,\n isMQTTConfigured,\n isMQTTConnected,\n publishMQTT\n});\n","import mqtt from \"mqtt\";\nimport type { MqttClient } from \"mqtt\";\n\nconst LOG = \"[StormcloudVideoPlayer][MQTT]\";\n\nexport type MQTTStatus = \"disconnected\" | \"connecting\" | \"connected\" | \"error\";\n\nlet client: MqttClient | null = null;\nlet status: MQTTStatus = \"disconnected\";\nlet brokerUrl = \"\";\n\nexport function getMQTTStatus(): MQTTStatus {\n return status;\n}\n\nexport function isMQTTConnected(): boolean {\n return status === \"connected\" && client !== null && client.connected;\n}\n\nexport function isMQTTConfigured(): boolean {\n return client !== null;\n}\n\nexport function initMQTTClient(\n url: string,\n _topicPrefix = \"adstorm\"\n): void {\n if (client) return;\n\n brokerUrl = url;\n status = \"connecting\";\n\n const clientId = `stormcloud-vp-${Math.random().toString(36).slice(2, 9)}`;\n\n try {\n client = mqtt.connect(url, {\n clientId,\n keepalive: 60,\n clean: true,\n reconnectPeriod: 5000,\n connectTimeout: 10_000,\n queueQoSZero: false,\n });\n } catch (err) {\n status = \"error\";\n console.warn(`${LOG} connect() threw:`, err);\n return;\n }\n\n client.on(\"connect\", () => {\n status = \"connected\";\n console.info(`${LOG} connected to ${url}`);\n });\n\n client.on(\"reconnect\", () => {\n status = \"connecting\";\n console.info(`${LOG} reconnecting…`);\n });\n\n client.on(\"offline\", () => {\n status = \"disconnected\";\n console.warn(`${LOG} offline`);\n });\n\n client.on(\"error\", (err) => {\n status = \"error\";\n console.warn(`${LOG} error:`, err.message);\n });\n\n client.on(\"close\", () => {\n if (status === \"connected\") {\n status = \"disconnected\";\n }\n });\n}\n\nexport function publishMQTT(\n topic: string,\n payload: Record<string, unknown>\n): boolean {\n if (!client) {\n return false;\n }\n try {\n client.publish(topic, JSON.stringify(payload), { qos: 1 });\n return true;\n } catch (err) {\n console.warn(`${LOG} publish failed on ${topic}:`, err);\n return false;\n }\n}\n\nexport function disconnectMQTT(): void {\n if (client) {\n client.end(true);\n client = null;\n status = \"disconnected\";\n brokerUrl = \"\";\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ type MQTTStatus = "disconnected" | "connecting" | "connected" | "error";
2
+ declare function getMQTTStatus(): MQTTStatus;
3
+ declare function isMQTTConnected(): boolean;
4
+ declare function isMQTTConfigured(): boolean;
5
+ declare function initMQTTClient(url: string, _topicPrefix?: string): void;
6
+ declare function publishMQTT(topic: string, payload: Record<string, unknown>): boolean;
7
+ declare function disconnectMQTT(): void;
8
+
9
+ export { type MQTTStatus, disconnectMQTT, getMQTTStatus, initMQTTClient, isMQTTConfigured, isMQTTConnected, publishMQTT };
@@ -159,9 +159,11 @@ function _ts_generator(thisArg, body) {
159
159
  };
160
160
  }
161
161
  }
162
+ var __create = Object.create;
162
163
  var __defProp = Object.defineProperty;
163
164
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
164
165
  var __getOwnPropNames = Object.getOwnPropertyNames;
166
+ var __getProtoOf = Object.getPrototypeOf;
165
167
  var __hasOwnProp = Object.prototype.hasOwnProperty;
166
168
  var __export = function __export(target, all) {
167
169
  for(var name in all)__defProp(target, name, {
@@ -200,6 +202,16 @@ var __copyProps = function __copyProps(to, from, except, desc) {
200
202
  }
201
203
  return to;
202
204
  };
205
+ var __toESM = function __toESM(mod, isNodeMode, target) {
206
+ return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
207
+ // file that has been converted to a CommonJS file using a Babel-
208
+ // compatible transform (i.e. "__esModule" has not been set), then set
209
+ // "default" to the CommonJS "module.exports" for node compatibility.
210
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
211
+ value: mod,
212
+ enumerable: true
213
+ }) : target, mod);
214
+ };
203
215
  var __toCommonJS = function __toCommonJS(mod) {
204
216
  return __copyProps(__defProp({}, "__esModule", {
205
217
  value: true
@@ -228,9 +240,34 @@ __export(tracking_exports, {
228
240
  },
229
241
  sendInitialTracking: function sendInitialTracking1() {
230
242
  return sendInitialTracking;
243
+ },
244
+ setMQTTTopicPrefix: function setMQTTTopicPrefix1() {
245
+ return setMQTTTopicPrefix;
231
246
  }
232
247
  });
233
248
  module.exports = __toCommonJS(tracking_exports);
249
+ // src/utils/mqttClient.ts
250
+ var import_mqtt = __toESM(require("mqtt"), 1);
251
+ var LOG = "[StormcloudVideoPlayer][MQTT]";
252
+ var client = null;
253
+ function isMQTTConfigured() {
254
+ return client !== null;
255
+ }
256
+ function publishMQTT(topic, payload) {
257
+ if (!client) {
258
+ return false;
259
+ }
260
+ try {
261
+ client.publish(topic, JSON.stringify(payload), {
262
+ qos: 1
263
+ });
264
+ return true;
265
+ } catch (err) {
266
+ console.warn("".concat(LOG, " publish failed on ").concat(topic, ":"), err);
267
+ return false;
268
+ }
269
+ }
270
+ // src/utils/tracking.ts
234
271
  var cachedBrowserId = null;
235
272
  function getClientInfo() {
236
273
  var _screen, _screen1, _screen2, _screen3, _screen_orientation, _screen4, _screen5, _window, _window1, _window_screen_orientation, _window_screen, _navigator_languages;
@@ -261,8 +298,8 @@ function getClientInfo() {
261
298
  os = "webOS";
262
299
  isSmartTV = true;
263
300
  deviceType = "tv";
264
- var webosMatch = ua.match(/Web0S\/([^\s]+)/);
265
- model = webosMatch ? "webOS ".concat(webosMatch[1]) : "webOS TV";
301
+ var m = ua.match(/Web0S\/([^\s]+)/);
302
+ model = m ? "webOS ".concat(m[1]) : "webOS TV";
266
303
  } else if (ua.includes("Tizen")) {
267
304
  brand = "Samsung";
268
305
  os = "Tizen";
@@ -306,23 +343,19 @@ function getClientInfo() {
306
343
  isAndroid = true;
307
344
  os = "Android";
308
345
  deviceType = /Mobile/.test(ua) ? "mobile" : "tablet";
309
- if (ua.includes("Android") && (maxTouchPoints === 0 || ua.includes("Google TV") || ua.includes("XiaoMi"))) {
346
+ if (maxTouchPoints === 0 || ua.includes("Google TV") || ua.includes("XiaoMi")) {
310
347
  deviceType = "tv";
311
348
  isSmartTV = true;
312
349
  brand = brand === "Unknown" ? "Android TV" : brand;
313
350
  }
314
351
  var androidModelMatch = ua.match(/\(([^)]*Android[^)]*)\)/);
315
- if (androidModelMatch && androidModelMatch[1]) {
316
- model = androidModelMatch[1];
317
- }
352
+ if (androidModelMatch === null || androidModelMatch === void 0 ? void 0 : androidModelMatch[1]) model = androidModelMatch[1];
318
353
  }
319
354
  if (/iPad|iPhone|iPod/.test(ua)) {
320
355
  os = "iOS";
321
356
  deviceType = "mobile";
322
357
  brand = "Apple";
323
- if (navigator.maxTouchPoints > 1 && /iPad/.test(ua)) {
324
- deviceType = "tablet";
325
- }
358
+ if (navigator.maxTouchPoints > 1 && /iPad/.test(ua)) deviceType = "tablet";
326
359
  }
327
360
  if (!isAndroid && !isSmartTV && !/Mobile/.test(ua)) {
328
361
  if (ua.includes("Windows")) {
@@ -343,9 +376,7 @@ function getClientInfo() {
343
376
  if (vendor.includes("Samsung") || ua.includes("SM-")) brand = "Samsung";
344
377
  }
345
378
  isWebView = /wv|WebView|Linux; U;/.test(ua);
346
- if (((_window = window) === null || _window === void 0 ? void 0 : _window.outerHeight) === 0 && ((_window1 = window) === null || _window1 === void 0 ? void 0 : _window1.outerWidth) === 0) {
347
- isWebView = true;
348
- }
379
+ 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;
349
380
  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;
350
381
  return {
351
382
  brand: brand,
@@ -376,18 +407,16 @@ function getClientInfo() {
376
407
  }
377
408
  function getBrowserID(clientInfo) {
378
409
  return _async_to_generator(function() {
379
- var fingerprintString, encodedData, utf8, buffer, i, hashBuffer, hashArray, hashHex, error, hash, i1, char, fallbackHash, timestamp, random;
410
+ var _crypto_subtle, fingerprintString, encodedData, utf8, buffer, i, hashBuffer, hashHex, unused, hash, i1, char, fallbackHash, timestamp, random;
380
411
  return _ts_generator(this, function(_state) {
381
412
  switch(_state.label){
382
413
  case 0:
383
- if (cachedBrowserId) {
384
- return [
385
- 2,
386
- cachedBrowserId
387
- ];
388
- }
414
+ if (cachedBrowserId) return [
415
+ 2,
416
+ cachedBrowserId
417
+ ];
389
418
  fingerprintString = JSON.stringify(clientInfo);
390
- if (!(typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest)) return [
419
+ if (!(typeof crypto !== "undefined" && ((_crypto_subtle = crypto.subtle) === null || _crypto_subtle === void 0 ? void 0 : _crypto_subtle.digest))) return [
391
420
  3,
392
421
  5
393
422
  ];
@@ -414,9 +443,7 @@ function getBrowserID(clientInfo) {
414
443
  } else {
415
444
  utf8 = unescape(encodeURIComponent(fingerprintString));
416
445
  buffer = new Uint8Array(utf8.length);
417
- for(i = 0; i < utf8.length; i++){
418
- buffer[i] = utf8.charCodeAt(i);
419
- }
446
+ for(i = 0; i < utf8.length; i++)buffer[i] = utf8.charCodeAt(i);
420
447
  encodedData = buffer;
421
448
  }
422
449
  return [
@@ -425,8 +452,7 @@ function getBrowserID(clientInfo) {
425
452
  ];
426
453
  case 3:
427
454
  hashBuffer = _state.sent();
428
- hashArray = Array.from(new Uint8Array(hashBuffer));
429
- hashHex = hashArray.map(function(b) {
455
+ hashHex = Array.from(new Uint8Array(hashBuffer)).map(function(b) {
430
456
  return b.toString(16).padStart(2, "0");
431
457
  }).join("");
432
458
  cachedBrowserId = hashHex;
@@ -435,8 +461,8 @@ function getBrowserID(clientInfo) {
435
461
  hashHex
436
462
  ];
437
463
  case 4:
438
- error = _state.sent();
439
- console.warn("[StormcloudVideoPlayer] crypto.subtle.digest not supported, using fallback hash");
464
+ unused = _state.sent();
465
+ console.warn("[StormcloudVideoPlayer] crypto.subtle not supported, using fallback hash");
440
466
  return [
441
467
  3,
442
468
  5
@@ -460,6 +486,10 @@ function getBrowserID(clientInfo) {
460
486
  });
461
487
  })();
462
488
  }
489
+ var mqttTopicPrefix = "adstorm";
490
+ function setMQTTTopicPrefix(prefix) {
491
+ mqttTopicPrefix = prefix || "adstorm";
492
+ }
463
493
  var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
464
494
  var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
465
495
  var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
@@ -468,43 +498,9 @@ function buildHeaders(licenseKey) {
468
498
  var headers = {
469
499
  "Content-Type": "application/json"
470
500
  };
471
- if (licenseKey) {
472
- headers["Authorization"] = "Bearer ".concat(licenseKey);
473
- }
501
+ if (licenseKey) headers["Authorization"] = "Bearer ".concat(licenseKey);
474
502
  return headers;
475
503
  }
476
- function sendTrackRequest(licenseKey, body) {
477
- return _async_to_generator(function() {
478
- var response;
479
- return _ts_generator(this, function(_state) {
480
- switch(_state.label){
481
- case 0:
482
- return [
483
- 4,
484
- fetch(TRACK_URL, {
485
- method: "POST",
486
- headers: buildHeaders(licenseKey),
487
- body: JSON.stringify(body)
488
- })
489
- ];
490
- case 1:
491
- response = _state.sent();
492
- if (!response.ok) {
493
- throw new Error("HTTP error! status: ".concat(response.status));
494
- }
495
- return [
496
- 4,
497
- response.json()
498
- ];
499
- case 2:
500
- _state.sent();
501
- return [
502
- 2
503
- ];
504
- }
505
- });
506
- })();
507
- }
508
504
  function postJson(url, licenseKey, body) {
509
505
  return _async_to_generator(function() {
510
506
  var response;
@@ -521,9 +517,7 @@ function postJson(url, licenseKey, body) {
521
517
  ];
522
518
  case 1:
523
519
  response = _state.sent();
524
- if (!response.ok) {
525
- throw new Error("HTTP error! status: ".concat(response.status));
526
- }
520
+ if (!response.ok) throw new Error("HTTP error! status: ".concat(response.status));
527
521
  return [
528
522
  4,
529
523
  response.json()
@@ -573,9 +567,33 @@ function buildPlayerMetricEvent(_0) {
573
567
  });
574
568
  }).apply(this, arguments);
575
569
  }
570
+ function publishOrPost(mqttTopic, httpUrl, licenseKey, body) {
571
+ return _async_to_generator(function() {
572
+ return _ts_generator(this, function(_state) {
573
+ switch(_state.label){
574
+ case 0:
575
+ if (isMQTTConfigured()) {
576
+ publishMQTT(mqttTopic, body);
577
+ return [
578
+ 2
579
+ ];
580
+ }
581
+ return [
582
+ 4,
583
+ postJson(httpUrl, licenseKey, body)
584
+ ];
585
+ case 1:
586
+ _state.sent();
587
+ return [
588
+ 2
589
+ ];
590
+ }
591
+ });
592
+ })();
593
+ }
576
594
  function sendInitialTracking(_0) {
577
595
  return _async_to_generator(function(licenseKey) {
578
- var context, clientInfo, browserId, trackingData, error;
596
+ var context, clientInfo, browserId, captureAt, trackingData, metricsBody, error;
579
597
  var _arguments = arguments;
580
598
  return _ts_generator(this, function(_state) {
581
599
  switch(_state.label){
@@ -596,26 +614,28 @@ function sendInitialTracking(_0) {
596
614
  ];
597
615
  case 2:
598
616
  browserId = _state.sent();
617
+ captureAt = /* @__PURE__ */ new Date().toISOString();
599
618
  trackingData = _object_spread({
600
619
  browserId: browserId
601
620
  }, clientInfo);
621
+ metricsBody = {
622
+ events: [
623
+ {
624
+ player_id: browserId,
625
+ device_type: clientInfo.deviceType,
626
+ input_stream_type: context.inputStreamType,
627
+ os: clientInfo.os,
628
+ ad_loaded: false,
629
+ ad_detect: false,
630
+ license_key: licenseKey,
631
+ capture_at: captureAt
632
+ }
633
+ ],
634
+ trackingData: trackingData
635
+ };
602
636
  return [
603
637
  4,
604
- sendTrackRequest(licenseKey, {
605
- events: [
606
- {
607
- player_id: browserId,
608
- device_type: clientInfo.deviceType,
609
- input_stream_type: context.inputStreamType,
610
- os: clientInfo.os,
611
- ad_loaded: false,
612
- ad_detect: false,
613
- license_key: licenseKey,
614
- capture_at: /* @__PURE__ */ new Date().toISOString()
615
- }
616
- ],
617
- trackingData: trackingData
618
- })
638
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/metrics"), TRACK_URL, licenseKey, metricsBody)
619
639
  ];
620
640
  case 3:
621
641
  _state.sent();
@@ -728,7 +748,7 @@ function sendAdLoadedTracking(_0, _1) {
728
748
  }
729
749
  function sendAdImpressionTracking(_0, _1) {
730
750
  return _async_to_generator(function(licenseKey, adImpressionInfo) {
731
- var context, metricEvent, error;
751
+ var context, metricEvent, heartbeatBody, impressionsBody, error;
732
752
  var _arguments = arguments;
733
753
  return _ts_generator(this, function(_state) {
734
754
  switch(_state.label){
@@ -750,21 +770,23 @@ function sendAdImpressionTracking(_0, _1) {
750
770
  ];
751
771
  case 2:
752
772
  metricEvent = _state.sent();
773
+ heartbeatBody = metricEvent;
774
+ impressionsBody = {
775
+ events: [
776
+ {
777
+ player_id: metricEvent.player_id,
778
+ ad_played_count: 1,
779
+ ad_url: adImpressionInfo.adUrl,
780
+ license_key: licenseKey,
781
+ capture_at: adImpressionInfo.timestamp
782
+ }
783
+ ]
784
+ };
753
785
  return [
754
786
  4,
755
787
  Promise.all([
756
- postJson(HEARTBEAT_URL, licenseKey, metricEvent),
757
- postJson(IMPRESSIONS_URL, licenseKey, {
758
- events: [
759
- {
760
- player_id: metricEvent.player_id,
761
- ad_played_count: 1,
762
- ad_url: adImpressionInfo.adUrl,
763
- license_key: licenseKey,
764
- capture_at: adImpressionInfo.timestamp
765
- }
766
- ]
767
- })
788
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/heartbeat"), HEARTBEAT_URL, licenseKey, heartbeatBody),
789
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/impressions"), IMPRESSIONS_URL, licenseKey, impressionsBody)
768
790
  ])
769
791
  ];
770
792
  case 3:
@@ -812,7 +834,7 @@ function sendHeartbeat(_0) {
812
834
  heartbeatData = _state.sent();
813
835
  return [
814
836
  4,
815
- postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
837
+ publishOrPost("".concat(mqttTopicPrefix, "/tracking/heartbeat"), HEARTBEAT_URL, licenseKey, heartbeatData)
816
838
  ];
817
839
  case 3:
818
840
  _state.sent();
@@ -843,6 +865,7 @@ function sendHeartbeat(_0) {
843
865
  sendAdImpressionTracking: sendAdImpressionTracking,
844
866
  sendAdLoadedTracking: sendAdLoadedTracking,
845
867
  sendHeartbeat: sendHeartbeat,
846
- sendInitialTracking: sendInitialTracking
868
+ sendInitialTracking: sendInitialTracking,
869
+ setMQTTTopicPrefix: setMQTTTopicPrefix
847
870
  });
848
871
  //# sourceMappingURL=tracking.cjs.map