@ceeblue/web-utils 7.5.1 → 7.7.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.
@@ -869,10 +869,12 @@ declare function iterableEntries(value: any): IterableIterator<[string, any]>;
869
869
  * Converts various data types, such as objects, strings, exceptions, errors,
870
870
  * or numbers, into a string representation. Since it offers a more comprehensive format,
871
871
  * this function is preferred to `JSON.stringify()`.
872
+ *
872
873
  * @param obj Any objects, strings, exceptions, errors, or number
873
874
  * @param params.space `''`, allows to configure space in the string representation
874
875
  * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation
875
- * @param params.recursion `1`, recursion depth to stringify recursively every object value until this depth, beware if a value refers to a already parsed value an infinite loop will occur
876
+ * @param params.recursion `2`, recursion depth to stringify recursively every object value until this depth,
877
+ * beware if a value refers to a already parsed value an infinite loop will occur
876
878
  * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information
877
879
  * @returns the final string representation
878
880
  */
@@ -1211,8 +1213,9 @@ declare class PlayerStats extends Loggable {
1211
1213
  skippedAudio?: number;
1212
1214
  playbackSpeed?: number;
1213
1215
  playbackRate?: number;
1214
- recvByteRate?: number;
1215
- sendByteRate?: number;
1216
+ audioByteRate?: number;
1217
+ videoByteRate?: number;
1218
+ dataByteRate?: number;
1216
1219
  videoTrackId?: number;
1217
1220
  videoTrackBandwidth?: number;
1218
1221
  audioTrackId?: number;
package/dist/web-utils.js CHANGED
@@ -295,17 +295,19 @@ function iterableEntries(value) {
295
295
  * Converts various data types, such as objects, strings, exceptions, errors,
296
296
  * or numbers, into a string representation. Since it offers a more comprehensive format,
297
297
  * this function is preferred to `JSON.stringify()`.
298
+ *
298
299
  * @param obj Any objects, strings, exceptions, errors, or number
299
300
  * @param params.space `''`, allows to configure space in the string representation
300
301
  * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation
301
- * @param params.recursion `1`, recursion depth to stringify recursively every object value until this depth, beware if a value refers to a already parsed value an infinite loop will occur
302
+ * @param params.recursion `2`, recursion depth to stringify recursively every object value until this depth,
303
+ * beware if a value refers to a already parsed value an infinite loop will occur
302
304
  * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information
303
305
  * @returns the final string representation
304
306
  */
305
307
  // Online Javascript Editor for free
306
308
  // Write, Edit and Run your Javascript code using JS Online Compiler
307
309
  function stringify(obj, params = {}) {
308
- params = Object.assign({ space: ' ', decimal: 2, recursion: 1, noBin: false }, params);
310
+ params = Object.assign({ space: ' ', decimal: 2, recursion: 2, noBin: false }, params);
309
311
  if (obj == null) {
310
312
  return String(obj);
311
313
  }
@@ -328,27 +330,58 @@ function stringify(obj, params = {}) {
328
330
  // boolean or string type or stop recursivity
329
331
  if (typeof obj === 'boolean' || obj.substring || !params.recursion) {
330
332
  // is already a string OR has to be stringified
331
- return String(obj);
333
+ return typeof obj === 'object' ? Object.prototype.toString.call(obj) : String(obj);
334
+ }
335
+ const space = params.space;
336
+ if (obj instanceof Set) {
337
+ let res = 'Set[';
338
+ let first = true;
339
+ for (const value of obj.values()) {
340
+ if (!first) {
341
+ res += ',' + space;
342
+ }
343
+ first = false;
344
+ res += stringify(value, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));
345
+ }
346
+ return res + ']';
347
+ }
348
+ if (obj instanceof Map) {
349
+ let res = 'Map{';
350
+ let first = true;
351
+ for (const [k, v] of obj.entries()) {
352
+ if (!first) {
353
+ res += ',' + space;
354
+ }
355
+ first = false;
356
+ res += stringify(k, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));
357
+ res += ':' + stringify(v, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));
358
+ }
359
+ return res + '}';
332
360
  }
333
- const space = params.space || '';
334
361
  if (Array.isArray(obj)) {
335
362
  // Array!
336
- let res = '';
363
+ let res = '[';
364
+ let first = true;
337
365
  for (const value of obj) {
338
- res += (res ? ',' : '[') + space;
366
+ if (!first) {
367
+ res += ',' + space;
368
+ }
369
+ first = false;
339
370
  res += stringify(value, Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));
340
371
  }
341
- return (res += space + ']');
372
+ return res + ']';
342
373
  }
343
374
  let res = '{';
375
+ let first = true;
344
376
  for (const name in obj) {
345
- if (res.length > 1) {
346
- res += ',';
377
+ if (!first) {
378
+ res += ',' + space;
347
379
  }
348
- res += space + name + ':';
349
- res += stringify(obj[name], Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 })) + space;
380
+ first = false;
381
+ res += name + ':';
382
+ res += stringify(obj[name], Object.assign(Object.assign({}, params), { recursion: params.recursion - 1 }));
350
383
  }
351
- return (res += '}');
384
+ return res + '}';
352
385
  }
353
386
  /**
354
387
  * Encode a string to a binary representation
@@ -13382,7 +13415,7 @@ class PlayerStats extends Loggable {
13382
13415
  * @returns A {@link CML.Cmcd} object representing the CMCD payload.
13383
13416
  */
13384
13417
  toCmcd(url, trackId, prevStats) {
13385
- var _a, _b, _c, _d, _e, _f, _g, _h;
13418
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
13386
13419
  const cmcd = {};
13387
13420
  // Determine playback rate to use, preferring 'playbackRate' if available, otherwise falling back to 'playbackSpeed'
13388
13421
  const playBack = (_a = this.playbackRate) !== null && _a !== void 0 ? _a : this.playbackSpeed;
@@ -13417,8 +13450,9 @@ class PlayerStats extends Loggable {
13417
13450
  if (this.bufferAmount != null) {
13418
13451
  cmcd.bl = this.bufferAmount; // Buffer Length
13419
13452
  }
13420
- if (this.recvByteRate != null) {
13421
- cmcd.mtp = this.recvByteRate; // Measured mtp CMCD throughput
13453
+ if (this.audioByteRate != null || this.videoByteRate != null || this.dataByteRate != null) {
13454
+ // Measured mtp CMCD throughput
13455
+ cmcd.mtp = ((_g = this.audioByteRate) !== null && _g !== void 0 ? _g : 0) + ((_h = this.videoByteRate) !== null && _h !== void 0 ? _h : 0) + ((_j = this.dataByteRate) !== null && _j !== void 0 ? _j : 0);
13422
13456
  }
13423
13457
  if (playBack != null) {
13424
13458
  cmcd.pr = Number(playBack.toFixed(2)); // Playback Rate
@@ -13429,9 +13463,9 @@ class PlayerStats extends Loggable {
13429
13463
  hls: 'h',
13430
13464
  smooth: 's'
13431
13465
  };
13432
- const proto = (_g = this.protocol) === null || _g === void 0 ? void 0 : _g.toLowerCase();
13466
+ const proto = (_k = this.protocol) === null || _k === void 0 ? void 0 : _k.toLowerCase();
13433
13467
  if (proto != null) {
13434
- cmcd.sf = ((_h = sfByProtocol[proto]) !== null && _h !== void 0 ? _h : 'o'); // Streaming Format
13468
+ cmcd.sf = ((_l = sfByProtocol[proto]) !== null && _l !== void 0 ? _l : 'o'); // Streaming Format
13435
13469
  }
13436
13470
  if (this.waitingData != null) {
13437
13471
  cmcd.su = this.waitingData; // Startup
@@ -13697,4 +13731,4 @@ class UIMetrics {
13697
13731
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
13698
13732
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
13699
13733
  */
13700
- const VERSION = '7.5.1';export{BinaryReader,BinaryWriter,BitReader,ByteRate,index as CML,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,PlayerStats,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map
13734
+ const VERSION = '7.7.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,index as CML,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,PlayerStats,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map