aotrautils 0.0.1889 → 0.0.1892

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5470,7 +5470,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5470
5470
 
5471
5471
 
5472
5472
 
5473
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
5473
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
5474
5474
  /*-----------------------------------------------------------------------------*/
5475
5475
  /* ## Utility global methods in a browser (htmljs) client environment.
5476
5476
  *
@@ -6483,7 +6483,7 @@ function removeServerPartOfURL(urlWithServerPart){
6483
6483
  /*DEPRECATED, use new URL("...") instead !*/
6484
6484
  /*UNUSED*/
6485
6485
  function getHostnameOfURL(url){
6486
- const result=url;
6486
+ let result=url;
6487
6487
  if (containsIgnoreCase(result, "(ht|f)tp[s]*://", true))
6488
6488
  result=result.replace(/(ht|f)tp[s]*:\/\//gim, "");
6489
6489
 
@@ -11832,7 +11832,8 @@ createFusrodaClient=function(doOnClientReady, doOnDataReception, urlParam=null,
11832
11832
  // CAUTION : WORKS BETTER WHEN UNSECURE, BUT 'NEEDS CLIENT BROWSER TO ALLOW MIXED (SECURE/UNSECURE) CONTENT !
11833
11833
 
11834
11834
  const fusrodaClient=initClient(false,
11835
- /*CAUTION : Fusroda Java server requires the Socket IO websocket implementation !!*/true,
11835
+ // TODO : FIXME : REFACTOR THE FUSRODA SERVER TO USE THE WEBSOCKET IMPLEMENTATION !!!
11836
+ // /*CAUTION : Fusroda Java server requires the Socket IO websocket implementation !!*/true
11836
11837
  /*doOnServerConnection:*/(socketToServerClientInstance)=>{
11837
11838
 
11838
11839
  // DBG
@@ -12065,7 +12066,9 @@ window.createOritaMainClient=function(
12065
12066
 
12066
12067
 
12067
12068
 
12068
- const oritaClient=initClient(false, false, /*doOnServerConnection*/(socketToServerClientInstance)=>{
12069
+ const oritaClient=initClient(false,
12070
+ // false,
12071
+ /*doOnServerConnection*/(socketToServerClientInstance)=>{
12069
12072
 
12070
12073
  // DBG
12071
12074
  lognow("ORITA MAIN CLIENT : SETTING UP");
@@ -13288,7 +13291,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13288
13291
 
13289
13292
 
13290
13293
 
13291
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
13294
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
13292
13295
  /*-----------------------------------------------------------------------------*/
13293
13296
 
13294
13297
 
@@ -14373,10 +14376,10 @@ function rayVsUnitSphereClosestPoint(p, r) {
14373
14376
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14374
14377
 
14375
14378
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14376
- /*utils 3D library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
14379
+ /*utils 3D library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
14377
14380
  /*-----------------------------------------------------------------------------*/
14378
14381
 
14379
- /*utils AI library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
14382
+ /*utils AI library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
14380
14383
  /*-----------------------------------------------------------------------------*/
14381
14384
 
14382
14385
 
@@ -14636,7 +14639,7 @@ getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProviderName=DE
14636
14639
 
14637
14640
 
14638
14641
 
14639
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (19/06/2026-22:43:56)»*/
14642
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (25/07/2026-22:02:22)»*/
14640
14643
  /*-----------------------------------------------------------------------------*/
14641
14644
 
14642
14645
 
@@ -14679,7 +14682,7 @@ if(typeof(window)==="undefined") window=global;
14679
14682
 
14680
14683
  class AORTACClientCell{
14681
14684
 
14682
- constructor(serverCellOrigin, model, view, isNodeContext=false){
14685
+ constructor(serverCellOrigin, model, view, isNodeContext=true){
14683
14686
 
14684
14687
  this.clientId=getUUID();
14685
14688
 
@@ -14722,7 +14725,9 @@ class AORTACClientCell{
14722
14725
 
14723
14726
 
14724
14727
  // 1) Initial connection
14725
- self.initialClientInstance=initClient(self.isNodeContext, false, (socketToServerClientInstance, initialClientInstanceLocal)=>{
14728
+ self.initialClientInstance=initClient(self.isNodeContext
14729
+ // ,false
14730
+ ,(socketToServerClientInstance, initialClientInstanceLocal)=>{
14726
14731
 
14727
14732
  // DBG
14728
14733
  lognow("DEBUG : Starting client...");
@@ -14816,7 +14821,9 @@ class AORTACClientCell{
14816
14821
  const host=nonull(infos.host,"localhost");
14817
14822
  const port=nonull(infos.port,"30000");
14818
14823
 
14819
- const reconnectedClientInstance=initClient(self.isNodeContext, false, (socketToServerClientInstance, reconnectedClientInstanceLocal)=>{
14824
+ const reconnectedClientInstance=initClient(self.isNodeContext
14825
+ // ,false
14826
+ ,(socketToServerClientInstance, reconnectedClientInstanceLocal)=>{
14820
14827
 
14821
14828
  // DBG
14822
14829
  lognow("DEBUG : Starting reconnected client...");
@@ -14998,7 +15005,7 @@ class ClientLobule{
14998
15005
 
14999
15006
 
15000
15007
 
15001
- window.getAORTACClient=function(serverCellOrigin="ws://127.0.0.1:40000", model, view, isNodeContext=false){
15008
+ window.getAORTACClient=function(serverCellOrigin="ws://127.0.0.1:40000", model, view, isNodeContext=true){
15002
15009
  if(nothing(serverCellOrigin)){
15003
15010
  // TRACE
15004
15011
  lognow("ERROR : No known server node, cannot connect to servers cells blob. Aborting AORTAC client setup.");
@@ -15213,7 +15220,9 @@ class AORTACServerCell{
15213
15220
  const outcomingCellHost=nonull(infos.host,"localhost");
15214
15221
  const outcomingCellPort=nonull(infos.port,"40000");
15215
15222
 
15216
- const clientInstance=initClient(true, false, (socketToServerClientInstance)=>{
15223
+ const clientInstance=initClient(true
15224
+ // ,false
15225
+ ,(socketToServerClientInstance)=>{
15217
15226
 
15218
15227
 
15219
15228
  const channelsNames=[];
@@ -16751,9 +16760,11 @@ window.fileExists=(filePath)=>{
16751
16760
  //- WEBSOCKETS AND NODEJS :
16752
16761
 
16753
16762
  function isConnected(clientSocket){
16754
- if(!WebsocketImplementation.useSocketIOImplementation)
16755
- return (clientSocket.readyState===WebSocket.OPEN)
16756
- return (clientSocket.connected);
16763
+ // if(!WebsocketImplementation.useSocketIOImplementation)
16764
+ if(!WebsocketImplementation.implementationToUse)
16765
+ return (clientSocket.readyState===WebSocket.OPEN)
16766
+ return WebsocketImplementation.implementationToUse.isConnected(clientSocket);
16767
+ // return (clientSocket.connected);
16757
16768
  }
16758
16769
 
16759
16770
  // Client-side or Server-side :
@@ -16890,7 +16901,8 @@ WebsocketImplementation={
16890
16901
 
16891
16902
 
16892
16903
  isNodeContext:true,
16893
- useSocketIOImplementation:false,
16904
+ // useSocketIOImplementation:false,
16905
+ implementationToUse:null,// null is default (WebSocket)
16894
16906
  useFlatStrings:false,
16895
16907
 
16896
16908
  // COMMON METHODS
@@ -16902,12 +16914,16 @@ WebsocketImplementation={
16902
16914
  //
16903
16915
  // CONSOLE NODE SERVER/CLIENT
16904
16916
  //
16905
- getStatic:(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false)=>{
16917
+ getStatic:(isNodeContext=true
16918
+ // , useSocketIOImplementation=/*DEBUG*/false
16919
+ )=>{
16906
16920
 
16907
16921
  WebsocketImplementation.isNodeContext=isNodeContext;
16908
- WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
16922
+ // WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
16923
+
16924
+ // if(!WebsocketImplementation.useSocketIOImplementation){
16925
+ if(!WebsocketImplementation.implementationToUse){
16909
16926
 
16910
- if(!WebsocketImplementation.useSocketIOImplementation){
16911
16927
  // TRACE
16912
16928
  lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
16913
16929
 
@@ -16927,40 +16943,40 @@ WebsocketImplementation={
16927
16943
  }
16928
16944
 
16929
16945
  }else{
16930
- // TRACE
16931
- lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
16932
-
16933
- if(isNodeContext){
16934
-
16935
- // NODE SERVER :
16936
- // DBG
16937
- lognow("INFO : Loading NODE SERVER socket.io libraries.")
16938
- if(typeof(Socket)==="undefined"){
16939
- // TRACE
16940
- console.log("«socket.io» NODE SERVER library not called yet, calling it now.");
16941
- Socket=require("socket.io");
16942
- }
16943
- if(typeof(Socket)==="undefined"){
16944
- // TRACE
16945
- console.log("ERROR : «socket.io» NODE CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
16946
- }
16947
-
16948
- // NODE CLIENT :
16949
- // DBG
16950
- lognow("INFO : Loading NODE CLIENT socket.io libraries.")
16951
- if(typeof(io)==="undefined"){
16952
- // TRACE
16953
- console.log("«socket.io-client» NODE CLIENT library not called yet, calling it now.");
16954
- io=require("socket.io-client");
16955
- }
16956
- if(typeof(io)==="undefined"){
16957
- // TRACE
16958
- console.log("ERROR : «socket-client.io» NODE CLIENT library not found. Cannot launch nodejs server. Aborting.");
16959
- }
16960
- }
16961
-
16962
-
16946
+ window.WebSocket=WebsocketImplementation.implementationToUse.getSocketClass();
16963
16947
  }
16948
+ // // TRACE
16949
+ // lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
16950
+ //
16951
+ // if(isNodeContext){
16952
+ //
16953
+ // // NODE SERVER :
16954
+ // // DBG
16955
+ // lognow("INFO : Loading NODE SERVER socket.io libraries.")
16956
+ // if(typeof(Socket)==="undefined"){
16957
+ // // TRACE
16958
+ // console.log("«socket.io» NODE SERVER library not called yet, calling it now.");
16959
+ // Socket=require("socket.io");
16960
+ // }
16961
+ // if(typeof(Socket)==="undefined"){
16962
+ // // TRACE
16963
+ // console.log("ERROR : «socket.io» NODE CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
16964
+ // }
16965
+ //
16966
+ // // NODE CLIENT :
16967
+ // // DBG
16968
+ // lognow("INFO : Loading NODE CLIENT socket.io libraries.")
16969
+ // if(typeof(io)==="undefined"){
16970
+ // // TRACE
16971
+ // console.log("«socket.io-client» NODE CLIENT library not called yet, calling it now.");
16972
+ // io=require("socket.io-client");
16973
+ // }
16974
+ // if(typeof(io)==="undefined"){
16975
+ // // TRACE
16976
+ // console.log("ERROR : «socket-client.io» NODE CLIENT library not found. Cannot launch nodejs server. Aborting.");
16977
+ // }
16978
+ // }
16979
+ // }
16964
16980
 
16965
16981
  // *********************************************************************************
16966
16982
 
@@ -16970,8 +16986,12 @@ WebsocketImplementation={
16970
16986
 
16971
16987
  /*public*//*static*/getMessageDataBothImplementations:(eventOrMessageParam)=>{
16972
16988
 
16973
- const eventOrMessage=(!WebsocketImplementation.useSocketIOImplementation?eventOrMessageParam.data:eventOrMessageParam);
16974
-
16989
+ // const eventOrMessage=(!WebsocketImplementation.useSocketIOImplementation?eventOrMessageParam.data:eventOrMessageParam);
16990
+ const eventOrMessage=
16991
+ (!WebsocketImplementation.implementationToUse)?
16992
+ eventOrMessageParam.data
16993
+ :WebsocketImplementation.implementationToUse.getData(eventOrMessageParam);
16994
+
16975
16995
  let dataResult=eventOrMessage;
16976
16996
 
16977
16997
  try{
@@ -16993,42 +17013,43 @@ WebsocketImplementation={
16993
17013
  throw new Error("ERROR : SERVER : Server launch is not supported in a non-nodejs context for any implementation.");
16994
17014
  }
16995
17015
 
16996
-
16997
- // TODO : FIXME : Use one single interface !
16998
17016
  // NODE SERVER MODE ONLY :
16999
17017
  let serverSocket;
17000
- if(!WebsocketImplementation.useSocketIOImplementation){
17001
-
17018
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17019
+ if(!WebsocketImplementation.implementationToUse){
17002
17020
  if(typeof(WebSocketServer)==="undefined")
17003
17021
  window.WebSocketServer=require("ws");
17004
17022
  if(typeof(WebSocketServer)==="undefined")
17005
17023
  // TRACE
17006
17024
  lognow("ERROR : «ws» CONSOLE SERVER library not found. Cannot launch nodejs server. Aborting.");
17007
17025
 
17008
- // DOES NOT WORK ANYMORE :
17026
+ // DOES NOT WORK ANYMORE : (< node v20)
17009
17027
  // serverSocket=new WebSocket.Server({
17028
+ // DOES WORK NOW : (> node v20)
17010
17029
  serverSocket=new WebSocketServer.Server({
17030
+ // DOES WORK ALSO : (> node v20)
17011
17031
  // serverSocket=new window.WebSocketServer.WebSocketServer({
17012
17032
  server:listenableServer,
17013
- perMessageDeflate: false,
17033
+ perMessageDeflate: false, // (to improve a bit the security)
17014
17034
  });
17015
17035
 
17016
17036
  }else{
17017
-
17018
- // NOW : socket.io :
17019
- // Loading socket.io
17020
- // OLD SYNTAX : serverSocket=Socket.listen(listenableServer);
17021
- serverSocket=new Socket.Server(listenableServer);
17022
-
17023
- if(listenableServer.cert || listenableServer.key){
17024
- // TRACE :
17025
- lognow("WARN : CAUTION ! ON TODAY (01/08/2022) socket.io SERVER LIBRARY IS BOGUS AND WON'T WORK (node clients can't connect !!) IF listenableServer IS A https SERVER !!!");
17026
- }
17027
-
17028
- // Setting up the disconnect event for a client :
17029
- serverSocket.on("endConnection",()=>{
17030
- serverSocket.disconnect();
17031
- });
17037
+ serverSocket=WebsocketImplementation.implementationToUse.getServerSocket(listenableServer);
17038
+
17039
+ //
17040
+ // // Loading socket.io
17041
+ //// OLD SYNTAX : serverSocket=Socket.listen(listenableServer);
17042
+ // serverSocket=new Socket.Server(listenableServer);
17043
+ //
17044
+ // if(listenableServer.cert || listenableServer.key){
17045
+ // // TRACE :
17046
+ // lognow("WARN : CAUTION ! ON TODAY (01/08/2022) socket.io SERVER LIBRARY IS BOGUS AND WON'T WORK (node clients can't connect !!) IF listenableServer IS A https SERVER !!!");
17047
+ // }
17048
+ //
17049
+ // // Setting up the disconnect event for a client :
17050
+ // serverSocket.on("endConnection",()=>{
17051
+ // serverSocket.disconnect();
17052
+ // });
17032
17053
  }
17033
17054
 
17034
17055
  serverSocket.on("error",(error)=>{
@@ -17048,10 +17069,13 @@ WebsocketImplementation={
17048
17069
  // To make the server aware of the clients connections states :
17049
17070
  nodeServerInstance.serverSocket.on("close", function close() {
17050
17071
 
17051
- // TODO : FIXME : Use one single interface !
17052
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=nodeServerInstance.serverSocket.clients;
17053
- // OLD : else serverClients=nodeServerInstance.serverSocket.sockets.clients();
17054
- else serverClients=nodeServerInstance.serverSocket.sockets.sockets;
17072
+ // if(!WebsocketImplementation.useSocketIOImplementation)
17073
+ if(!WebsocketImplementation.implementationToUse){
17074
+ serverClients=nodeServerInstance.serverSocket.clients;
17075
+ }else{
17076
+ serverClients=WebsocketImplementation.implementationToUse.getClientSockets();
17077
+ // serverClients=nodeServerInstance.serverSocket.sockets.sockets;
17078
+ }
17055
17079
 
17056
17080
  serverClients.forEach((clientSocket)=>{
17057
17081
  clearInterval(clientSocket.stateCheckInterval);
@@ -17082,8 +17106,9 @@ WebsocketImplementation={
17082
17106
 
17083
17107
  // NODE CLIENT MODE ONLY :
17084
17108
  let clientSocket;
17085
- if(!WebsocketImplementation.useSocketIOImplementation){
17086
-
17109
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17110
+ if(!WebsocketImplementation.implementationToUse){
17111
+
17087
17112
  // NEW : ws :
17088
17113
  if(typeof(WebSocket)==="undefined"){
17089
17114
  // TRACE
@@ -17094,7 +17119,6 @@ WebsocketImplementation={
17094
17119
  // TRACE
17095
17120
  lognow("INFO : CLIENT : Trying to establish connection to server (serverURL:«"+serverURL+"» ; port:«"+port+"» ; isSecure:«"+isSecure+"»)");
17096
17121
 
17097
-
17098
17122
  clientSocket=new WebSocket(serverURL+":"+port,/*WORKAROUND:*/{
17099
17123
  // CAUTION : SECURITY BREACH :
17100
17124
  // BUT ALSO NECESSARY TO ALLOW SELF-SIGNED CERTIFICATES USAGE WITH THE YESBOT SYSTEM ON DEV ENVIRONMENTS !
@@ -17103,28 +17127,30 @@ WebsocketImplementation={
17103
17127
  secure: isSecure
17104
17128
  });
17105
17129
 
17130
+ // TODO : FIXME :
17131
+ // !!! CAUTION !!! ON TODAY (06/2026) IT DOES NOT WORK ON NODE VERSIONS > v20 !!!
17132
+ // MEANING IT WILL TRIGGER THE error EVENT FOR NO REASON WITH wss:// !!!
17106
17133
  clientSocket.addEventListener("error", error=>{
17107
17134
  // TRACE
17108
17135
  lognow("ERROR : (NODEJS) A WebSocket client error occurred while trying to connect to server: error:", error);
17109
17136
  });
17110
17137
 
17111
17138
  }else{
17112
- // NOW : socket.io :
17113
- //client on server-side:
17139
+ clientSocket=WebsocketImplementation.implementationToUse.getClientSocket(true);
17114
17140
 
17115
- if(WebsocketImplementation.isNodeContext && typeof(io)!=="undefined"){
17116
-
17117
- // OLD SYNTAX: clientSocket=Socket.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17118
- // NO : clientSocket=new Socket.Client(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17119
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure, autoConnect:true});
17120
- // UNUSEFUL (since we have the autoconnect:true option) : clientSocket.connect();
17121
-
17122
- clientSocket.on("connect_error", error=>{
17123
- // TRACE
17124
- lognow("ERROR : (NODEJS) A SocketIO client error occurred while trying to connect to server:", error.message);
17125
- });
17126
-
17127
- }
17141
+ // // NOW : socket.io :
17142
+ // //client on server-side:
17143
+ // if(WebsocketImplementation.isNodeContext && typeof(io)!=="undefined"){
17144
+ //// OLD SYNTAX: clientSocket=Socket.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17145
+ //// NO : clientSocket=new Socket.Client(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17146
+ // clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure, autoConnect:true});
17147
+ // // UNUSEFUL (since we have the autoconnect:true option) : clientSocket.connect();
17148
+ //
17149
+ // clientSocket.on("connect_error", error=>{
17150
+ // // TRACE
17151
+ // lognow("ERROR : (NODEJS) A SocketIO client error occurred while trying to connect to server:", error.message);
17152
+ // });
17153
+ // }
17128
17154
  }
17129
17155
 
17130
17156
  // DBG
@@ -17147,10 +17173,12 @@ WebsocketImplementation={
17147
17173
  return null;
17148
17174
  }
17149
17175
 
17150
- // TODO : FIXME : Use one single interface !
17151
17176
  // BROWSER CLIENT MODE ONLY :
17152
17177
  let clientSocket;
17153
- if(!WebsocketImplementation.useSocketIOImplementation){
17178
+
17179
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17180
+ if(!WebsocketImplementation.implementationToUse){
17181
+
17154
17182
  // CAUTION : PARAMETER rejectUnauthorized:false WILL DO NOTHING,
17155
17183
  // BECAUSE THIS IS COMPLETLY HANDLED BY THE BROWSER SECURITY POLICY !
17156
17184
  // SO TO CLEAR THE SSL ERROR :
@@ -17162,17 +17190,17 @@ WebsocketImplementation={
17162
17190
  // TRACE
17163
17191
  lognow("ERROR : (BROWSER) A WebSocket client error occurred while trying to connect to server:", error.message);
17164
17192
  });
17165
-
17166
- }else if(typeof(io)!=="undefined"){
17167
- // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17168
- // ALTERNATIVE :
17169
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17170
-
17171
- clientSocket.on("connect_error", error=>{
17172
- // TRACE
17173
- lognow("ERROR : (BROWSER) A SocketIO client error occurred while trying to connect to server:", error.message);
17174
- });
17175
-
17193
+ }else{
17194
+ // }else if(typeof(io)!=="undefined"){
17195
+ WebsocketImplementation.implementationToUse.getClientSocket();
17196
+ // // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17197
+ // // ALTERNATIVE :
17198
+ // clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17199
+ //
17200
+ // clientSocket.on("connect_error", error=>{
17201
+ // // TRACE
17202
+ // lognow("ERROR : (BROWSER) A SocketIO client error occurred while trying to connect to server:", error.message);
17203
+ // });
17176
17204
  }
17177
17205
 
17178
17206
  // BROWSER CLIENT INSTANCE :
@@ -17973,12 +18001,59 @@ if(typeof(window)==="undefined") window=global;
17973
18001
  // ==================================================================================================================
17974
18002
 
17975
18003
 
18004
+ // TODO : FIXME : DEVELOP...
18005
+ // THIS IS HOW A implementationToUse FOR WEBSOCKET TECHNOLOGY MUST BE :
18006
+ //
18007
+ //return WebsocketImplementation.implementationToUse.isConnected(clientSocket);
18008
+ //
18009
+ //return WebsocketImplementation.implementationToUse.getSocketClass();
18010
+ //
18011
+ //return WebsocketImplementation.implementationToUse.getData(eventOrMessageParam)
18012
+ // serverSocket=WebsocketImplementation.implementationToUse.getServerSocket(listenableServer);
18013
+ //
18014
+ //serverClients=WebsocketImplementation.implementationToUse.getClientSockets();
18015
+ //
18016
+ //clientSocket=WebsocketImplementation.implementationToUse.getClientSocket(isNodeContext=true);
18017
+ //
18018
+ //WebsocketImplementation.implementationToUse.send(dataWrapped);
18019
+ //WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
18020
+ //
18021
+ //WebsocketImplementation.implementationToUse.receive((eventOrMessage)=>{ });
18022
+ //
18023
+ //
18024
+ //WebsocketImplementation.implementationToUse.initClientSocket(clientSocket);
18025
+ //WebsocketImplementation.implementationToUse.initOnClose(()=>{
18026
+ // foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
18027
+ //});
18028
+ //
18029
+ //WebsocketImplementation.implementationToUse.initOnReceiveBrowserContext(channelNameParam, (eventOrMessage)=>{ });
18030
+ //
18031
+ //WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
18032
+ //
18033
+ //WebsocketImplementation.implementationToUse.getServerClients();
18034
+ //
18035
+ //if(WebsocketImplementation.implementationToUse.isReady(clientSocket)) return;
18036
+ // WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
18037
+ // WebsocketImplementation.implementationToUse.terminate();
18038
+ //
18039
+ //WebsocketImplementation.implementationToUse.ping();
18040
+ //
18041
+ //WebsocketImplementation.implementationToUse.doOnPong(()=>{
18042
+ // clientSocket.isConnectionAlive=true;
18043
+ //});
18044
+
18045
+
18046
+
18047
+
18048
+ // ==================================================================================================================
17976
18049
 
17977
18050
 
17978
18051
  // -Client :
17979
18052
 
17980
18053
  // TODO : Use everywhere it's applicable !
17981
- initClient=function(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false, doOnServerConnection=null, url, /*OPTIONAL*/port=25000, /*OPTIONAL*/timeout=10000, /*OPTIONAL*/selfParam=null){
18054
+ initClient=function(isNodeContext=true
18055
+ // ,useSocketIOImplementation=/*DEBUG*/false
18056
+ ,doOnServerConnection=null, url, /*OPTIONAL*/port=25000, /*OPTIONAL*/timeout=10000, /*OPTIONAL*/selfParam=null){
17982
18057
 
17983
18058
  const isSecure=(contains(url.toLowerCase(),"https:") || contains(url.toLowerCase(),"wss:"));
17984
18059
 
@@ -17990,7 +18065,9 @@ initClient=function(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false
17990
18065
  // DBG
17991
18066
  lognow("INFO : Setting up client :... (url:«"+url+"» ; port:«"+port+"»)");
17992
18067
 
17993
- let socketToServerClientInstance=WebsocketImplementation.getStatic(isNodeContext, useSocketIOImplementation).connectToServer(url, port, isSecure, timeout);
18068
+ let socketToServerClientInstance=WebsocketImplementation.getStatic(isNodeContext
18069
+ // , useSocketIOImplementation
18070
+ ).connectToServer(url, port, isSecure, timeout);
17994
18071
  if(!socketToServerClientInstance){
17995
18072
  // TRACE
17996
18073
  lognow("ERROR : CLIENT : Could not get socketToServerClientInstance, aborting client connection.");
@@ -18205,12 +18282,16 @@ class ClientInstance{
18205
18282
  this.clientReceptionEntryPoints.push(clientReceptionEntryPoint);
18206
18283
  }
18207
18284
 
18208
- const clientSocket=this.clientSocket;
18209
- if(WebsocketImplementation.useSocketIOImplementation){
18210
- // FOR THE SOCKETIO IMPLEMENTATION :
18211
- clientSocket.on(channelNameParam, (eventOrMessage)=>{
18285
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18286
+ // const clientSocket=this.clientSocket;
18287
+ // if(WebsocketImplementation.useSocketIOImplementation){
18288
+ if(WebsocketImplementation.implementationToUse){
18289
+ WebsocketImplementation.implementationToUse.initOnReceiveBrowserContext(channelNameParam, (eventOrMessage)=>{
18212
18290
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
18213
18291
  });
18292
+ // clientSocket.on(channelNameParam, (eventOrMessage)=>{
18293
+ // clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
18294
+ // });
18214
18295
  }
18215
18296
 
18216
18297
  return this;
@@ -18237,9 +18318,13 @@ class ClientInstance{
18237
18318
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
18238
18319
  dataWrapped=stringifyObject(dataWrapped);
18239
18320
 
18240
- // TODO : FIXME : Use one single interface !
18241
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18242
- else clientSocket.emit(channelNameParam,dataWrapped);
18321
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18322
+ if(!WebsocketImplementation.implementationToUse){
18323
+ clientSocket.send(dataWrapped);
18324
+ }else{
18325
+ WebsocketImplementation.implementationToUse.send(dataWrapped);
18326
+ // clientSocket.emit(channelNameParam,dataWrapped);
18327
+ }
18243
18328
 
18244
18329
  return this;
18245
18330
  }
@@ -18268,20 +18353,29 @@ class ClientInstance{
18268
18353
  lognow("DEBUG : CLIENT : doOnConnection !");
18269
18354
 
18270
18355
  const clientSocket=self.clientSocket;
18271
- if(!WebsocketImplementation.useSocketIOImplementation){
18356
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18357
+ if(!WebsocketImplementation.implementationToUse){
18272
18358
  // FOR THE WEBSOCKET IMPLEMENTATION :
18273
18359
  clientSocket.addEventListener("message", (eventOrMessage)=>{
18274
18360
  foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
18275
18361
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
18276
18362
  });
18277
18363
  });
18364
+ }else{
18365
+ WebsocketImplementation.implementationToUse.receive((eventOrMessage)=>{
18366
+ foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
18367
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
18368
+ });
18369
+ });
18278
18370
  }
18279
18371
 
18280
18372
  doOnConnection(self, clientSocket);
18281
18373
  };
18282
18374
 
18283
18375
 
18284
- if(!WebsocketImplementation.useSocketIOImplementation){
18376
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18377
+ if(!WebsocketImplementation.implementationToUse){
18378
+
18285
18379
  // FOR THE WEBSOCKET IMPLEMENTATION :
18286
18380
  this.clientSocket.addEventListener("open",doAllOnConnection);
18287
18381
 
@@ -18292,25 +18386,31 @@ class ClientInstance{
18292
18386
  }
18293
18387
 
18294
18388
  }else{
18295
- // FOR THE SOCKETIO IMPLEMENTATION :
18296
- this.clientSocket.on("connect",doAllOnConnection);
18297
-
18389
+ WebsocketImplementation.implementationToUse.initClientSocket(this.clientSocket);
18298
18390
  if(!empty(this.onServerLostListeners)){
18299
- this.clientSocket.on("close",()=>{
18391
+ WebsocketImplementation.implementationToUse.initOnClose(()=>{
18300
18392
  foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
18301
18393
  });
18302
18394
  }
18303
-
18304
-
18305
- // Client ping handling :
18306
- // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
18307
- // PING-PONG :
18308
- this.receive("protocol",(message)=>{
18309
- if(message.type!=="ping") return;
18310
- self.send("protocol",{type:"pong"});
18311
- // // DBG
18312
- // lognow("DEBUG : CLIENT : Pong sent.");
18313
- });
18395
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18396
+ // this.clientSocket.on("connect",doAllOnConnection);
18397
+ //
18398
+ // if(!empty(this.onServerLostListeners)){
18399
+ // this.clientSocket.on("close",()=>{
18400
+ // foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
18401
+ // });
18402
+ // }
18403
+ //
18404
+ //
18405
+ // // Client ping handling :
18406
+ // // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
18407
+ // // PING-PONG :
18408
+ // this.receive("protocol",(message)=>{
18409
+ // if(message.type!=="ping") return;
18410
+ // self.send("protocol",{type:"pong"});
18411
+ // // // DBG
18412
+ // // lognow("DEBUG : CLIENT : Pong sent.");
18413
+ // });
18314
18414
  }
18315
18415
 
18316
18416
 
@@ -18356,7 +18456,6 @@ class ServerReceptionEntryPoint{
18356
18456
  // Channel information is stored in exchanged data :
18357
18457
  if(dataWrapped.channelName!==this.channelName) return;
18358
18458
 
18359
- // TODO : FIXME : Use one single interface !
18360
18459
  // Room information is stored in client socket object :
18361
18460
  const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
18362
18461
 
@@ -18441,11 +18540,13 @@ class NodeServerInstance{
18441
18540
  this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
18442
18541
 
18443
18542
  // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
18444
- if(WebsocketImplementation.useSocketIOImplementation){
18445
- const channelName=serverReceptionEntryPoint.channelName;
18446
- clientSocket.on(channelName, (eventOrMessage)=>{
18447
- serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
18448
- });
18543
+ // if(WebsocketImplementation.useSocketIOImplementation){
18544
+ if(WebsocketImplementation.implementationToUse){
18545
+ WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
18546
+ // const channelName=serverReceptionEntryPoint.channelName;
18547
+ // clientSocket.on(channelName, (eventOrMessage)=>{
18548
+ // serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
18549
+ // });
18449
18550
  }
18450
18551
 
18451
18552
  return this;
@@ -18463,10 +18564,14 @@ class NodeServerInstance{
18463
18564
  // DBG
18464
18565
  lognow("(SERVER) (server sends to all clients)");
18465
18566
 
18466
- // TODO : FIXME : Use one single interface !
18467
18567
  let serverClients;
18468
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=this.serverSocket.clients;
18469
- else serverClients=this.serverSocket.sockets.sockets;
18568
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18569
+ if(!WebsocketImplementation.implementationToUse){
18570
+ serverClients=this.serverSocket.clients;
18571
+ }else{
18572
+ WebsocketImplementation.implementationToUse.getServerClients();
18573
+ // serverClients=this.serverSocket.sockets.sockets;
18574
+ }
18470
18575
 
18471
18576
 
18472
18577
  serverClients.forEach((clientSocket)=>{
@@ -18486,9 +18591,13 @@ class NodeServerInstance{
18486
18591
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
18487
18592
  dataWrapped=stringifyObject(dataWrapped);
18488
18593
 
18489
- // TODO : FIXME : Use one single interface !
18490
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18491
- else clientSocket.emit(channelName, dataWrapped);
18594
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18595
+ if(!WebsocketImplementation.implementationToUse){
18596
+ clientSocket.send(dataWrapped);
18597
+ }else{
18598
+ WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
18599
+ // clientSocket.emit(channelName, dataWrapped);
18600
+ }
18492
18601
 
18493
18602
  });
18494
18603
 
@@ -18498,10 +18607,14 @@ class NodeServerInstance{
18498
18607
  lognow("(SERVER) (server sends to a client)");
18499
18608
 
18500
18609
 
18501
- // TODO : FIXME : Use one single interface !
18502
18610
  let clientSocket=clientSocketParam;
18503
- if(!WebsocketImplementation.useSocketIOImplementation) if(clientSocket.readyState!==WebSocket.OPEN) return;
18504
- else if(clientSocket.connected) return;
18611
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18612
+ if(!WebsocketImplementation.implementationToUse){
18613
+ if(clientSocket.readyState!==WebSocket.OPEN) return;
18614
+ }else{
18615
+ if(WebsocketImplementation.implementationToUse.isReady(clientSocket)) return;
18616
+ // if(clientSocket.connected) return;
18617
+ }
18505
18618
 
18506
18619
 
18507
18620
  // Room information is stored in client socket object :
@@ -18516,9 +18629,13 @@ class NodeServerInstance{
18516
18629
  dataWrapped=stringifyObject(dataWrapped);
18517
18630
 
18518
18631
 
18519
- // TODO : FIXME : Use one single interface !
18520
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18521
- else clientSocket.emit(channelName,dataWrapped);
18632
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18633
+ if(!WebsocketImplementation.implementationToUse){
18634
+ clientSocket.send(dataWrapped);
18635
+ }else{
18636
+ WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
18637
+ // clientSocket.emit(channelName,dataWrapped);
18638
+ }
18522
18639
 
18523
18640
  }
18524
18641
 
@@ -18549,8 +18666,11 @@ class NodeServerInstance{
18549
18666
  });
18550
18667
  };
18551
18668
 
18552
- if(!WebsocketImplementation.useSocketIOImplementation){
18669
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18670
+ if(!WebsocketImplementation.implementationToUse){
18553
18671
  clientSocket.addEventListener("message", doOnMessage);
18672
+ }else{
18673
+ WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
18554
18674
  }
18555
18675
 
18556
18676
  doOnConnection(this, clientSocket);
@@ -18558,7 +18678,6 @@ class NodeServerInstance{
18558
18678
 
18559
18679
  // DBG
18560
18680
  lognow("DEBUG : Starting ping-pong with client : clientSocket.clientId:",clientSocket.clientId);
18561
- lognow("DEBUG : WebsocketImplementation.useSocketIOImplementation:",WebsocketImplementation.useSocketIOImplementation);
18562
18681
  lognow("DEBUG : clientSocket.readyState:",clientSocket.readyState);
18563
18682
 
18564
18683
 
@@ -18574,9 +18693,13 @@ class NodeServerInstance{
18574
18693
 
18575
18694
  clientSocket.removeAllListeners();
18576
18695
 
18577
- // TODO : FIXME : Use one single interface !
18578
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.terminate();
18579
- else clientSocket.emit("endConnection");
18696
+ // if(!WebsocketImplementation.useSocketIOImplementation)
18697
+ if(!WebsocketImplementation.implementationToUse){
18698
+ clientSocket.terminate();
18699
+ }else{
18700
+ WebsocketImplementation.implementationToUse.terminate();
18701
+ // clientSocket.emit("endConnection");
18702
+ }
18580
18703
 
18581
18704
  if(!empty(self.onClientLostListeners))
18582
18705
  foreach(self.onClientLostListeners,l=>{l.execute(clientSocket);});
@@ -18594,12 +18717,14 @@ class NodeServerInstance{
18594
18717
 
18595
18718
  clientSocket.isConnectionAlive=false;
18596
18719
 
18597
- if(!WebsocketImplementation.useSocketIOImplementation){
18720
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18721
+ if(!WebsocketImplementation.implementationToUse){
18598
18722
  // FOR THE WEBSOCKET IMPLEMENTATION :
18599
18723
  clientSocket.ping();
18600
18724
  }else{
18601
- // FOR THE SOCKETIO IMPLEMENTATION :
18602
- self.send("protocol",{type:"ping"}, null, clientSocket);
18725
+ WebsocketImplementation.implementationToUse.ping();
18726
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18727
+ // self.send("protocol",{type:"ping"}, null, clientSocket);
18603
18728
  }
18604
18729
 
18605
18730
 
@@ -18607,18 +18732,21 @@ class NodeServerInstance{
18607
18732
 
18608
18733
 
18609
18734
  // PING-PONG :
18610
- if(!WebsocketImplementation.useSocketIOImplementation){
18735
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18736
+ if(!WebsocketImplementation.implementationToUse){
18611
18737
  // FOR THE WEBSOCKET IMPLEMENTATION :
18612
18738
  clientSocket.on("pong",()=>{
18613
18739
  clientSocket.isConnectionAlive=true;
18614
18740
  });
18615
18741
  }else{
18616
- // FOR THE SOCKETIO IMPLEMENTATION :
18617
- this.receive("protocol",(message)=>{
18618
- if(message.type!=="pong") return;
18742
+ WebsocketImplementation.implementationToUse.doOnPong(()=>{
18619
18743
  clientSocket.isConnectionAlive=true;
18620
18744
  });
18621
-
18745
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18746
+ // this.receive("protocol",(message)=>{
18747
+ // if(message.type!=="pong") return;
18748
+ // clientSocket.isConnectionAlive=true;
18749
+ // });
18622
18750
  }
18623
18751
 
18624
18752
  });
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1889",
3
+ "version": "0.0.1892",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",