@ceeblue/web-utils 5.0.0 → 6.0.0

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/.codecov.yml ADDED
@@ -0,0 +1,21 @@
1
+ coverage:
2
+ status:
3
+ project:
4
+ default:
5
+ target: 90%
6
+ threshold: 10%
7
+ patch:
8
+ default:
9
+ target: 90%
10
+ threshold: 10%
11
+
12
+ comment:
13
+ layout: "reach, diff, flags, files"
14
+ behavior: default
15
+ require_changes: true
16
+
17
+ ignore:
18
+ - "**/*.test.ts"
19
+ - "**/*.spec.ts"
20
+ - "**/__tests__/**"
21
+ - "**/__mocks__/**"
@@ -273,6 +273,41 @@ declare class ByteRate {
273
273
  private updateSamples;
274
274
  }
275
275
 
276
+ /**
277
+ * Parameters of a key system for encrypted streams (DRM)
278
+ *
279
+ * If the key system is a string, it's the URL of the license server.
280
+ *
281
+ * If the key system is an object, it's a key system configuration with more parameters.
282
+ */
283
+ type KeySystem = string | {
284
+ /**
285
+ * The license server URL
286
+ */
287
+ licenseUrl: string;
288
+ /**
289
+ * The certificate URL if needed (for FairPlay)
290
+ *
291
+ * Or directly the certificate
292
+ */
293
+ certificate?: string | Uint8Array;
294
+ /**
295
+ * The additional HTTP headers to send to the license server
296
+ */
297
+ headers?: Record<string, string>;
298
+ /**
299
+ * Audio robustness level
300
+ *
301
+ * A list of robustness levels, prioritized by the order of the array.
302
+ */
303
+ audioRobustness?: string[];
304
+ /**
305
+ * Video robustness level
306
+ *
307
+ * A list of robustness levels, prioritized by the order of the array.
308
+ */
309
+ videoRobustness?: string[];
310
+ };
276
311
  /**
277
312
  * Parameters of connections
278
313
  */
@@ -296,6 +331,11 @@ type Params = {
296
331
  * iceServer to use while connecting to a WebRTC stream
297
332
  */
298
333
  iceServer?: RTCIceServer;
334
+ /**
335
+ * Map of keys to content protection settings for encrypted streams
336
+ * The key can be "com.apple.fps" for example for FairPlay
337
+ */
338
+ contentProtection?: Record<string, KeySystem>;
299
339
  /**
300
340
  * Optional media extension (mp4, flv, ts, rts), usefull for protocol like WebRTS which supports different container type.
301
341
  * When not set, it's also an output parameter for {@link defineMediaExt} to indicate what is the media type selected
@@ -337,13 +377,14 @@ declare function defineMediaExt(type: Type, params: Params): void;
337
377
  */
338
378
  declare function buildURL(type: Type, params: Params, protocol?: string): URL;
339
379
 
380
+ type Connect_KeySystem = KeySystem;
340
381
  type Connect_Params = Params;
341
382
  type Connect_Type = Type;
342
383
  declare const Connect_Type: typeof Type;
343
384
  declare const Connect_buildURL: typeof buildURL;
344
385
  declare const Connect_defineMediaExt: typeof defineMediaExt;
345
386
  declare namespace Connect {
346
- export { type Connect_Params as Params, Connect_Type as Type, Connect_buildURL as buildURL, Connect_defineMediaExt as defineMediaExt };
387
+ export { type Connect_KeySystem as KeySystem, type Connect_Params as Params, Connect_Type as Type, Connect_buildURL as buildURL, Connect_defineMediaExt as defineMediaExt };
347
388
  }
348
389
 
349
390
  /**
@@ -776,13 +817,22 @@ declare const SDP: {
776
817
  */
777
818
  declare const EMPTY_FUNCTION: () => void;
778
819
  /**
779
- * Efficient and high resolution timestamp in milliseconds elapsed since {@link Util.timeOrigin}
820
+ * Returns an efficient timestamp in milliseconds elapsed since {@link performance.timeOrigin},
821
+ * representing the start of the current JavaScript execution context.
822
+ *
823
+ * Note: Each Web Worker runs in a separate JS context, so timestamps
824
+ * are not directly comparable between different workers. Use {@link unixTime}
825
+ * for comparable timestamps across different Web Workers.
780
826
  */
781
827
  declare function time(): number;
782
828
  /**
783
- * Time origin represents the time when the application has started
829
+ * Returns an efficient Unix timestamp in milliseconds.
830
+ *
831
+ * Unix timestamps are universally comparable across different JavaScript
832
+ * contexts (e.g., Web Workers), as they reference the number of milliseconds
833
+ * elapsed since January 1, 1970 (UNIX epoch).
784
834
  */
785
- declare function timeOrigin(): number;
835
+ declare function unixTime(): number;
786
836
  /**
787
837
  * Parse query and returns it in an easy-to-use Javascript object form
788
838
  * @param urlOrQueryOrSearch string, url, or searchParams containing query. If not set it uses `location.search` to determinate query.
@@ -902,13 +952,13 @@ declare const Util_safePromise: typeof safePromise;
902
952
  declare const Util_sleep: typeof sleep;
903
953
  declare const Util_stringify: typeof stringify;
904
954
  declare const Util_time: typeof time;
905
- declare const Util_timeOrigin: typeof timeOrigin;
906
955
  declare const Util_toBin: typeof toBin;
907
956
  declare const Util_trim: typeof trim;
908
957
  declare const Util_trimEnd: typeof trimEnd;
909
958
  declare const Util_trimStart: typeof trimStart;
959
+ declare const Util_unixTime: typeof unixTime;
910
960
  declare namespace Util {
911
- export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_equal as equal, Util_fetch as fetch, Util_getBaseFile as getBaseFile, Util_getExtension as getExtension, Util_getFile as getFile, Util_iterableEntries as iterableEntries, Util_objectFrom as objectFrom, Util_options as options, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin, Util_trim as trim, Util_trimEnd as trimEnd, Util_trimStart as trimStart };
961
+ export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_equal as equal, Util_fetch as fetch, Util_getBaseFile as getBaseFile, Util_getExtension as getExtension, Util_getFile as getFile, Util_iterableEntries as iterableEntries, Util_objectFrom as objectFrom, Util_options as options, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_toBin as toBin, Util_trim as trim, Util_trimEnd as trimEnd, Util_trimStart as trimStart, Util_unixTime as unixTime };
912
962
  }
913
963
 
914
964
  /**
@@ -1183,6 +1233,7 @@ declare class UIMetrics {
1183
1233
  private _legendFontSize;
1184
1234
  private _stepSize;
1185
1235
  private _ranges;
1236
+ private _mouseX?;
1186
1237
  constructor(ui: HTMLElement);
1187
1238
  /**
1188
1239
  * Reset metrics stats, essentially rescaling the metrics
package/dist/web-utils.js CHANGED
@@ -164,16 +164,25 @@ const _perf = performance; // to increase x10 now performance!
164
164
  */
165
165
  const EMPTY_FUNCTION = () => { };
166
166
  /**
167
- * Efficient and high resolution timestamp in milliseconds elapsed since {@link Util.timeOrigin}
167
+ * Returns an efficient timestamp in milliseconds elapsed since {@link performance.timeOrigin},
168
+ * representing the start of the current JavaScript execution context.
169
+ *
170
+ * Note: Each Web Worker runs in a separate JS context, so timestamps
171
+ * are not directly comparable between different workers. Use {@link unixTime}
172
+ * for comparable timestamps across different Web Workers.
168
173
  */
169
174
  function time() {
170
175
  return Math.floor(_perf.now());
171
176
  }
172
177
  /**
173
- * Time origin represents the time when the application has started
178
+ * Returns an efficient Unix timestamp in milliseconds.
179
+ *
180
+ * Unix timestamps are universally comparable across different JavaScript
181
+ * contexts (e.g., Web Workers), as they reference the number of milliseconds
182
+ * elapsed since January 1, 1970 (UNIX epoch).
174
183
  */
175
- function timeOrigin() {
176
- return Math.floor(_perf.now() + _perf.timeOrigin);
184
+ function unixTime() {
185
+ return Math.floor(_perf.timeOrigin + _perf.now());
177
186
  }
178
187
  /**
179
188
  * Parse query and returns it in an easy-to-use Javascript object form
@@ -491,7 +500,7 @@ function trimEnd(value, chars = ' ') {
491
500
  --i;
492
501
  }
493
502
  return value.substring(0, i);
494
- }var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getBaseFile:getBaseFile,getExtension:getExtension,getFile:getFile,iterableEntries:iterableEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart});/**
503
+ }var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getBaseFile:getBaseFile,getExtension:getExtension,getFile:getFile,iterableEntries:iterableEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart,unixTime:unixTime});/**
495
504
  * Copyright 2024 Ceeblue B.V.
496
505
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
497
506
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
@@ -1032,6 +1041,8 @@ class NetAddress {
1032
1041
  * console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'
1033
1042
  */
1034
1043
  static fixProtocol(protocol, address) {
1044
+ // Remove leading slashes for absolute pathes!
1045
+ address = address.replace(/^[\/]+/, '');
1035
1046
  const found = address.indexOf('://');
1036
1047
  // isolate protocol is present in address
1037
1048
  if (found >= 0) {
@@ -1118,14 +1129,14 @@ class NetAddress {
1118
1129
  this._host = address;
1119
1130
  this._domain = address;
1120
1131
  this._port = defaultPort;
1121
- // Parse Port
1122
- pos = this._host.lastIndexOf(':');
1123
- const endOfBrace = this._host.lastIndexOf(']'); // to support IPv6
1124
- if (pos > endOfBrace) {
1125
- const port = parseInt(address.substring(pos + 1));
1126
- if (port >= 0 && port <= 0xffff) {
1127
- this._port = port;
1128
- this._domain = address.substring(0, pos);
1132
+ const domainPortMatch = this._host.match(/^(?:\[([0-9a-fA-F:]+)\]|([^:/?#]+))(?::(\d+))?(?=[/#?]|$)/);
1133
+ if (domainPortMatch) {
1134
+ this._domain = domainPortMatch[1] || domainPortMatch[2];
1135
+ if (domainPortMatch[3]) {
1136
+ const port = parseInt(domainPortMatch[3]);
1137
+ if (port >= 0 && port <= 0xffff) {
1138
+ this._port = port;
1139
+ }
1129
1140
  }
1130
1141
  }
1131
1142
  }
@@ -1360,11 +1371,12 @@ class EventEmitter extends Loggable {
1360
1371
  throw Error('event callback must be a function');
1361
1372
  }
1362
1373
  const events = this._event(name);
1363
- events.add((...args) => {
1364
- events.delete(event); // delete from events
1374
+ const wrapper = (...args) => {
1375
+ events.delete(wrapper); // delete the wrapper from events
1365
1376
  event(...args); // execute event
1366
- });
1367
- (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(event), { once: true });
1377
+ };
1378
+ events.add(wrapper);
1379
+ (_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => events.delete(wrapper), { once: true });
1368
1380
  }
1369
1381
  /**
1370
1382
  * Event unsubscription
@@ -2288,6 +2300,12 @@ class UIMetrics {
2288
2300
  }
2289
2301
  constructor(ui) {
2290
2302
  this._ui = ui;
2303
+ ui.addEventListener('mousemove', (event) => {
2304
+ this._mouseX = event.offsetX;
2305
+ });
2306
+ ui.addEventListener('mouseleave', (event) => {
2307
+ this._mouseX = undefined;
2308
+ });
2291
2309
  // default values in pixels
2292
2310
  this._lineHeight = 40;
2293
2311
  this._labelWidth = 170;
@@ -2371,6 +2389,7 @@ class UIMetrics {
2371
2389
  const delta = range.max - range.min;
2372
2390
  let minCircle = '';
2373
2391
  let maxCircle = '';
2392
+ let mouseCircle = this._mouseX == null || this._mouseX > x ? null : '';
2374
2393
  for (let i = 0; i < values.length; ++i) {
2375
2394
  x -= this._stepSize;
2376
2395
  const value = parseFloat(values[i].toString());
@@ -2382,6 +2401,9 @@ class UIMetrics {
2382
2401
  else if (value === max) {
2383
2402
  minCircle = minCircle || this._drawCircle(x, y, value);
2384
2403
  }
2404
+ if (mouseCircle === '' && x <= (this._mouseX || 0)) {
2405
+ mouseCircle = this._drawCircle(x, y, value, 'blue', '');
2406
+ }
2385
2407
  }
2386
2408
  this._html += '" />'; // end path
2387
2409
  // Average
@@ -2396,7 +2418,10 @@ class UIMetrics {
2396
2418
  '</tspan>';
2397
2419
  this._html += '<tspan x="' + (width + averageCenter) + '" dy="1em">±' + average + '</tspan>';
2398
2420
  this._html += '</text>';
2399
- this._html += minCircle + maxCircle;
2421
+ this._html += minCircle + maxCircle + (mouseCircle !== null && mouseCircle !== void 0 ? mouseCircle : '');
2422
+ if (mouseCircle) {
2423
+ this._html += mouseCircle;
2424
+ }
2400
2425
  this._html += '</svg>';
2401
2426
  }
2402
2427
  requestAnimationFrame(() => {
@@ -2406,8 +2431,8 @@ class UIMetrics {
2406
2431
  }
2407
2432
  });
2408
2433
  }
2409
- _drawCircle(x, y, value) {
2410
- let circle = '<circle cx="' + x + '" cy="' + y + '" r="2" fill="green" />';
2434
+ _drawCircle(x, y, value, color = 'green', fontStyle = 'italic') {
2435
+ let circle = '<circle cx="' + x + '" cy="' + y + '" r="2" fill="' + color + '" />';
2411
2436
  const legendFontHeight = 0.7 * this._legendFontSize;
2412
2437
  const graphMiddle = Math.round(this._lineHeight / 2);
2413
2438
  if (y < graphMiddle) {
@@ -2419,7 +2444,9 @@ class UIMetrics {
2419
2444
  y -= this.textMargin;
2420
2445
  }
2421
2446
  circle +=
2422
- '<text font-style="italic" font-size="' +
2447
+ '<text font-style="' +
2448
+ fontStyle +
2449
+ '" font-size="' +
2423
2450
  this._legendFontSize +
2424
2451
  '" x="' +
2425
2452
  (x - this._legendFontSize) +
@@ -2435,4 +2462,4 @@ class UIMetrics {
2435
2462
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
2436
2463
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
2437
2464
  */
2438
- const VERSION = '5.0.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map
2465
+ const VERSION = '6.0.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map