@ceeblue/web-utils 2.4.0 → 2.5.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 +14 -5
- package/dist/web-utils.js +33 -18
- 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 +7 -6
package/dist/web-utils.d.ts
CHANGED
|
@@ -731,6 +731,12 @@ declare function getExtension(path: string): string;
|
|
|
731
731
|
* @returns the file name
|
|
732
732
|
*/
|
|
733
733
|
declare function getFile(path: string): string;
|
|
734
|
+
/**
|
|
735
|
+
* Get Base File part from path, without extension
|
|
736
|
+
* @param path path to parse
|
|
737
|
+
* @returns the base file name
|
|
738
|
+
*/
|
|
739
|
+
declare function getBaseFile(path: string): string;
|
|
734
740
|
/**
|
|
735
741
|
* String Trim function with customizable chars
|
|
736
742
|
* @param value string to trim
|
|
@@ -756,6 +762,7 @@ declare function trimEnd(value: string, chars?: string): string;
|
|
|
756
762
|
declare const Util_EMPTY_FUNCTION: typeof EMPTY_FUNCTION;
|
|
757
763
|
declare const Util_equal: typeof equal;
|
|
758
764
|
declare const Util_fetch: typeof fetch;
|
|
765
|
+
declare const Util_getBaseFile: typeof getBaseFile;
|
|
759
766
|
declare const Util_getExtension: typeof getExtension;
|
|
760
767
|
declare const Util_getFile: typeof getFile;
|
|
761
768
|
declare const Util_objectEntries: typeof objectEntries;
|
|
@@ -771,7 +778,7 @@ declare const Util_trim: typeof trim;
|
|
|
771
778
|
declare const Util_trimEnd: typeof trimEnd;
|
|
772
779
|
declare const Util_trimStart: typeof trimStart;
|
|
773
780
|
declare namespace Util {
|
|
774
|
-
export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_equal as equal, Util_fetch as fetch, Util_getExtension as getExtension, Util_getFile as getFile, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin, Util_trim as trim, Util_trimEnd as trimEnd, Util_trimStart as trimStart };
|
|
781
|
+
export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_equal as equal, Util_fetch as fetch, Util_getBaseFile as getBaseFile, Util_getExtension as getExtension, Util_getFile as getFile, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin, Util_trim as trim, Util_trimEnd as trimEnd, Util_trimStart as trimStart };
|
|
775
782
|
}
|
|
776
783
|
|
|
777
784
|
/**
|
|
@@ -833,19 +840,22 @@ type WebSocketReliableError =
|
|
|
833
840
|
*/
|
|
834
841
|
declare class WebSocketReliable extends EventEmitter {
|
|
835
842
|
/**
|
|
836
|
-
*
|
|
843
|
+
* Fired when socket is connected
|
|
844
|
+
* @event
|
|
837
845
|
*/
|
|
838
846
|
onOpen(): void;
|
|
839
847
|
/**
|
|
840
|
-
*
|
|
848
|
+
* Fired on message reception
|
|
841
849
|
* @param message can be binary or string.
|
|
842
850
|
* If you subscribe to the event with message as string type (and not union),
|
|
843
851
|
* it means that you know that all your messages are distributed in a string format
|
|
852
|
+
* @event
|
|
844
853
|
*/
|
|
845
854
|
onMessage(message: ArrayBuffer | string): void;
|
|
846
855
|
/**
|
|
847
|
-
*
|
|
856
|
+
* Fired on websocket close
|
|
848
857
|
* @param error error description on an improper closure
|
|
858
|
+
* @event
|
|
849
859
|
*/
|
|
850
860
|
onClose(error?: WebSocketReliableError): void;
|
|
851
861
|
/**
|
|
@@ -919,7 +929,6 @@ declare class WebSocketReliable extends EventEmitter {
|
|
|
919
929
|
/**
|
|
920
930
|
* Close websocket
|
|
921
931
|
* @param error the error reason if is not a proper close
|
|
922
|
-
* @param detail detail of the error
|
|
923
932
|
*/
|
|
924
933
|
close(error?: WebSocketReliableError): void;
|
|
925
934
|
private _send;
|
package/dist/web-utils.js
CHANGED
|
@@ -633,10 +633,11 @@ function fetch(input, init) {
|
|
|
633
633
|
return __awaiter(this, void 0, void 0, function* () {
|
|
634
634
|
const response = yield self.fetch(input, init);
|
|
635
635
|
if (response.status >= 300) {
|
|
636
|
+
let error;
|
|
636
637
|
if (response.body) {
|
|
637
|
-
|
|
638
|
+
error = yield response.text();
|
|
638
639
|
}
|
|
639
|
-
throw response.statusText;
|
|
640
|
+
throw (error || response.statusText || response.status).toString();
|
|
640
641
|
}
|
|
641
642
|
return response;
|
|
642
643
|
});
|
|
@@ -659,6 +660,16 @@ function getExtension(path) {
|
|
|
659
660
|
function getFile(path) {
|
|
660
661
|
return path.substring(path.lastIndexOf('/') + 1);
|
|
661
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Get Base File part from path, without extension
|
|
665
|
+
* @param path path to parse
|
|
666
|
+
* @returns the base file name
|
|
667
|
+
*/
|
|
668
|
+
function getBaseFile(path) {
|
|
669
|
+
const dot = path.lastIndexOf('.');
|
|
670
|
+
const file = path.lastIndexOf('/') + 1;
|
|
671
|
+
return dot >= 0 && dot >= file ? path.substring(file, dot) : path.substring(file);
|
|
672
|
+
}
|
|
662
673
|
function codesFromString(value) {
|
|
663
674
|
const codes = [];
|
|
664
675
|
for (let i = 0; i < value.length; ++i) {
|
|
@@ -711,7 +722,7 @@ function trimEnd(value, chars = ' ') {
|
|
|
711
722
|
--i;
|
|
712
723
|
}
|
|
713
724
|
return value.substring(0, i);
|
|
714
|
-
}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getExtension:getExtension,getFile:getFile,objectEntries:objectEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart});/**
|
|
725
|
+
}var Util=/*#__PURE__*/Object.freeze({__proto__:null,EMPTY_FUNCTION:EMPTY_FUNCTION,equal:equal,fetch:fetch,getBaseFile:getBaseFile,getExtension:getExtension,getFile:getFile,objectEntries:objectEntries,objectFrom:objectFrom,options:options,safePromise:safePromise,sleep:sleep,stringify:stringify,time:time,timeOrigin:timeOrigin,toBin:toBin,trim:trim,trimEnd:trimEnd,trimStart:trimStart});/**
|
|
715
726
|
* Copyright 2024 Ceeblue B.V.
|
|
716
727
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
717
728
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
@@ -900,10 +911,6 @@ var Type;
|
|
|
900
911
|
* @param params The parameters for which the media extension is to be defined
|
|
901
912
|
*/
|
|
902
913
|
function defineMediaExt(type, params) {
|
|
903
|
-
// Fix mediaExt in removing the possible '.' prefix
|
|
904
|
-
if (params.mediaExt) {
|
|
905
|
-
params.mediaExt = trimStart(params.mediaExt, '.');
|
|
906
|
-
}
|
|
907
914
|
// Compute appropriate mediaExt out parameter
|
|
908
915
|
switch (type) {
|
|
909
916
|
case Type.HESP:
|
|
@@ -917,7 +924,7 @@ function defineMediaExt(type, params) {
|
|
|
917
924
|
const url = new URL(params.endPoint);
|
|
918
925
|
const ext = getExtension(getFile(url.pathname));
|
|
919
926
|
// set extension just if not json, json means a manifest file endPoint
|
|
920
|
-
if (ext && ext !== 'json') {
|
|
927
|
+
if (ext && ext.toLowerCase() !== '.json') {
|
|
921
928
|
params.mediaExt = ext;
|
|
922
929
|
}
|
|
923
930
|
}
|
|
@@ -941,6 +948,8 @@ function defineMediaExt(type, params) {
|
|
|
941
948
|
console.warn('Unknown params type ' + type);
|
|
942
949
|
break;
|
|
943
950
|
}
|
|
951
|
+
// Fix mediaExt in removing the possible '.' prefix
|
|
952
|
+
trimStart(params.mediaExt, '.');
|
|
944
953
|
}
|
|
945
954
|
/**
|
|
946
955
|
* Build an URL from {@link Type | type} and {@link Params | params}
|
|
@@ -962,7 +971,7 @@ function buildURL(type, params, protocol = 'wss') {
|
|
|
962
971
|
url.pathname = '/webrtc/' + params.streamName;
|
|
963
972
|
break;
|
|
964
973
|
case Type.WRTS:
|
|
965
|
-
url.pathname = '/wrts/' + params.streamName;
|
|
974
|
+
url.pathname = '/wrts/' + params.streamName + '.' + params.mediaExt;
|
|
966
975
|
break;
|
|
967
976
|
case Type.META:
|
|
968
977
|
url.pathname = '/json_' + params.streamName + '.js';
|
|
@@ -1701,21 +1710,31 @@ Object.freeze(SDP);/**
|
|
|
1701
1710
|
*/
|
|
1702
1711
|
class WebSocketReliable extends EventEmitter {
|
|
1703
1712
|
/**
|
|
1704
|
-
*
|
|
1713
|
+
* Fired when socket is connected
|
|
1714
|
+
* @event
|
|
1705
1715
|
*/
|
|
1706
1716
|
onOpen() { }
|
|
1707
1717
|
/**
|
|
1708
|
-
*
|
|
1718
|
+
* Fired on message reception
|
|
1709
1719
|
* @param message can be binary or string.
|
|
1710
1720
|
* If you subscribe to the event with message as string type (and not union),
|
|
1711
1721
|
* it means that you know that all your messages are distributed in a string format
|
|
1722
|
+
* @event
|
|
1712
1723
|
*/
|
|
1713
1724
|
onMessage(message) { }
|
|
1714
1725
|
/**
|
|
1715
|
-
*
|
|
1726
|
+
* Fired on websocket close
|
|
1716
1727
|
* @param error error description on an improper closure
|
|
1728
|
+
* @event
|
|
1717
1729
|
*/
|
|
1718
|
-
onClose(error) {
|
|
1730
|
+
onClose(error) {
|
|
1731
|
+
if (error) {
|
|
1732
|
+
this.log('onClose', error).error();
|
|
1733
|
+
}
|
|
1734
|
+
else {
|
|
1735
|
+
this.log('onClose').info();
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1719
1738
|
/**
|
|
1720
1739
|
* binaryType, fix binary type to arrayBuffer
|
|
1721
1740
|
*/
|
|
@@ -1882,7 +1901,6 @@ class WebSocketReliable extends EventEmitter {
|
|
|
1882
1901
|
/**
|
|
1883
1902
|
* Close websocket
|
|
1884
1903
|
* @param error the error reason if is not a proper close
|
|
1885
|
-
* @param detail detail of the error
|
|
1886
1904
|
*/
|
|
1887
1905
|
close(error) {
|
|
1888
1906
|
if (!this._ws || this._closed) {
|
|
@@ -1894,9 +1912,6 @@ class WebSocketReliable extends EventEmitter {
|
|
|
1894
1912
|
// release resources!
|
|
1895
1913
|
this._queueing.length = 0;
|
|
1896
1914
|
this._queueingBytes = 0;
|
|
1897
|
-
if (error) {
|
|
1898
|
-
this.log(error).error();
|
|
1899
|
-
}
|
|
1900
1915
|
this.onClose(error);
|
|
1901
1916
|
// Reset _opened in last to allow to differenciate in onClose an error while connecting OR while connected
|
|
1902
1917
|
this._opened = false;
|
|
@@ -1913,4 +1928,4 @@ class WebSocketReliable extends EventEmitter {
|
|
|
1913
1928
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
1914
1929
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
1915
1930
|
*/
|
|
1916
|
-
const VERSION = '2.
|
|
1931
|
+
const VERSION = '2.5.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,Log,LogType,Loggable,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map
|