stormcloud-video-player 0.8.78 → 0.8.80

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.
Files changed (76) hide show
  1. package/dist/stormcloud-vp.min.js +2 -2
  2. package/lib/Player.cjs +6 -0
  3. package/lib/Player.cjs.map +1 -1
  4. package/lib/Player.d.cts +2 -0
  5. package/lib/StormcloudPlayer.cjs +1143 -160
  6. package/lib/StormcloudPlayer.cjs.map +1 -1
  7. package/lib/StormcloudPlayer.d.cts +2 -0
  8. package/lib/index.cjs +1206 -162
  9. package/lib/index.cjs.map +1 -1
  10. package/lib/index.d.cts +2 -0
  11. package/lib/index.d.ts +64 -2
  12. package/lib/index.js +1206 -162
  13. package/lib/index.js.map +1 -1
  14. package/lib/player/AdBreakOrchestrator.cjs +424 -84
  15. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  16. package/lib/player/AdConfigManager.cjs +738 -94
  17. package/lib/player/AdConfigManager.cjs.map +1 -1
  18. package/lib/player/AdTimingService.cjs +0 -9
  19. package/lib/player/AdTimingService.cjs.map +1 -1
  20. package/lib/player/FloorLadder.cjs +3 -0
  21. package/lib/player/FloorLadder.cjs.map +1 -1
  22. package/lib/player/HlsEngine.cjs +7 -1
  23. package/lib/player/HlsEngine.cjs.map +1 -1
  24. package/lib/player/HlsEngine.d.cts +1 -0
  25. package/lib/player/OptimizedPodRequest.cjs +4 -1
  26. package/lib/player/OptimizedPodRequest.cjs.map +1 -1
  27. package/lib/player/OptimizedPodRequest.d.cts +1 -1
  28. package/lib/player/StormcloudVideoPlayer.cjs +1143 -160
  29. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  30. package/lib/player/StormcloudVideoPlayer.d.cts +18 -1
  31. package/lib/players/HlsPlayer.cjs +1143 -160
  32. package/lib/players/HlsPlayer.cjs.map +1 -1
  33. package/lib/players/index.cjs +1143 -160
  34. package/lib/players/index.cjs.map +1 -1
  35. package/lib/props.cjs +6 -0
  36. package/lib/props.cjs.map +1 -1
  37. package/lib/props.d.cts +2 -0
  38. package/lib/sdk/hlsAdPlayer.cjs +32 -3
  39. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  40. package/lib/sdk/pal.cjs +10 -3
  41. package/lib/sdk/pal.cjs.map +1 -1
  42. package/lib/sdk/pal.d.cts +3 -0
  43. package/lib/types.d.cts +24 -1
  44. package/lib/ui/StormcloudVideoPlayer.cjs +1206 -162
  45. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  46. package/lib/ui/StormcloudVideoPlayer.d.cts +2 -0
  47. package/lib/utils/__tests__/adSignals.test.cjs +25662 -0
  48. package/lib/utils/__tests__/adSignals.test.cjs.map +1 -0
  49. package/lib/utils/__tests__/adSignals.test.d.cts +2 -0
  50. package/lib/utils/adIdentity.cjs +421 -0
  51. package/lib/utils/adIdentity.cjs.map +1 -0
  52. package/lib/utils/adIdentity.d.cts +30 -0
  53. package/lib/utils/browserCompat.cjs +13 -0
  54. package/lib/utils/browserCompat.cjs.map +1 -1
  55. package/lib/utils/browserCompat.d.cts +2 -1
  56. package/lib/utils/contentMetadata.cjs +208 -0
  57. package/lib/utils/contentMetadata.cjs.map +1 -0
  58. package/lib/utils/contentMetadata.d.cts +15 -0
  59. package/lib/utils/ctvVastSignals.cjs +250 -181
  60. package/lib/utils/ctvVastSignals.cjs.map +1 -1
  61. package/lib/utils/deviceInfo.cjs +678 -0
  62. package/lib/utils/deviceInfo.cjs.map +1 -0
  63. package/lib/utils/deviceInfo.d.cts +43 -0
  64. package/lib/utils/screenActivity.cjs +125 -0
  65. package/lib/utils/screenActivity.cjs.map +1 -0
  66. package/lib/utils/screenActivity.d.cts +5 -0
  67. package/lib/utils/tracking.cjs +391 -57
  68. package/lib/utils/tracking.cjs.map +1 -1
  69. package/lib/utils/tracking.d.cts +1 -1
  70. package/lib/utils/vastEnvironmentSignals.cjs +255 -85
  71. package/lib/utils/vastEnvironmentSignals.cjs.map +1 -1
  72. package/lib/utils/vastEnvironmentSignals.d.cts +8 -2
  73. package/lib/utils/vastMacros.cjs +7 -0
  74. package/lib/utils/vastMacros.cjs.map +1 -1
  75. package/lib/utils/vastMacros.d.cts +1 -0
  76. package/package.json +1 -1
@@ -0,0 +1,678 @@
1
+ "use strict";
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function _define_property(obj, key, value) {
14
+ if (key in obj) {
15
+ Object.defineProperty(obj, key, {
16
+ value: value,
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true
20
+ });
21
+ } else obj[key] = value;
22
+ return obj;
23
+ }
24
+ function _iterable_to_array(iter) {
25
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
26
+ return Array.from(iter);
27
+ }
28
+ }
29
+ function _iterable_to_array_limit(arr, i) {
30
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
31
+ if (_i == null) return;
32
+ var _arr = [];
33
+ var _n = true;
34
+ var _d = false;
35
+ var _s, _e;
36
+ try {
37
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
38
+ _arr.push(_s.value);
39
+ if (i && _arr.length === i) break;
40
+ }
41
+ } catch (err) {
42
+ _d = true;
43
+ _e = err;
44
+ } finally{
45
+ try {
46
+ if (!_n && _i["return"] != null) _i["return"]();
47
+ } finally{
48
+ if (_d) throw _e;
49
+ }
50
+ }
51
+ return _arr;
52
+ }
53
+ function _non_iterable_rest() {
54
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
55
+ }
56
+ function _non_iterable_spread() {
57
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ }
59
+ function _object_spread(target) {
60
+ for(var i = 1; i < arguments.length; i++){
61
+ var source = arguments[i] != null ? arguments[i] : {};
62
+ var ownKeys = Object.keys(source);
63
+ if (typeof Object.getOwnPropertySymbols === "function") {
64
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
65
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
66
+ }));
67
+ }
68
+ ownKeys.forEach(function(key) {
69
+ _define_property(target, key, source[key]);
70
+ });
71
+ }
72
+ return target;
73
+ }
74
+ function ownKeys(object, enumerableOnly) {
75
+ var keys = Object.keys(object);
76
+ if (Object.getOwnPropertySymbols) {
77
+ var symbols = Object.getOwnPropertySymbols(object);
78
+ if (enumerableOnly) {
79
+ symbols = symbols.filter(function(sym) {
80
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
81
+ });
82
+ }
83
+ keys.push.apply(keys, symbols);
84
+ }
85
+ return keys;
86
+ }
87
+ function _object_spread_props(target, source) {
88
+ source = source != null ? source : {};
89
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
90
+ else {
91
+ ownKeys(Object(source)).forEach(function(key) {
92
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
93
+ });
94
+ }
95
+ return target;
96
+ }
97
+ function _sliced_to_array(arr, i) {
98
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
+ }
100
+ function _to_consumable_array(arr) {
101
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
102
+ }
103
+ function _type_of(obj) {
104
+ "@swc/helpers - typeof";
105
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
106
+ }
107
+ function _unsupported_iterable_to_array(o, minLen) {
108
+ if (!o) return;
109
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
110
+ var n = Object.prototype.toString.call(o).slice(8, -1);
111
+ if (n === "Object" && o.constructor) n = o.constructor.name;
112
+ if (n === "Map" || n === "Set") return Array.from(n);
113
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
114
+ }
115
+ var __defProp = Object.defineProperty;
116
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
117
+ var __getOwnPropNames = Object.getOwnPropertyNames;
118
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
119
+ var __export = function __export(target, all) {
120
+ for(var name in all)__defProp(target, name, {
121
+ get: all[name],
122
+ enumerable: true
123
+ });
124
+ };
125
+ var __copyProps = function __copyProps(to, from, except, desc) {
126
+ if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
127
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
128
+ try {
129
+ var _loop = function() {
130
+ var key = _step.value;
131
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
132
+ get: function get() {
133
+ return from[key];
134
+ },
135
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
136
+ });
137
+ };
138
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
139
+ } catch (err) {
140
+ _didIteratorError = true;
141
+ _iteratorError = err;
142
+ } finally{
143
+ try {
144
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
145
+ _iterator.return();
146
+ }
147
+ } finally{
148
+ if (_didIteratorError) {
149
+ throw _iteratorError;
150
+ }
151
+ }
152
+ }
153
+ }
154
+ return to;
155
+ };
156
+ var __toCommonJS = function __toCommonJS(mod) {
157
+ return __copyProps(__defProp({}, "__esModule", {
158
+ value: true
159
+ }), mod);
160
+ };
161
+ // src/utils/deviceInfo.ts
162
+ var deviceInfo_exports = {};
163
+ __export(deviceInfo_exports, {
164
+ DEVICE_KEY_VALUE_KEYS: function DEVICE_KEY_VALUE_KEYS1() {
165
+ return DEVICE_KEY_VALUE_KEYS;
166
+ },
167
+ __resetDeviceInfoStateForTests: function __resetDeviceInfoStateForTests1() {
168
+ return __resetDeviceInfoStateForTests;
169
+ },
170
+ applyDeviceKeyValues: function applyDeviceKeyValues1() {
171
+ return applyDeviceKeyValues;
172
+ },
173
+ deviceInfoAnalyticsFields: function deviceInfoAnalyticsFields1() {
174
+ return deviceInfoAnalyticsFields;
175
+ },
176
+ deviceKeyValuePairs: function deviceKeyValuePairs1() {
177
+ return deviceKeyValuePairs;
178
+ },
179
+ getDeviceInfo: function getDeviceInfo1() {
180
+ return getDeviceInfo;
181
+ },
182
+ parseUserAgentDeviceInfo: function parseUserAgentDeviceInfo1() {
183
+ return parseUserAgentDeviceInfo;
184
+ },
185
+ primeDeviceInfo: function primeDeviceInfo1() {
186
+ return primeDeviceInfo;
187
+ },
188
+ sanitizeKeyValue: function sanitizeKeyValue1() {
189
+ return sanitizeKeyValue;
190
+ },
191
+ setHostDeviceInfo: function setHostDeviceInfo1() {
192
+ return setHostDeviceInfo;
193
+ }
194
+ });
195
+ module.exports = __toCommonJS(deviceInfo_exports);
196
+ // src/utils/adIdentity.ts
197
+ var MAX_SESSION_ID_AGE_MS = 6 * 60 * 60 * 1e3;
198
+ var DEFAULT_FALLBACK_DEVICE_ID_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
199
+ var DEFAULT_LGUDID_TIMEOUT_MS = 1500;
200
+ var ZEROED_IDS = /* @__PURE__ */ new Set([
201
+ "00000000-0000-0000-0000-000000000000",
202
+ "38400000-8cf0-11bd-b23e-10b96e40000d"
203
+ ]);
204
+ var lgUdidResult;
205
+ var lgUdidPromise;
206
+ function isUsableAdId(value) {
207
+ if (typeof value !== "string") return false;
208
+ var t = value.trim();
209
+ if (!t) return false;
210
+ if (/^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%|\$\{[^}]+\})$/.test(t)) return false;
211
+ if (/^(unknown|null|undefined|none|n\/a)$/i.test(t)) return false;
212
+ return !ZEROED_IDS.has(t.toLowerCase());
213
+ }
214
+ function isZeroedAdId(value) {
215
+ return typeof value === "string" && ZEROED_IDS.has(value.trim().toLowerCase());
216
+ }
217
+ function primeLgUdid() {
218
+ var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DEFAULT_LGUDID_TIMEOUT_MS;
219
+ if (lgUdidResult || lgUdidPromise) return lgUdidPromise !== null && lgUdidPromise !== void 0 ? lgUdidPromise : Promise.resolve();
220
+ var dev = typeof window !== "undefined" ? window.webOSDev : void 0;
221
+ if (!dev) return Promise.resolve();
222
+ if (typeof dev.LGUDID !== "function") {
223
+ var _dev_lgudid;
224
+ var direct = (_dev_lgudid = dev.lgudid) !== null && _dev_lgudid !== void 0 ? _dev_lgudid : dev.LGUDID;
225
+ if (isZeroedAdId(direct)) lgUdidResult = {
226
+ deviceIdType: "lgudid",
227
+ limitAdTracking: true
228
+ };
229
+ else if (isUsableAdId(direct)) {
230
+ lgUdidResult = {
231
+ deviceId: direct.trim(),
232
+ deviceIdType: "lgudid",
233
+ limitAdTracking: false
234
+ };
235
+ }
236
+ return Promise.resolve();
237
+ }
238
+ lgUdidPromise = new Promise(function(resolve) {
239
+ var settled = false;
240
+ var finish = function finish() {
241
+ if (settled) return;
242
+ settled = true;
243
+ clearTimeout(timer);
244
+ resolve();
245
+ };
246
+ var timer = setTimeout(finish, Math.max(0, timeoutMs));
247
+ try {
248
+ dev.LGUDID({
249
+ onSuccess: function onSuccess(res) {
250
+ var id = res === null || res === void 0 ? void 0 : res.id;
251
+ if (isZeroedAdId(id)) {
252
+ lgUdidResult = {
253
+ deviceIdType: "lgudid",
254
+ limitAdTracking: true
255
+ };
256
+ } else if (isUsableAdId(id)) {
257
+ lgUdidResult = {
258
+ deviceId: id.trim(),
259
+ deviceIdType: "lgudid",
260
+ limitAdTracking: false
261
+ };
262
+ }
263
+ finish();
264
+ },
265
+ onFailure: function onFailure() {
266
+ return finish();
267
+ }
268
+ });
269
+ } catch (unused) {
270
+ finish();
271
+ }
272
+ });
273
+ return lgUdidPromise;
274
+ }
275
+ function readCachedLgUdid() {
276
+ return lgUdidResult ? _object_spread({}, lgUdidResult) : void 0;
277
+ }
278
+ // src/utils/deviceInfo.ts
279
+ var CATEGORY_CODES = {
280
+ "LG TV": "lg_tv",
281
+ "LG Set-Top Box": "lg_stb",
282
+ "Samsung TV": "samsung_tv",
283
+ Other: "other"
284
+ };
285
+ var DEVICE_CATEGORIES = [
286
+ "LG TV",
287
+ "LG Set-Top Box",
288
+ "Samsung TV",
289
+ "Other"
290
+ ];
291
+ var hostDeviceInfo;
292
+ var lgDeviceInfo;
293
+ var platformCache;
294
+ var primePromise;
295
+ function cleanString(value) {
296
+ var maxLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 128;
297
+ if (typeof value !== "string") return void 0;
298
+ var t = value.replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
299
+ if (!t || /^(unknown|null|undefined|none|n\/a|-|0)$/i.test(t)) return void 0;
300
+ return t.length > maxLength ? t.slice(0, maxLength) : t;
301
+ }
302
+ function safeCall(fn, thisArg) {
303
+ if (typeof fn !== "function") return void 0;
304
+ try {
305
+ return fn.call(thisArg);
306
+ } catch (unused) {
307
+ return void 0;
308
+ }
309
+ }
310
+ function userAgent() {
311
+ return typeof navigator !== "undefined" ? navigator.userAgent || "" : "";
312
+ }
313
+ function bridgeSources() {
314
+ if (typeof window === "undefined") return [];
315
+ var w = window;
316
+ return [
317
+ w.__STORMCLOUD_CTV__,
318
+ w.__STORMCLOUD_CTV_AD_INFO__,
319
+ w.stormcloudCtv
320
+ ].filter(Boolean);
321
+ }
322
+ function readBridge(keys) {
323
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
324
+ try {
325
+ for(var _iterator = bridgeSources()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
326
+ var source = _step.value;
327
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
328
+ try {
329
+ for(var _iterator1 = keys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
330
+ var key = _step1.value;
331
+ var value = void 0;
332
+ try {
333
+ value = source === null || source === void 0 ? void 0 : source[key];
334
+ if (typeof value === "function") value = value.call(source);
335
+ } catch (unused) {
336
+ value = void 0;
337
+ }
338
+ var clean = cleanString(value);
339
+ if (clean) return clean;
340
+ }
341
+ } catch (err) {
342
+ _didIteratorError1 = true;
343
+ _iteratorError1 = err;
344
+ } finally{
345
+ try {
346
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
347
+ _iterator1.return();
348
+ }
349
+ } finally{
350
+ if (_didIteratorError1) {
351
+ throw _iteratorError1;
352
+ }
353
+ }
354
+ }
355
+ }
356
+ } catch (err) {
357
+ _didIteratorError = true;
358
+ _iteratorError = err;
359
+ } finally{
360
+ try {
361
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
362
+ _iterator.return();
363
+ }
364
+ } finally{
365
+ if (_didIteratorError) {
366
+ throw _iteratorError;
367
+ }
368
+ }
369
+ }
370
+ return void 0;
371
+ }
372
+ function normalizeCategory(value) {
373
+ var v = cleanString(value);
374
+ if (!v) return void 0;
375
+ var exact = DEVICE_CATEGORIES.find(function(c) {
376
+ return c.toLowerCase() === v.toLowerCase();
377
+ });
378
+ if (exact) return exact;
379
+ var code = v.toLowerCase().replace(/[\s-]+/g, "_");
380
+ var byCode = Object.keys(CATEGORY_CODES).find(function(c) {
381
+ return CATEGORY_CODES[c] === code;
382
+ });
383
+ return byCode;
384
+ }
385
+ function parseUserAgentDeviceInfo(ua) {
386
+ var sources = [];
387
+ var out = {
388
+ platform: "other",
389
+ sources: sources
390
+ };
391
+ var chrome = ua.match(/(?:Chrome|PCBR)\/(\d+)\./) || ua.match(/\s(\d{2,3})\.\d+\.\d+\.\d+\/[\d.]+\s+TV\b/);
392
+ if (chrome && chrome[1]) out.browserMajorVersion = parseInt(chrome[1], 10);
393
+ if (/Web0S|webOS/i.test(ua)) {
394
+ out.platform = "webos";
395
+ var lg = ua.match(/LGE\s*;\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*;\s*(\d{2}\.\d{2}\.\d{2})/);
396
+ if (lg && lg[1] && lg[2]) {
397
+ out.model = lg[1];
398
+ out.firmware = lg[2];
399
+ sources.push("user_agent");
400
+ }
401
+ } else if (/Tizen/i.test(ua)) {
402
+ out.platform = "tizen";
403
+ var tizen = ua.match(/Tizen\s+(\d+(?:\.\d+)*)/i);
404
+ if (tizen && tizen[1]) {
405
+ out.osVersion = "Tizen ".concat(tizen[1]);
406
+ sources.push("user_agent");
407
+ }
408
+ }
409
+ return out;
410
+ }
411
+ function readSamsungProductInfo() {
412
+ var _cleanString;
413
+ var _window_webapis;
414
+ if (typeof window === "undefined") return void 0;
415
+ var productinfo = (_window_webapis = window.webapis) === null || _window_webapis === void 0 ? void 0 : _window_webapis.productinfo;
416
+ if (!productinfo) return void 0;
417
+ var model = (_cleanString = cleanString(safeCall(productinfo.getRealModel, productinfo), 40)) !== null && _cleanString !== void 0 ? _cleanString : cleanString(safeCall(productinfo.getModel, productinfo), 40);
418
+ var firmware = cleanString(safeCall(productinfo.getFirmware, productinfo), 64);
419
+ var duid = cleanString(safeCall(productinfo.getDuid, productinfo), 128);
420
+ if (!model && !firmware && !duid) return void 0;
421
+ return _object_spread({}, model ? {
422
+ model: model
423
+ } : {}, firmware ? {
424
+ firmware: firmware
425
+ } : {}, duid ? {
426
+ internalDeviceId: duid,
427
+ internalDeviceIdSource: "samsung_duid"
428
+ } : {});
429
+ }
430
+ function readLgDeviceInfo(timeoutMs) {
431
+ var webOS = typeof window !== "undefined" ? window.webOS : void 0;
432
+ if (lgDeviceInfo || !webOS || typeof webOS.deviceInfo !== "function") return Promise.resolve();
433
+ return new Promise(function(resolve) {
434
+ var settled = false;
435
+ var finish = function finish() {
436
+ if (settled) return;
437
+ settled = true;
438
+ clearTimeout(timer);
439
+ resolve();
440
+ };
441
+ var timer = setTimeout(finish, Math.max(0, timeoutMs));
442
+ try {
443
+ webOS.deviceInfo(function(info) {
444
+ var model = cleanString(info === null || info === void 0 ? void 0 : info.modelName, 40);
445
+ var firmware = cleanString(info === null || info === void 0 ? void 0 : info.version, 64);
446
+ var sdkVersion = cleanString(info === null || info === void 0 ? void 0 : info.sdkVersion, 32);
447
+ lgDeviceInfo = _object_spread({}, model ? {
448
+ model: model
449
+ } : {}, firmware ? {
450
+ firmware: firmware
451
+ } : {}, sdkVersion ? {
452
+ sdkVersion: sdkVersion
453
+ } : {});
454
+ finish();
455
+ });
456
+ } catch (unused) {
457
+ finish();
458
+ }
459
+ });
460
+ }
461
+ function computePlatformInfo() {
462
+ var info = parseUserAgentDeviceInfo(userAgent());
463
+ var sources = _to_consumable_array(info.sources);
464
+ var samsung = readSamsungProductInfo();
465
+ if (samsung) {
466
+ info.platform = "tizen";
467
+ if (samsung.model) info.model = samsung.model;
468
+ if (samsung.firmware) info.firmware = samsung.firmware;
469
+ if (samsung.internalDeviceId) {
470
+ info.internalDeviceId = samsung.internalDeviceId;
471
+ info.internalDeviceIdSource = "samsung_duid";
472
+ }
473
+ sources.push("samsung_productinfo");
474
+ }
475
+ if (lgDeviceInfo) {
476
+ info.platform = "webos";
477
+ if (!info.model && lgDeviceInfo.model) info.model = lgDeviceInfo.model;
478
+ if (!info.firmware && lgDeviceInfo.firmware) info.firmware = lgDeviceInfo.firmware;
479
+ if (lgDeviceInfo.sdkVersion) info.osVersion = "webOS TV ".concat(lgDeviceInfo.sdkVersion);
480
+ sources.push("lg_deviceinfo");
481
+ }
482
+ var lgUdid = readCachedLgUdid();
483
+ if ((lgUdid === null || lgUdid === void 0 ? void 0 : lgUdid.deviceId) && !info.internalDeviceId) {
484
+ info.internalDeviceId = lgUdid.deviceId;
485
+ info.internalDeviceIdSource = "lg_udid";
486
+ sources.push("lg_udid");
487
+ }
488
+ info.sources = sources;
489
+ return info;
490
+ }
491
+ function categorize(platform, model) {
492
+ if (platform === "tizen") return "Samsung TV";
493
+ if (platform === "webos") {
494
+ var ua = userAgent();
495
+ if (model && /^STB-/i.test(model) || /\bSTB-\d{4}|LGSTB/i.test(ua)) return "LG Set-Top Box";
496
+ return "LG TV";
497
+ }
498
+ return "Other";
499
+ }
500
+ function setHostDeviceInfo(info) {
501
+ hostDeviceInfo = info ? _object_spread({}, info) : void 0;
502
+ }
503
+ function primeDeviceInfo() {
504
+ var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1500;
505
+ if (!primePromise) {
506
+ primePromise = Promise.all([
507
+ readLgDeviceInfo(timeoutMs),
508
+ primeLgUdid(timeoutMs)
509
+ ]).catch(function() {
510
+ return void 0;
511
+ }).then(function() {
512
+ platformCache = computePlatformInfo();
513
+ return getDeviceInfo();
514
+ });
515
+ }
516
+ return primePromise;
517
+ }
518
+ function getDeviceInfo() {
519
+ var _cleanString, _cleanString1, _ref, _cleanString2, _ref1, _cleanString3, _ref2, _normalizeCategory;
520
+ var platform = platformCache !== null && platformCache !== void 0 ? platformCache : computePlatformInfo();
521
+ if (primePromise && !platformCache) {} else {
522
+ platformCache = platform;
523
+ }
524
+ var host = hostDeviceInfo !== null && hostDeviceInfo !== void 0 ? hostDeviceInfo : {};
525
+ var bridge = {
526
+ terminalId: readBridge([
527
+ "terminalId",
528
+ "terminal_id"
529
+ ]),
530
+ internalDeviceId: readBridge([
531
+ "internalDeviceId",
532
+ "internal_device_id"
533
+ ]),
534
+ model: readBridge([
535
+ "deviceModel"
536
+ ]),
537
+ firmware: readBridge([
538
+ "firmwareVersion"
539
+ ]),
540
+ category: normalizeCategory(readBridge([
541
+ "deviceCategory"
542
+ ]))
543
+ };
544
+ var terminalId = (_cleanString = cleanString(host.terminalId)) !== null && _cleanString !== void 0 ? _cleanString : bridge.terminalId;
545
+ var hostInternalId = (_cleanString1 = cleanString(host.internalDeviceId)) !== null && _cleanString1 !== void 0 ? _cleanString1 : bridge.internalDeviceId;
546
+ var model = (_ref = (_cleanString2 = cleanString(host.model, 40)) !== null && _cleanString2 !== void 0 ? _cleanString2 : bridge.model) !== null && _ref !== void 0 ? _ref : platform.model;
547
+ var firmware = (_ref1 = (_cleanString3 = cleanString(host.firmware, 64)) !== null && _cleanString3 !== void 0 ? _cleanString3 : bridge.firmware) !== null && _ref1 !== void 0 ? _ref1 : platform.firmware;
548
+ var category = (_ref2 = (_normalizeCategory = normalizeCategory(host.category)) !== null && _normalizeCategory !== void 0 ? _normalizeCategory : bridge.category) !== null && _ref2 !== void 0 ? _ref2 : categorize(platform.platform, model);
549
+ var sources = _to_consumable_array(platform.sources);
550
+ var bridgeValues = [
551
+ bridge.terminalId,
552
+ bridge.internalDeviceId,
553
+ bridge.model,
554
+ bridge.firmware,
555
+ bridge.category
556
+ ];
557
+ if (bridgeValues.some(function(v) {
558
+ return v !== void 0;
559
+ })) sources.unshift("bridge");
560
+ if (hostDeviceInfo) sources.unshift("host");
561
+ var internalDeviceId = hostInternalId !== null && hostInternalId !== void 0 ? hostInternalId : platform.internalDeviceId;
562
+ var internalDeviceIdSource = hostInternalId ? "host" : platform.internalDeviceIdSource;
563
+ var sonifiModel = model && category === "Samsung TV" && !/^SAMSUNG-IPTV-/i.test(model) ? "SAMSUNG-IPTV-".concat(model) : model;
564
+ return _object_spread_props(_object_spread({
565
+ category: category,
566
+ categoryCode: CATEGORY_CODES[category]
567
+ }, model ? {
568
+ model: model
569
+ } : {}, sonifiModel ? {
570
+ sonifiModel: sonifiModel
571
+ } : {}, firmware ? {
572
+ firmware: firmware
573
+ } : {}, platform.osVersion ? {
574
+ osVersion: platform.osVersion
575
+ } : {}, platform.browserMajorVersion != null ? {
576
+ browserMajorVersion: platform.browserMajorVersion
577
+ } : {}, internalDeviceId ? {
578
+ internalDeviceId: internalDeviceId
579
+ } : {}, internalDeviceId && internalDeviceIdSource ? {
580
+ internalDeviceIdSource: internalDeviceIdSource
581
+ } : {}, terminalId ? {
582
+ terminalId: terminalId
583
+ } : {}), {
584
+ sources: sources
585
+ });
586
+ }
587
+ var DEVICE_KEY_VALUE_KEYS = {
588
+ category: "sc_dev",
589
+ model: "sc_model",
590
+ firmware: "sc_fw"
591
+ };
592
+ function sanitizeKeyValue(value) {
593
+ if (typeof value !== "string") return void 0;
594
+ var v = value.trim().replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "");
595
+ return v ? v.slice(0, 40) : void 0;
596
+ }
597
+ function deviceKeyValuePairs(info) {
598
+ var pairs = [
599
+ [
600
+ DEVICE_KEY_VALUE_KEYS.category,
601
+ info.categoryCode
602
+ ]
603
+ ];
604
+ var model = sanitizeKeyValue(info.model);
605
+ var firmware = sanitizeKeyValue(info.firmware);
606
+ if (model) pairs.push([
607
+ DEVICE_KEY_VALUE_KEYS.model,
608
+ model
609
+ ]);
610
+ if (firmware) pairs.push([
611
+ DEVICE_KEY_VALUE_KEYS.firmware,
612
+ firmware
613
+ ]);
614
+ return pairs;
615
+ }
616
+ function applyDeviceKeyValues(url, info) {
617
+ try {
618
+ var parsed = new URL(url);
619
+ var pairs = deviceKeyValuePairs(info);
620
+ var ours = new Set(pairs.map(function(param) {
621
+ var _param = _sliced_to_array(param, 1), k = _param[0];
622
+ return k;
623
+ }));
624
+ var existing = (parsed.searchParams.get("cust_params") || "").split("&").filter(function(p) {
625
+ var _p_split_;
626
+ return p !== "" && !ours.has((_p_split_ = p.split("=")[0]) !== null && _p_split_ !== void 0 ? _p_split_ : "");
627
+ });
628
+ var merged = existing.concat(pairs.map(function(param) {
629
+ var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
630
+ return "".concat(k, "=").concat(v);
631
+ })).join("&");
632
+ parsed.searchParams.set("cust_params", merged);
633
+ return parsed.toString();
634
+ } catch (unused) {
635
+ return url;
636
+ }
637
+ }
638
+ function deviceInfoAnalyticsFields(info) {
639
+ return _object_spread({
640
+ device_category: info.category
641
+ }, info.model ? {
642
+ device_model: info.model
643
+ } : {}, info.sonifiModel ? {
644
+ sonifi_model: info.sonifiModel
645
+ } : {}, info.firmware ? {
646
+ firmware_version: info.firmware
647
+ } : {}, info.osVersion ? {
648
+ os_version: info.osVersion
649
+ } : {}, info.browserMajorVersion != null ? {
650
+ browser_major_version: info.browserMajorVersion
651
+ } : {}, info.internalDeviceId ? {
652
+ internal_device_id: info.internalDeviceId
653
+ } : {}, info.internalDeviceIdSource ? {
654
+ internal_device_id_source: info.internalDeviceIdSource
655
+ } : {}, info.terminalId ? {
656
+ terminal_id: info.terminalId
657
+ } : {});
658
+ }
659
+ function __resetDeviceInfoStateForTests() {
660
+ hostDeviceInfo = void 0;
661
+ lgDeviceInfo = void 0;
662
+ platformCache = void 0;
663
+ primePromise = void 0;
664
+ }
665
+ // Annotate the CommonJS export names for ESM import in node:
666
+ 0 && (module.exports = {
667
+ DEVICE_KEY_VALUE_KEYS: DEVICE_KEY_VALUE_KEYS,
668
+ __resetDeviceInfoStateForTests: __resetDeviceInfoStateForTests,
669
+ applyDeviceKeyValues: applyDeviceKeyValues,
670
+ deviceInfoAnalyticsFields: deviceInfoAnalyticsFields,
671
+ deviceKeyValuePairs: deviceKeyValuePairs,
672
+ getDeviceInfo: getDeviceInfo,
673
+ parseUserAgentDeviceInfo: parseUserAgentDeviceInfo,
674
+ primeDeviceInfo: primeDeviceInfo,
675
+ sanitizeKeyValue: sanitizeKeyValue,
676
+ setHostDeviceInfo: setHostDeviceInfo
677
+ });
678
+ //# sourceMappingURL=deviceInfo.cjs.map