@ceeblue/web-utils 1.1.0 → 1.3.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/README.md CHANGED
@@ -1,21 +1,65 @@
1
- # Ceeblue web framework
1
+ [Usage](#usage) | [Building locally](#building-locally) | [Documentation](#documentation) | [Contribution](#contribution) | [License](#license)
2
2
 
3
- This is a web framework for CeeblueTV's web libraries. It is a collection of tools and utilities that are used across all of CeeblueTV's web projects.
3
+ # Ceeblue Web Utilities
4
4
 
5
- ## Installation
5
+ This is a Web base compoments for CeeblueTV's web libraries : a collection of tools and utilities used across all of CeeblueTV's web projects.
6
6
 
7
- You can install the package using npm:
7
+ ## Usage
8
8
 
9
+ Add the library as a dependency to your npm project using:
9
10
  ```bash
10
11
  npm install @ceeblue/web-utils
11
12
  ```
13
+ Then [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) the library into your project, for example:
14
+ ```javascript
15
+ import { Util, ILog } from '@ceeblue/web-utils';
16
+ ```
17
+ > 💡 **TIP**
18
+ >
19
+ > If your project uses [TypeScript](https://www.typescriptlang.org/), it is recommended to set `"target": "ES6"` in your configuration to align with our usage of ES6 features and ensures that your build will succeed (for those requiring a backwards-compatible [UMD](https://github.com/umdjs/umd) version, a [local build](#building-locally) is advised).
20
+ > Then Defining the compiler option `"moduleResolution": "Node"` in **tsconfig.json** helps with import errors by ensuring that TypeScript uses the correct strategy for resolving imports based on the targeted Node.js version.
21
+ > ```json
22
+ > {
23
+ > "compilerOptions": {
24
+ > "target": "ES6",
25
+ > "moduleResolution": "Node"
26
+ > }
27
+ > }
28
+ > ```
29
+
30
+ ## Building locally
12
31
 
13
- Or manually add it to your `package.json` file:
32
+ 1. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository
33
+ 2. Enter the `webr-utils` folder and run `npm install` to install packages dependencies.
34
+ 3. Execute `npm run build`. The output will be five files placed in the **/dist/** folder:
35
+ - **web-utils.d.ts** Typescript definitions file
36
+ - **web-utils.js**: Bundled JavaScript library
37
+ - **web-utils.js.map**: Source map that associates the bundled library with the original source files
38
+ - **web-utils.min.js** Minified version of the library, optimized for size
39
+ - **web-utils.min.js.map** Source map that associates the minified library with the original source files
14
40
 
15
- ```json
16
- {
17
- "dependencies": {
18
- "@ceeblue/web-utils": "latest"
19
- }
20
- }
21
41
  ```
42
+ git clone https://github.com/CeeblueTV/web-utils.git
43
+ cd web-utils
44
+ npm install
45
+ npm run build
46
+ ```
47
+
48
+ ## Documentation
49
+
50
+ This monorepo also contains built-in documentation about the APIs in the library, which can be built using the following npm command:
51
+ ```
52
+ npm run build:docs
53
+ ```
54
+ You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`), or if you have installed and started the [http-server package](https://www.npmjs.com/package/http-server) by navigating to:
55
+ ```
56
+ http://localhost:8080/docs/
57
+ ```
58
+
59
+ ## Contribution
60
+
61
+ All contributions are welcome. Please see [our contribution guide](/CONTRIBUTING.md) for details.
62
+
63
+ ## License
64
+
65
+ By contributing code to this project, you agree to license your contribution under the [GNU Affero General Public License](/LICENSE).
@@ -1,11 +1,3 @@
1
- /**
2
- * Copyright 2024 Ceeblue B.V.
3
- * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
4
- * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
5
- */
6
- /**
7
- * BinaryReader allows to read binary data
8
- */
9
1
  declare class BinaryReader {
10
2
  private _data;
11
3
  private _size;
@@ -24,13 +16,14 @@ declare class BinaryReader {
24
16
  read16(): number;
25
17
  read24(): number;
26
18
  read32(): number;
19
+ read64(): number;
27
20
  readFloat(): number;
28
21
  readDouble(): number;
29
22
  read7Bit(bytes?: number): number;
30
23
  readString(): string;
31
24
  readHex(size: number): string;
32
25
  /**
33
- * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size))
26
+ * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size)) or Util.stringify
34
27
  * @param {UInt32} size
35
28
  */
36
29
  read(size?: number): Uint8Array;
@@ -56,14 +49,19 @@ declare class BinaryWriter {
56
49
  size(): number;
57
50
  next(count?: number): BinaryWriter;
58
51
  clear(size?: number): BinaryWriter;
59
- write(data: string | ArrayLike<number>): BinaryWriter;
52
+ /**
53
+ * Write binary data
54
+ * @param data
55
+ */
56
+ write(data: ArrayLike<number>): BinaryWriter;
60
57
  write8(value: number): BinaryWriter;
61
58
  write16(value: number): BinaryWriter;
62
59
  write24(value: number): BinaryWriter;
63
60
  write32(value: number): BinaryWriter;
61
+ write64(value: number): BinaryWriter;
64
62
  writeFloat(value: number): BinaryWriter;
65
63
  writeDouble(value: number): BinaryWriter;
66
- write7Bit(value: number, bytes?: number): BinaryWriter;
64
+ write7Bit(value: number): BinaryWriter;
67
65
  writeString(value: string): BinaryWriter;
68
66
  writeHex(value: string): BinaryWriter;
69
67
  reserve(size: number): BinaryWriter;
@@ -124,11 +122,11 @@ type Params = {
124
122
  * Type of connection
125
123
  */
126
124
  declare enum Type {
127
- HESP = "hesp",
128
- WEBRTS = "webrts",
129
- WEBRTC = "webrtc",
130
- META = "meta",
131
- DATA = "data"
125
+ HESP = "HESP",
126
+ WEBRTS = "WebRTS",
127
+ WEBRTC = "WebRTC",
128
+ META = "Meta",
129
+ DATA = "Data"
132
130
  }
133
131
  /**
134
132
  * Some connection utility functions
@@ -549,10 +547,6 @@ declare const SDP: {
549
547
  /**
550
548
  * Some basic utility functions
551
549
  */
552
- /**
553
- * Version of the library
554
- */
555
- declare const VERSION = "?";
556
550
  /**
557
551
  * An empty lambda function, pratical to disable default behavior of function or events which are not expected to be null
558
552
  * @example
@@ -597,27 +591,56 @@ declare function objectEntries(value: any): [string, any][];
597
591
  * @param obj Any objects, strings, exceptions, errors, or number
598
592
  * @param params.space `''`, allows to configure space in the string representation
599
593
  * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation
600
- * @param params.recursive `false`, allows to serialize recursively every object value, beware if a value refers to a already parsed value an infinite loop will occur.
594
+ * @param params.recursive `false`, allows to serialize recursively every object value, beware if a value refers to a already parsed value an infinite loop will occur
595
+ * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information
601
596
  * @returns the final string representation
602
597
  */
603
598
  declare function stringify(obj: any, params?: {
604
599
  space?: string;
605
600
  decimal?: number;
606
601
  recursive?: number;
602
+ noBin?: boolean;
607
603
  }): string;
604
+ /**
605
+ * Encode a string to a binary representation
606
+ * @param value string value to convert
607
+ * @returns binary conversion
608
+ */
608
609
  declare function toBin(value: string): Uint8Array;
610
+ /**
611
+ * Execute a promise in a safe way with a timeout if caller doesn't resolve it in the accurate time
612
+ */
613
+ declare function safePromise<T>(timeout: number, promise: Promise<T>): Promise<unknown>;
614
+ /**
615
+ * Wait in milliseconds, requires a call with await keyword!
616
+ */
617
+ declare function sleep(ms: number): Promise<unknown>;
618
+ /**
619
+ * fetch help method with few usefull fix:
620
+ * - throw an string exception if response code is not 200 with the text of the response or uses statusText
621
+ */
622
+ declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
623
+ /**
624
+ * Extension parser
625
+ * @param path path to parse
626
+ * @returns the extension
627
+ */
628
+ declare function parseExtension(path: string): string;
609
629
 
610
630
  declare const Util_EMPTY_FUNCTION: typeof EMPTY_FUNCTION;
611
- declare const Util_VERSION: typeof VERSION;
631
+ declare const Util_fetch: typeof fetch;
612
632
  declare const Util_objectEntries: typeof objectEntries;
613
633
  declare const Util_objectFrom: typeof objectFrom;
614
634
  declare const Util_options: typeof options;
635
+ declare const Util_parseExtension: typeof parseExtension;
636
+ declare const Util_safePromise: typeof safePromise;
637
+ declare const Util_sleep: typeof sleep;
615
638
  declare const Util_stringify: typeof stringify;
616
639
  declare const Util_time: typeof time;
617
640
  declare const Util_timeOrigin: typeof timeOrigin;
618
641
  declare const Util_toBin: typeof toBin;
619
642
  declare namespace Util {
620
- export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_VERSION as VERSION, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
643
+ export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_fetch as fetch, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_parseExtension as parseExtension, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
621
644
  }
622
645
 
623
646
  /**
@@ -671,6 +694,8 @@ declare class WebSocketReliable extends EventEmitter {
671
694
  * binaryType, fix binary type to arrayBuffer
672
695
  */
673
696
  get binaryType(): BinaryType;
697
+ get recvByteRate(): number;
698
+ get sendByteRate(): number;
674
699
  /**
675
700
  * url of connection
676
701
  */
@@ -709,6 +734,8 @@ declare class WebSocketReliable extends EventEmitter {
709
734
  private _queueing;
710
735
  private _queueingBytes;
711
736
  private _ws?;
737
+ private _recvByteRate;
738
+ private _sendByteRate;
712
739
  /**
713
740
  * Create a WebSocketReliable object, and open it if an url is passed in argument
714
741
  * @param url URL of the WebSocket endpoint or null to start the connection later
@@ -736,6 +763,15 @@ declare class WebSocketReliable extends EventEmitter {
736
763
  * @param error the error reason if is not a proper close
737
764
  */
738
765
  close(error?: string): void;
766
+ private _send;
739
767
  }
740
768
 
741
- export { BinaryReader, BinaryWriter, BitReader, Connect, EventEmitter, type ILog, NetAddress, Numbers, Queue, SDP, Util, WebSocketReliable };
769
+ /**
770
+ * Copyright 2024 Ceeblue B.V.
771
+ * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
772
+ * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
773
+ */
774
+
775
+ declare const VERSION: string;
776
+
777
+ export { BinaryReader, BinaryWriter, BitReader, Connect, EventEmitter, type ILog, NetAddress, Numbers, Queue, SDP, Util, VERSION, WebSocketReliable };