@ceeblue/web-utils 2.4.1 → 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.
@@ -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
  /**
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
- throw (yield response.text()) || response.statusText;
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';
@@ -1919,4 +1928,4 @@ class WebSocketReliable extends EventEmitter {
1919
1928
  * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
1920
1929
  * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
1921
1930
  */
1922
- const VERSION = '2.4.1';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EventEmitter,FixMap,Log,LogType,Loggable,NetAddress,Numbers,Queue,SDP,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map
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