@ceeblue/web-utils 1.3.0 → 1.4.1
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/README.md +6 -9
- package/dist/web-utils.d.ts +44 -1
- package/dist/web-utils.js +223 -159
- package/dist/web-utils.js.map +1 -1
- package/dist/web-utils.min.js +1 -1
- package/dist/web-utils.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Ceeblue Web Utilities
|
|
4
4
|
|
|
5
|
-
This is a
|
|
5
|
+
This is a basic component library for Ceeblue projects, consisting of a collection of essential tools and utilities used in all Ceeblue web projects.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
@@ -16,8 +16,8 @@ import { Util, ILog } from '@ceeblue/web-utils';
|
|
|
16
16
|
```
|
|
17
17
|
> 💡 **TIP**
|
|
18
18
|
>
|
|
19
|
-
> If your project uses
|
|
20
|
-
> Then
|
|
19
|
+
> If your project uses TypeScript, it is recommended that you set target: "ES6" in your configuration to match our use of ES6 features and ensure that your build will succeed (for those requiring a backward-compatible UMD version, a local build is recommended).
|
|
20
|
+
> Then define the "moduleResolution" compiler option: "Node" in tsconfig.json helps with import failures by ensuring that TypeScript uses the correct import resolution strategy based on the targeted Node.js version.
|
|
21
21
|
> ```json
|
|
22
22
|
> {
|
|
23
23
|
> "compilerOptions": {
|
|
@@ -30,8 +30,8 @@ import { Util, ILog } from '@ceeblue/web-utils';
|
|
|
30
30
|
## Building locally
|
|
31
31
|
|
|
32
32
|
1. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository
|
|
33
|
-
2.
|
|
34
|
-
3.
|
|
33
|
+
2. Got to the `web-utils` folder and run `npm install` to install the packages dependencies.
|
|
34
|
+
3. Run `npm run build`. The output will be five files placed in the **/dist/** folder:
|
|
35
35
|
- **web-utils.d.ts** Typescript definitions file
|
|
36
36
|
- **web-utils.js**: Bundled JavaScript library
|
|
37
37
|
- **web-utils.js.map**: Source map that associates the bundled library with the original source files
|
|
@@ -51,10 +51,7 @@ This monorepo also contains built-in documentation about the APIs in the library
|
|
|
51
51
|
```
|
|
52
52
|
npm run build:docs
|
|
53
53
|
```
|
|
54
|
-
You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`)
|
|
55
|
-
```
|
|
56
|
-
http://localhost:8080/docs/
|
|
57
|
-
```
|
|
54
|
+
You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`).
|
|
58
55
|
|
|
59
56
|
## Contribution
|
|
60
57
|
|
package/dist/web-utils.d.ts
CHANGED
|
@@ -90,6 +90,23 @@ declare class BitReader {
|
|
|
90
90
|
read16(): number;
|
|
91
91
|
read24(): number;
|
|
92
92
|
read32(): number;
|
|
93
|
+
readExpGolomb(): number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Compute ByteRate every delta time
|
|
98
|
+
*/
|
|
99
|
+
declare class ByteRate {
|
|
100
|
+
onBytes(bytes: number): void;
|
|
101
|
+
get delta(): number;
|
|
102
|
+
private _bytes;
|
|
103
|
+
private _time;
|
|
104
|
+
private _delta;
|
|
105
|
+
private _value;
|
|
106
|
+
constructor(delta?: number);
|
|
107
|
+
value(): number;
|
|
108
|
+
exact(): number;
|
|
109
|
+
addBytes(bytes: number): this;
|
|
93
110
|
}
|
|
94
111
|
|
|
95
112
|
/**
|
|
@@ -223,6 +240,32 @@ declare class EventEmitter {
|
|
|
223
240
|
private _event;
|
|
224
241
|
}
|
|
225
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Copyright 2024 Ceeblue B.V.
|
|
245
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
246
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
247
|
+
*/
|
|
248
|
+
/**
|
|
249
|
+
* Some fix for JS MAP:
|
|
250
|
+
* - find(key) search an item in the map and returns undefined if not found
|
|
251
|
+
* - get(key) return the item if exists or otherwise create and returns it
|
|
252
|
+
* - set(key, value) returns the value of the item (rather the MAP)
|
|
253
|
+
*/
|
|
254
|
+
declare class FixMap<KeyType, ValueType> {
|
|
255
|
+
private _initValue;
|
|
256
|
+
[Symbol.iterator](): IterableIterator<[KeyType, ValueType]>;
|
|
257
|
+
get size(): number;
|
|
258
|
+
private _map;
|
|
259
|
+
constructor(_initValue: () => ValueType);
|
|
260
|
+
get(key: KeyType): ValueType;
|
|
261
|
+
find(key: KeyType): ValueType | undefined;
|
|
262
|
+
has(key: KeyType): boolean;
|
|
263
|
+
clear(): void;
|
|
264
|
+
delete(key: KeyType): boolean;
|
|
265
|
+
set(key: KeyType, value: ValueType): ValueType;
|
|
266
|
+
forEach(callbackfn: (value: ValueType, key: KeyType, map: Map<KeyType, ValueType>) => void, thisArg?: any): void;
|
|
267
|
+
}
|
|
268
|
+
|
|
226
269
|
/**
|
|
227
270
|
* Copyright 2024 Ceeblue B.V.
|
|
228
271
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
@@ -774,4 +817,4 @@ declare class WebSocketReliable extends EventEmitter {
|
|
|
774
817
|
|
|
775
818
|
declare const VERSION: string;
|
|
776
819
|
|
|
777
|
-
export { BinaryReader, BinaryWriter, BitReader, Connect, EventEmitter, type ILog, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable };
|
|
820
|
+
export { BinaryReader, BinaryWriter, BitReader, ByteRate, Connect, EventEmitter, FixMap, type ILog, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable };
|
package/dist/web-utils.js
CHANGED
|
@@ -341,129 +341,20 @@ class BitReader {
|
|
|
341
341
|
read32() {
|
|
342
342
|
return this.read(32);
|
|
343
343
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Help class to manipulate and parse a net address. The Address can be only the domain field,
|
|
351
|
-
* or a URL format with protocol and path part `(http://)domain(:port/path)`
|
|
352
|
-
* @example
|
|
353
|
-
* const address = new Address('nl-ams-42.live.ceeblue.tv:80');
|
|
354
|
-
* console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'
|
|
355
|
-
* console.log(address.port) // '80'
|
|
356
|
-
* console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'
|
|
357
|
-
*/
|
|
358
|
-
class NetAddress {
|
|
359
|
-
/**
|
|
360
|
-
* Static help function to build an end point from an address `(proto://)domain(:port/path)`
|
|
361
|
-
*
|
|
362
|
-
* Mainly it fix the protocol, in addition if:
|
|
363
|
-
* - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version
|
|
364
|
-
* - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version
|
|
365
|
-
* @param protocol protocol to set in the end point returned
|
|
366
|
-
* @param address string address to fix with protocol as indicated
|
|
367
|
-
* @returns the end point built
|
|
368
|
-
* @example
|
|
369
|
-
* console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'
|
|
370
|
-
* console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'
|
|
371
|
-
* console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'
|
|
372
|
-
*/
|
|
373
|
-
static fixProtocol(protocol, address) {
|
|
374
|
-
const found = address.indexOf('://');
|
|
375
|
-
// isolate protocol is present in address
|
|
376
|
-
if (found >= 0) {
|
|
377
|
-
// In this case replace by protocol in keeping SSL like given in address
|
|
378
|
-
if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') {
|
|
379
|
-
// SSL!
|
|
380
|
-
if (protocol.length <= 2 || !protocol.endsWith('s')) {
|
|
381
|
-
protocol += 's'; // Add SSL
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
// Not SSL!
|
|
386
|
-
if (protocol.length > 2 && protocol.endsWith('s')) {
|
|
387
|
-
protocol = protocol.slice(0, -1); // Remove SSL
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
// Build host!
|
|
391
|
-
address = address.substring(found + 3);
|
|
392
|
-
}
|
|
393
|
-
return protocol + '://' + address;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* The domain part from address `(http://)domain(:port/path)`
|
|
397
|
-
*/
|
|
398
|
-
get domain() {
|
|
399
|
-
return this._domain;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor
|
|
403
|
-
*/
|
|
404
|
-
get port() {
|
|
405
|
-
return this._port;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* @returns the string address as passed in the constructor
|
|
409
|
-
*/
|
|
410
|
-
toString() {
|
|
411
|
-
return this._address;
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* @returns the string address as passed in the constructor
|
|
415
|
-
* @override
|
|
416
|
-
*/
|
|
417
|
-
valueOf() {
|
|
418
|
-
return this._address;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Build a NetAddress object and parse address
|
|
422
|
-
* @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)`
|
|
423
|
-
* @param defaultPort set a default port to use if there is no port in the string address parsed
|
|
424
|
-
*/
|
|
425
|
-
constructor(address, defaultPort) {
|
|
426
|
-
this._address = address;
|
|
427
|
-
// Remove Protocol
|
|
428
|
-
let pos = address.indexOf('/');
|
|
429
|
-
if (pos >= 0) {
|
|
430
|
-
// Remove ://
|
|
431
|
-
if (address.charCodeAt(pos + 1) === 47) {
|
|
432
|
-
// has //
|
|
433
|
-
if (pos > 0) {
|
|
434
|
-
if (address.charCodeAt(pos - 1) === 58) {
|
|
435
|
-
// has ://
|
|
436
|
-
address = address.substring(pos + 2);
|
|
437
|
-
} // something else #//
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
// otherwise starts by //
|
|
441
|
-
address = address.substring(2);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else if (!pos) {
|
|
445
|
-
// starts by /, remove it
|
|
446
|
-
address = address.substring(1);
|
|
447
|
-
} // else something else #/
|
|
448
|
-
}
|
|
449
|
-
this._domain = address;
|
|
450
|
-
this._port = defaultPort;
|
|
451
|
-
// Parse Port
|
|
452
|
-
pos = address.lastIndexOf(':');
|
|
453
|
-
if (pos >= 0) {
|
|
454
|
-
const port = parseInt(address.substring(pos + 1));
|
|
455
|
-
if (port && port <= 0xffff) {
|
|
456
|
-
this._port = port;
|
|
457
|
-
this._domain = address.substring(0, pos);
|
|
344
|
+
readExpGolomb() {
|
|
345
|
+
let i = 0;
|
|
346
|
+
while (!this.read()) {
|
|
347
|
+
if (!this.available()) {
|
|
348
|
+
return 0;
|
|
458
349
|
}
|
|
350
|
+
++i;
|
|
459
351
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
this._domain = address.substring(0, pos);
|
|
465
|
-
}
|
|
352
|
+
const result = this.read(i);
|
|
353
|
+
if (i > 15) {
|
|
354
|
+
console.warn('Exponential-Golomb code exceeding unsigned 16 bits');
|
|
355
|
+
return 0;
|
|
466
356
|
}
|
|
357
|
+
return result + (1 << i) - 1;
|
|
467
358
|
}
|
|
468
359
|
}/******************************************************************************
|
|
469
360
|
Copyright (c) Microsoft Corporation.
|
|
@@ -736,6 +627,168 @@ function parseExtension(path) {
|
|
|
736
627
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
737
628
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
738
629
|
*/
|
|
630
|
+
/**
|
|
631
|
+
* Compute ByteRate every delta time
|
|
632
|
+
*/
|
|
633
|
+
class ByteRate {
|
|
634
|
+
onBytes(bytes) { }
|
|
635
|
+
get delta() {
|
|
636
|
+
return this._delta;
|
|
637
|
+
}
|
|
638
|
+
constructor(delta = 1000) {
|
|
639
|
+
this._time = time();
|
|
640
|
+
this._value = NaN;
|
|
641
|
+
this._delta = delta;
|
|
642
|
+
this._bytes = 0;
|
|
643
|
+
}
|
|
644
|
+
value() {
|
|
645
|
+
return Math.round(this.exact());
|
|
646
|
+
}
|
|
647
|
+
exact() {
|
|
648
|
+
const now = time();
|
|
649
|
+
const elapsed = now - this._time;
|
|
650
|
+
if (elapsed > this._delta || isNaN(this._value)) {
|
|
651
|
+
// wait "_delta" before next compute rate
|
|
652
|
+
this._value = (this._bytes * 1000) / elapsed;
|
|
653
|
+
this._bytes = 0;
|
|
654
|
+
this._time = now;
|
|
655
|
+
}
|
|
656
|
+
return this._value;
|
|
657
|
+
}
|
|
658
|
+
addBytes(bytes) {
|
|
659
|
+
this._bytes += bytes;
|
|
660
|
+
this.onBytes(bytes);
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
}/**
|
|
664
|
+
* Copyright 2024 Ceeblue B.V.
|
|
665
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
666
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
667
|
+
*/
|
|
668
|
+
/**
|
|
669
|
+
* Help class to manipulate and parse a net address. The Address can be only the domain field,
|
|
670
|
+
* or a URL format with protocol and path part `(http://)domain(:port/path)`
|
|
671
|
+
* @example
|
|
672
|
+
* const address = new Address('nl-ams-42.live.ceeblue.tv:80');
|
|
673
|
+
* console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'
|
|
674
|
+
* console.log(address.port) // '80'
|
|
675
|
+
* console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'
|
|
676
|
+
*/
|
|
677
|
+
class NetAddress {
|
|
678
|
+
/**
|
|
679
|
+
* Static help function to build an end point from an address `(proto://)domain(:port/path)`
|
|
680
|
+
*
|
|
681
|
+
* Mainly it fix the protocol, in addition if:
|
|
682
|
+
* - the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version
|
|
683
|
+
* - the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version
|
|
684
|
+
* @param protocol protocol to set in the end point returned
|
|
685
|
+
* @param address string address to fix with protocol as indicated
|
|
686
|
+
* @returns the end point built
|
|
687
|
+
* @example
|
|
688
|
+
* console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'
|
|
689
|
+
* console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'
|
|
690
|
+
* console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'
|
|
691
|
+
*/
|
|
692
|
+
static fixProtocol(protocol, address) {
|
|
693
|
+
const found = address.indexOf('://');
|
|
694
|
+
// isolate protocol is present in address
|
|
695
|
+
if (found >= 0) {
|
|
696
|
+
// In this case replace by protocol in keeping SSL like given in address
|
|
697
|
+
if (found > 2 && address.charAt(found - 1).toLowerCase() === 's') {
|
|
698
|
+
// SSL!
|
|
699
|
+
if (protocol.length <= 2 || !protocol.endsWith('s')) {
|
|
700
|
+
protocol += 's'; // Add SSL
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
// Not SSL!
|
|
705
|
+
if (protocol.length > 2 && protocol.endsWith('s')) {
|
|
706
|
+
protocol = protocol.slice(0, -1); // Remove SSL
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
// Build host!
|
|
710
|
+
address = address.substring(found + 3);
|
|
711
|
+
}
|
|
712
|
+
return protocol + '://' + address;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* The domain part from address `(http://)domain(:port/path)`
|
|
716
|
+
*/
|
|
717
|
+
get domain() {
|
|
718
|
+
return this._domain;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor
|
|
722
|
+
*/
|
|
723
|
+
get port() {
|
|
724
|
+
return this._port;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* @returns the string address as passed in the constructor
|
|
728
|
+
*/
|
|
729
|
+
toString() {
|
|
730
|
+
return this._address;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* @returns the string address as passed in the constructor
|
|
734
|
+
* @override
|
|
735
|
+
*/
|
|
736
|
+
valueOf() {
|
|
737
|
+
return this._address;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Build a NetAddress object and parse address
|
|
741
|
+
* @param address string address to parse, accept an url format with protocol and path `(http://)domain(:port/path)`
|
|
742
|
+
* @param defaultPort set a default port to use if there is no port in the string address parsed
|
|
743
|
+
*/
|
|
744
|
+
constructor(address, defaultPort) {
|
|
745
|
+
this._address = address;
|
|
746
|
+
// Remove Protocol
|
|
747
|
+
let pos = address.indexOf('/');
|
|
748
|
+
if (pos >= 0) {
|
|
749
|
+
// Remove ://
|
|
750
|
+
if (address.charCodeAt(pos + 1) === 47) {
|
|
751
|
+
// has //
|
|
752
|
+
if (pos > 0) {
|
|
753
|
+
if (address.charCodeAt(pos - 1) === 58) {
|
|
754
|
+
// has ://
|
|
755
|
+
address = address.substring(pos + 2);
|
|
756
|
+
} // something else #//
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
// otherwise starts by //
|
|
760
|
+
address = address.substring(2);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else if (!pos) {
|
|
764
|
+
// starts by /, remove it
|
|
765
|
+
address = address.substring(1);
|
|
766
|
+
} // else something else #/
|
|
767
|
+
}
|
|
768
|
+
this._domain = address;
|
|
769
|
+
this._port = defaultPort;
|
|
770
|
+
// Parse Port
|
|
771
|
+
pos = address.lastIndexOf(':');
|
|
772
|
+
if (pos >= 0) {
|
|
773
|
+
const port = parseInt(address.substring(pos + 1));
|
|
774
|
+
if (port && port <= 0xffff) {
|
|
775
|
+
this._port = port;
|
|
776
|
+
this._domain = address.substring(0, pos);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
// Remove Path!
|
|
781
|
+
pos = address.indexOf('/');
|
|
782
|
+
if (pos >= 0) {
|
|
783
|
+
this._domain = address.substring(0, pos);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}/**
|
|
788
|
+
* Copyright 2024 Ceeblue B.V.
|
|
789
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
790
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
791
|
+
*/
|
|
739
792
|
/**
|
|
740
793
|
* Type of connection
|
|
741
794
|
*/
|
|
@@ -936,6 +989,55 @@ class EventEmitter {
|
|
|
936
989
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
937
990
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
938
991
|
*/
|
|
992
|
+
/**
|
|
993
|
+
* Some fix for JS MAP:
|
|
994
|
+
* - find(key) search an item in the map and returns undefined if not found
|
|
995
|
+
* - get(key) return the item if exists or otherwise create and returns it
|
|
996
|
+
* - set(key, value) returns the value of the item (rather the MAP)
|
|
997
|
+
*/
|
|
998
|
+
class FixMap {
|
|
999
|
+
[Symbol.iterator]() {
|
|
1000
|
+
return this._map[Symbol.iterator]();
|
|
1001
|
+
}
|
|
1002
|
+
get size() {
|
|
1003
|
+
return this._map.size;
|
|
1004
|
+
}
|
|
1005
|
+
constructor(_initValue) {
|
|
1006
|
+
this._initValue = _initValue;
|
|
1007
|
+
this._map = new Map();
|
|
1008
|
+
}
|
|
1009
|
+
get(key) {
|
|
1010
|
+
let value = this.find(key);
|
|
1011
|
+
if (value === undefined) {
|
|
1012
|
+
this._map.set(key, (value = this._initValue()));
|
|
1013
|
+
}
|
|
1014
|
+
return value;
|
|
1015
|
+
}
|
|
1016
|
+
find(key) {
|
|
1017
|
+
return this._map.get(key);
|
|
1018
|
+
}
|
|
1019
|
+
has(key) {
|
|
1020
|
+
return this._map.has(key);
|
|
1021
|
+
}
|
|
1022
|
+
clear() {
|
|
1023
|
+
this._map.clear();
|
|
1024
|
+
}
|
|
1025
|
+
delete(key) {
|
|
1026
|
+
return this._map.delete(key);
|
|
1027
|
+
}
|
|
1028
|
+
set(key, value) {
|
|
1029
|
+
this._map.set(key, value);
|
|
1030
|
+
return value;
|
|
1031
|
+
}
|
|
1032
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1033
|
+
forEach(callbackfn, thisArg) {
|
|
1034
|
+
this._map.forEach(callbackfn, thisArg);
|
|
1035
|
+
}
|
|
1036
|
+
}/**
|
|
1037
|
+
* Copyright 2024 Ceeblue B.V.
|
|
1038
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
1039
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
1040
|
+
*/
|
|
939
1041
|
/**
|
|
940
1042
|
* Queue typed similar to a {@link https://en.cppreference.com/w/cpp/container/queue | std::queue<Type>} with possibility to limit the capacity like a FIFO
|
|
941
1043
|
* @example
|
|
@@ -1353,44 +1455,6 @@ Object.freeze(SDP);/**
|
|
|
1353
1455
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
1354
1456
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
1355
1457
|
*/
|
|
1356
|
-
/**
|
|
1357
|
-
* Compute ByteRate every delta time
|
|
1358
|
-
*/
|
|
1359
|
-
class ByteRate {
|
|
1360
|
-
onBytes(bytes) { }
|
|
1361
|
-
get delta() {
|
|
1362
|
-
return this._delta;
|
|
1363
|
-
}
|
|
1364
|
-
constructor(delta = 1000) {
|
|
1365
|
-
this._time = time();
|
|
1366
|
-
this._value = NaN;
|
|
1367
|
-
this._delta = delta;
|
|
1368
|
-
this._bytes = 0;
|
|
1369
|
-
}
|
|
1370
|
-
value() {
|
|
1371
|
-
return Math.round(this.exact());
|
|
1372
|
-
}
|
|
1373
|
-
exact() {
|
|
1374
|
-
const now = time();
|
|
1375
|
-
const elapsed = now - this._time;
|
|
1376
|
-
if (elapsed > this._delta || isNaN(this._value)) {
|
|
1377
|
-
// wait "_delta" before next compute rate
|
|
1378
|
-
this._value = (this._bytes * 1000) / elapsed;
|
|
1379
|
-
this._bytes = 0;
|
|
1380
|
-
this._time = now;
|
|
1381
|
-
}
|
|
1382
|
-
return this._value;
|
|
1383
|
-
}
|
|
1384
|
-
addBytes(bytes) {
|
|
1385
|
-
this._bytes += bytes;
|
|
1386
|
-
this.onBytes(bytes);
|
|
1387
|
-
return this;
|
|
1388
|
-
}
|
|
1389
|
-
}/**
|
|
1390
|
-
* Copyright 2024 Ceeblue B.V.
|
|
1391
|
-
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
1392
|
-
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
1393
|
-
*/
|
|
1394
1458
|
/**
|
|
1395
1459
|
* The WebSocketReliable class extends WebSocket to bring up the following improvements:
|
|
1396
1460
|
* - Fix all possible unintentional closing ways to get always a related error message, {@link onClose | onClose(error?) event}
|
|
@@ -1614,4 +1678,4 @@ class WebSocketReliable extends EventEmitter {
|
|
|
1614
1678
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
1615
1679
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
1616
1680
|
*/
|
|
1617
|
-
const VERSION = '1.
|
|
1681
|
+
const VERSION = '1.4.1';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable};//# sourceMappingURL=web-utils.js.map
|