@ceeblue/web-utils 2.1.0 → 2.2.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.
@@ -140,7 +140,7 @@ type Params = {
140
140
  */
141
141
  declare enum Type {
142
142
  HESP = "HESP",
143
- WEBRTS = "WebRTS",
143
+ WRTS = "WebRTS",
144
144
  WEBRTC = "WebRTC",
145
145
  META = "Meta",
146
146
  DATA = "Data"
@@ -658,6 +658,10 @@ declare function safePromise<T>(timeout: number, promise: Promise<T>): Promise<u
658
658
  * Wait in milliseconds, requires a call with await keyword!
659
659
  */
660
660
  declare function sleep(ms: number): Promise<unknown>;
661
+ /**
662
+ * Test equality between two value whatever their type, array included
663
+ */
664
+ declare function equal(a: any, b: any): boolean;
661
665
  /**
662
666
  * fetch help method with few usefull fix:
663
667
  * - throw an string exception if response code is not 200 with the text of the response or uses statusText
@@ -671,6 +675,7 @@ declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Re
671
675
  declare function parseExtension(path: string): string;
672
676
 
673
677
  declare const Util_EMPTY_FUNCTION: typeof EMPTY_FUNCTION;
678
+ declare const Util_equal: typeof equal;
674
679
  declare const Util_fetch: typeof fetch;
675
680
  declare const Util_objectEntries: typeof objectEntries;
676
681
  declare const Util_objectFrom: typeof objectFrom;
@@ -683,7 +688,7 @@ declare const Util_time: typeof time;
683
688
  declare const Util_timeOrigin: typeof timeOrigin;
684
689
  declare const Util_toBin: typeof toBin;
685
690
  declare namespace Util {
686
- 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 };
691
+ export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_equal as equal, 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 };
687
692
  }
688
693
 
689
694
  /**
package/dist/web-utils.js CHANGED
@@ -597,6 +597,34 @@ function sleep(ms) {
597
597
  setTimeout(resolve, ms);
598
598
  });
599
599
  }
600
+ /**
601
+ * Test equality between two value whatever their type, array included
602
+ */
603
+ function equal(a, b) {
604
+ if (Object(a) !== a) {
605
+ if (Object(b) === b) {
606
+ return false;
607
+ }
608
+ // both primitive (null and undefined included)
609
+ return a === b;
610
+ }
611
+ // complexe object
612
+ if (a[Symbol.iterator]) {
613
+ if (!b[Symbol.iterator]) {
614
+ return false;
615
+ }
616
+ if (a.length !== b.length) {
617
+ return false;
618
+ }
619
+ for (let i = 0; i !== a.length; ++i) {
620
+ if (a[i] !== b[i]) {
621
+ return false;
622
+ }
623
+ }
624
+ return true;
625
+ }
626
+ return a === b;
627
+ }
600
628
  /**
601
629
  * fetch help method with few usefull fix:
602
630
  * - throw an string exception if response code is not 200 with the text of the response or uses statusText
@@ -622,7 +650,7 @@ function parseExtension(path) {
622
650
  const dot = path.lastIndexOf('.');
623
651
  const ext = dot >= 0 && dot > path.lastIndexOf('/') ? path.substring(dot) : '';
624
652
  return ext;
625
- }var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,fetch:fetch,objectEntries:objectEntries,objectFrom:objectFrom,options:options,parseExtension:parseExtension,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin});/**
653
+ }var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,objectEntries:objectEntries,objectFrom:objectFrom,options:options,parseExtension:parseExtension,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin});/**
626
654
  * Copyright 2024 Ceeblue B.V.
627
655
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
628
656
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
@@ -795,7 +823,7 @@ class NetAddress {
795
823
  var Type;
796
824
  (function (Type) {
797
825
  Type["HESP"] = "HESP";
798
- Type["WEBRTS"] = "WebRTS";
826
+ Type["WRTS"] = "WebRTS";
799
827
  Type["WEBRTC"] = "WebRTC";
800
828
  Type["META"] = "Meta";
801
829
  Type["DATA"] = "Data";
@@ -812,6 +840,9 @@ var Type;
812
840
  */
813
841
  function buildURL(type, params, protocol = 'wss') {
814
842
  const url = new URL(NetAddress.fixProtocol(protocol, params.endPoint));
843
+ // Remove possible extension of streamName put sometimes to decide format when multiple choices are possible like with WRTS
844
+ const ext = parseExtension(params.streamName);
845
+ params.streamName = params.streamName.substring(0, params.streamName.length - ext.length);
815
846
  if (url.pathname.length <= 1) {
816
847
  // build ceeblue path!
817
848
  switch (type) {
@@ -821,8 +852,8 @@ function buildURL(type, params, protocol = 'wss') {
821
852
  case Type.WEBRTC:
822
853
  url.pathname = '/webrtc/' + params.streamName;
823
854
  break;
824
- case Type.WEBRTS:
825
- url.pathname = '/webrts/' + params.streamName;
855
+ case Type.WRTS:
856
+ url.pathname = '/wrts/' + params.streamName + ext;
826
857
  break;
827
858
  case Type.META:
828
859
  url.pathname = '/json_' + params.streamName + '.js';
@@ -841,8 +872,6 @@ function buildURL(type, params, protocol = 'wss') {
841
872
  for (const key in params.query) {
842
873
  url.searchParams.set(key, params.query[key]);
843
874
  }
844
- // Remove possible extension of streamName
845
- params.streamName.substring(0, params.streamName.length - parseExtension(params.streamName).length);
846
875
  return url;
847
876
  }var Connect=/*#__PURE__*/Object.freeze({__proto__:null,get Type(){return Type},buildURL:buildURL});/**
848
877
  * Copyright 2024 Ceeblue B.V.
@@ -1682,4 +1711,4 @@ class WebSocketReliable extends EventEmitter {
1682
1711
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
1683
1712
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
1684
1713
  */
1685
- const VERSION = '2.1.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable};//# sourceMappingURL=web-utils.js.map
1714
+ const VERSION = '2.2.1';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable};//# sourceMappingURL=web-utils.js.map