@ceeblue/web-utils 4.0.0 → 4.2.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/dist/web-utils.d.ts +17 -10
- package/dist/web-utils.js +43 -28
- 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/dist/web-utils.d.ts
CHANGED
|
@@ -283,7 +283,9 @@ type Params = {
|
|
|
283
283
|
*/
|
|
284
284
|
endPoint: string;
|
|
285
285
|
/**
|
|
286
|
-
* The name of the stream to join
|
|
286
|
+
* The name of the stream to join.
|
|
287
|
+
* If `endPoint` is a complete URL and `streamName` is not provided, {@link buildURL} will set this parameter automatically
|
|
288
|
+
* using the second part of the URL's path (the first part being the protocol name), or the first path if no other part exists.
|
|
287
289
|
*/
|
|
288
290
|
streamName: string;
|
|
289
291
|
/**
|
|
@@ -296,7 +298,7 @@ type Params = {
|
|
|
296
298
|
iceServer?: RTCIceServer;
|
|
297
299
|
/**
|
|
298
300
|
* Optional media extension (mp4, flv, ts, rts), usefull for protocol like WebRTS which supports different container type.
|
|
299
|
-
* When not set, it's also an output parameter to indicate what is the media type selected
|
|
301
|
+
* When not set, it's also an output parameter for {@link defineMediaExt} to indicate what is the media type selected
|
|
300
302
|
*/
|
|
301
303
|
mediaExt?: string;
|
|
302
304
|
/**
|
|
@@ -327,6 +329,7 @@ declare enum Type {
|
|
|
327
329
|
declare function defineMediaExt(type: Type, params: Params): void;
|
|
328
330
|
/**
|
|
329
331
|
* Build an URL from {@link Type | type} and {@link Params | params}
|
|
332
|
+
* Can assign {@link Params.mediaExt | params.mediaExt} or {@link Params.streamName | params.streamName}
|
|
330
333
|
* @param type Type of the connection wanted
|
|
331
334
|
* @param params Connection parameters
|
|
332
335
|
* @param protocol Optional parameter to choose the prefered protocol to connect
|
|
@@ -493,6 +496,10 @@ declare class NetAddress {
|
|
|
493
496
|
* console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'
|
|
494
497
|
*/
|
|
495
498
|
static fixProtocol(protocol: string, address: string): string;
|
|
499
|
+
/**
|
|
500
|
+
* The host part from address `(http://)domain:port/path)`
|
|
501
|
+
*/
|
|
502
|
+
get host(): string;
|
|
496
503
|
/**
|
|
497
504
|
* The domain part from address `(http://)domain(:port/path)`
|
|
498
505
|
*/
|
|
@@ -501,9 +508,6 @@ declare class NetAddress {
|
|
|
501
508
|
* The port part from address `(http://)domain(:port/path)`, or defaultPort if passed in NetAddress constructor
|
|
502
509
|
*/
|
|
503
510
|
get port(): number | undefined;
|
|
504
|
-
/**
|
|
505
|
-
* @returns the string address as passed in the constructor
|
|
506
|
-
*/
|
|
507
511
|
toString(): string;
|
|
508
512
|
/**
|
|
509
513
|
* @returns the string address as passed in the constructor
|
|
@@ -512,6 +516,7 @@ declare class NetAddress {
|
|
|
512
516
|
valueOf(): string;
|
|
513
517
|
private _address;
|
|
514
518
|
private _domain;
|
|
519
|
+
private _host;
|
|
515
520
|
private _port?;
|
|
516
521
|
/**
|
|
517
522
|
* Build a NetAddress object and parse address
|
|
@@ -796,12 +801,14 @@ declare function objectFrom(value: any, params: {
|
|
|
796
801
|
noEmptyString: boolean;
|
|
797
802
|
}): any;
|
|
798
803
|
/**
|
|
799
|
-
* Returns entries from
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
804
|
+
* Returns entries from an iterable input like Map, Set, or Array.
|
|
805
|
+
*
|
|
806
|
+
* For all other types of values (including `null` or `undefined`), it returns an empty array.
|
|
807
|
+
*
|
|
808
|
+
* @param value An iterable input
|
|
809
|
+
* @returns An array of key-value pairs
|
|
803
810
|
*/
|
|
804
|
-
declare function objectEntries(value: any
|
|
811
|
+
declare function objectEntries(value: any): [string, any][];
|
|
805
812
|
/**
|
|
806
813
|
* Converts various data types, such as objects, strings, exceptions, errors,
|
|
807
814
|
* or numbers, into a string representation. Since it offers a more comprehensive format,
|
package/dist/web-utils.js
CHANGED
|
@@ -257,25 +257,28 @@ function objectFrom(value, params) {
|
|
|
257
257
|
return obj;
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
|
-
* Returns entries from
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
260
|
+
* Returns entries from an iterable input like Map, Set, or Array.
|
|
261
|
+
*
|
|
262
|
+
* For all other types of values (including `null` or `undefined`), it returns an empty array.
|
|
263
|
+
*
|
|
264
|
+
* @param value An iterable input
|
|
265
|
+
* @returns An array of key-value pairs
|
|
264
266
|
*/
|
|
265
267
|
function objectEntries(value) {
|
|
266
268
|
if (!value) {
|
|
267
269
|
return [];
|
|
268
270
|
}
|
|
269
|
-
if (value.entries) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
[Symbol.iterator]: function* () {
|
|
274
|
-
for (const key in value) {
|
|
275
|
-
yield [key, value[key]];
|
|
276
|
-
}
|
|
271
|
+
if (value.entries && typeof value.entries === 'function') {
|
|
272
|
+
value = value.entries();
|
|
273
|
+
if (Array.isArray(value)) {
|
|
274
|
+
return value;
|
|
277
275
|
}
|
|
278
|
-
}
|
|
276
|
+
}
|
|
277
|
+
const entries = [];
|
|
278
|
+
for (const key of Object.keys(value)) {
|
|
279
|
+
entries.push([key, value[key]]);
|
|
280
|
+
}
|
|
281
|
+
return entries;
|
|
279
282
|
}
|
|
280
283
|
/**
|
|
281
284
|
* Converts various data types, such as objects, strings, exceptions, errors,
|
|
@@ -1050,6 +1053,12 @@ class NetAddress {
|
|
|
1050
1053
|
}
|
|
1051
1054
|
return protocol + '://' + address;
|
|
1052
1055
|
}
|
|
1056
|
+
/**
|
|
1057
|
+
* The host part from address `(http://)domain:port/path)`
|
|
1058
|
+
*/
|
|
1059
|
+
get host() {
|
|
1060
|
+
return this._host;
|
|
1061
|
+
}
|
|
1053
1062
|
/**
|
|
1054
1063
|
* The domain part from address `(http://)domain(:port/path)`
|
|
1055
1064
|
*/
|
|
@@ -1062,9 +1071,6 @@ class NetAddress {
|
|
|
1062
1071
|
get port() {
|
|
1063
1072
|
return this._port;
|
|
1064
1073
|
}
|
|
1065
|
-
/**
|
|
1066
|
-
* @returns the string address as passed in the constructor
|
|
1067
|
-
*/
|
|
1068
1074
|
toString() {
|
|
1069
1075
|
return this._address;
|
|
1070
1076
|
}
|
|
@@ -1104,24 +1110,24 @@ class NetAddress {
|
|
|
1104
1110
|
address = address.substring(1);
|
|
1105
1111
|
} // else something else #/
|
|
1106
1112
|
}
|
|
1113
|
+
// Remove Path!
|
|
1114
|
+
pos = address.indexOf('/');
|
|
1115
|
+
if (pos >= 0) {
|
|
1116
|
+
address = address.substring(0, pos);
|
|
1117
|
+
}
|
|
1118
|
+
this._host = address;
|
|
1107
1119
|
this._domain = address;
|
|
1108
1120
|
this._port = defaultPort;
|
|
1109
1121
|
// Parse Port
|
|
1110
|
-
pos =
|
|
1111
|
-
|
|
1122
|
+
pos = this._host.lastIndexOf(':');
|
|
1123
|
+
const endOfBrace = this._host.lastIndexOf(']'); // to support IPv6
|
|
1124
|
+
if (pos > endOfBrace) {
|
|
1112
1125
|
const port = parseInt(address.substring(pos + 1));
|
|
1113
|
-
if (port && port <= 0xffff) {
|
|
1126
|
+
if (port >= 0 && port <= 0xffff) {
|
|
1114
1127
|
this._port = port;
|
|
1115
1128
|
this._domain = address.substring(0, pos);
|
|
1116
1129
|
}
|
|
1117
1130
|
}
|
|
1118
|
-
else {
|
|
1119
|
-
// Remove Path!
|
|
1120
|
-
pos = address.indexOf('/');
|
|
1121
|
-
if (pos >= 0) {
|
|
1122
|
-
this._domain = address.substring(0, pos);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
1131
|
}
|
|
1126
1132
|
}/**
|
|
1127
1133
|
* Copyright 2024 Ceeblue B.V.
|
|
@@ -1192,6 +1198,7 @@ function defineMediaExt(type, params) {
|
|
|
1192
1198
|
}
|
|
1193
1199
|
/**
|
|
1194
1200
|
* Build an URL from {@link Type | type} and {@link Params | params}
|
|
1201
|
+
* Can assign {@link Params.mediaExt | params.mediaExt} or {@link Params.streamName | params.streamName}
|
|
1195
1202
|
* @param type Type of the connection wanted
|
|
1196
1203
|
* @param params Connection parameters
|
|
1197
1204
|
* @param protocol Optional parameter to choose the prefered protocol to connect
|
|
@@ -1222,7 +1229,15 @@ function buildURL(type, params, protocol = 'wss') {
|
|
|
1222
1229
|
console.warn('Unknown url type ' + type);
|
|
1223
1230
|
break;
|
|
1224
1231
|
}
|
|
1225
|
-
}
|
|
1232
|
+
}
|
|
1233
|
+
else {
|
|
1234
|
+
// Host has already a path! keep it unchanged, it's user intentionnal (used with some other WHIP/WHEP server?)
|
|
1235
|
+
if (!params.streamName) {
|
|
1236
|
+
// extract the second part of the URL's path (the first part being the protocol name), or the first path if no other part exists
|
|
1237
|
+
const parts = url.pathname.split('/');
|
|
1238
|
+
params.streamName = getBaseFile(parts[2] || parts[1] || parts[0]);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1226
1241
|
if (params.accessToken) {
|
|
1227
1242
|
url.searchParams.set('id', params.accessToken);
|
|
1228
1243
|
}
|
|
@@ -2419,4 +2434,4 @@ class UIMetrics {
|
|
|
2419
2434
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
2420
2435
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
2421
2436
|
*/
|
|
2422
|
-
const VERSION = '4.
|
|
2437
|
+
const VERSION = '4.2.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
|