@ceeblue/web-utils 4.0.0 → 4.1.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.
@@ -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
@@ -796,12 +799,14 @@ declare function objectFrom(value: any, params: {
796
799
  noEmptyString: boolean;
797
800
  }): any;
798
801
  /**
799
- * Returns entries from something iterable, such as a Map, Set, or Array
800
- * If value is null it returns an empty array
801
- * @param value iterable input
802
- * @returns An javascript object
802
+ * Returns entries from an iterable input like Map, Set, or Array.
803
+ *
804
+ * For all other types of values (including `null` or `undefined`), it returns an empty array.
805
+ *
806
+ * @param value An iterable input
807
+ * @returns An array of key-value pairs
803
808
  */
804
- declare function objectEntries(value: any | null): [string, any][];
809
+ declare function objectEntries(value: any): [string, any][];
805
810
  /**
806
811
  * Converts various data types, such as objects, strings, exceptions, errors,
807
812
  * 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 something iterable, such as a Map, Set, or Array
261
- * If value is null it returns an empty array
262
- * @param value iterable input
263
- * @returns An javascript object
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
- return value.entries();
271
- }
272
- return Array.from({
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,
@@ -1192,6 +1195,7 @@ function defineMediaExt(type, params) {
1192
1195
  }
1193
1196
  /**
1194
1197
  * Build an URL from {@link Type | type} and {@link Params | params}
1198
+ * Can assign {@link Params.mediaExt | params.mediaExt} or {@link Params.streamName | params.streamName}
1195
1199
  * @param type Type of the connection wanted
1196
1200
  * @param params Connection parameters
1197
1201
  * @param protocol Optional parameter to choose the prefered protocol to connect
@@ -1222,7 +1226,15 @@ function buildURL(type, params, protocol = 'wss') {
1222
1226
  console.warn('Unknown url type ' + type);
1223
1227
  break;
1224
1228
  }
1225
- } // Host has already a path! keep it unchanged, it's user intentionnal (used with some other WHIP/WHEP server?)
1229
+ }
1230
+ else {
1231
+ // Host has already a path! keep it unchanged, it's user intentionnal (used with some other WHIP/WHEP server?)
1232
+ if (!params.streamName) {
1233
+ // 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
1234
+ const parts = url.pathname.split('/');
1235
+ params.streamName = parts[2] || parts[1] || parts[0];
1236
+ }
1237
+ }
1226
1238
  if (params.accessToken) {
1227
1239
  url.searchParams.set('id', params.accessToken);
1228
1240
  }
@@ -2419,4 +2431,4 @@ class UIMetrics {
2419
2431
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
2420
2432
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
2421
2433
  */
2422
- const VERSION = '4.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
2434
+ const VERSION = '4.1.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