aotrautils 0.0.1888 → 0.0.1891

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:39:46)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
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:39:46)»*/
5473
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
5474
5474
  /*-----------------------------------------------------------------------------*/
5475
5475
  /* ## Utility global methods in a browser (htmljs) client environment.
5476
5476
  *
@@ -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:39:46)»*/
13294
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
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:39:46)»*/
14379
+ /*utils 3D library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
14377
14380
  /*-----------------------------------------------------------------------------*/
14378
14381
 
14379
- /*utils AI library associated with aotra version : «1_29072022-2359 (19/06/2026-22:39:46)»*/
14382
+ /*utils AI library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
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:39:46)»*/
14642
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (25/07/2026-21:58:29)»*/
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,41 +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
-
17002
- // if(typeof(WebSocketServer)==="undefined")
17003
- // window.WebSocketServer=require("ws");
17004
- // if(typeof(WebSocketServer)==="undefined")
17005
- // // TRACE
17006
- // lognow("ERROR : «ws» CONSOLE SERVER library not found. Cannot launch nodejs server. Aborting.");
17007
- // serverSocket=new window.WebSocketServer.WebSocketServer({
17018
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17019
+ if(!WebsocketImplementation.implementationToUse){
17020
+ if(typeof(WebSocketServer)==="undefined")
17021
+ window.WebSocketServer=require("ws");
17022
+ if(typeof(WebSocketServer)==="undefined")
17023
+ // TRACE
17024
+ lognow("ERROR : «ws» CONSOLE SERVER library not found. Cannot launch nodejs server. Aborting.");
17008
17025
 
17009
- // ??? :
17010
- serverSocket=new WebSocket.Server({
17026
+ // DOES NOT WORK ANYMORE : (< node v20)
17027
+ // serverSocket=new WebSocket.Server({
17028
+ // DOES WORK NOW : (> node v20)
17029
+ serverSocket=new WebSocketServer.Server({
17030
+ // DOES WORK ALSO : (> node v20)
17031
+ // serverSocket=new window.WebSocketServer.WebSocketServer({
17011
17032
  server:listenableServer,
17012
- perMessageDeflate: false,
17033
+ perMessageDeflate: false, // (to improve a bit the security)
17013
17034
  });
17014
17035
 
17015
17036
  }else{
17016
-
17017
- // NOW : socket.io :
17018
- // Loading socket.io
17019
- // OLD SYNTAX : serverSocket=Socket.listen(listenableServer);
17020
- serverSocket=new Socket.Server(listenableServer);
17021
-
17022
- if(listenableServer.cert || listenableServer.key){
17023
- // TRACE :
17024
- 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 !!!");
17025
- }
17026
-
17027
- // Setting up the disconnect event for a client :
17028
- serverSocket.on("endConnection",()=>{
17029
- serverSocket.disconnect();
17030
- });
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
+ // });
17031
17053
  }
17032
17054
 
17033
17055
  serverSocket.on("error",(error)=>{
@@ -17047,10 +17069,13 @@ WebsocketImplementation={
17047
17069
  // To make the server aware of the clients connections states :
17048
17070
  nodeServerInstance.serverSocket.on("close", function close() {
17049
17071
 
17050
- // TODO : FIXME : Use one single interface !
17051
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=nodeServerInstance.serverSocket.clients;
17052
- // OLD : else serverClients=nodeServerInstance.serverSocket.sockets.clients();
17053
- 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
+ }
17054
17079
 
17055
17080
  serverClients.forEach((clientSocket)=>{
17056
17081
  clearInterval(clientSocket.stateCheckInterval);
@@ -17081,8 +17106,9 @@ WebsocketImplementation={
17081
17106
 
17082
17107
  // NODE CLIENT MODE ONLY :
17083
17108
  let clientSocket;
17084
- if(!WebsocketImplementation.useSocketIOImplementation){
17085
-
17109
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17110
+ if(!WebsocketImplementation.implementationToUse){
17111
+
17086
17112
  // NEW : ws :
17087
17113
  if(typeof(WebSocket)==="undefined"){
17088
17114
  // TRACE
@@ -17093,7 +17119,6 @@ WebsocketImplementation={
17093
17119
  // TRACE
17094
17120
  lognow("INFO : CLIENT : Trying to establish connection to server (serverURL:«"+serverURL+"» ; port:«"+port+"» ; isSecure:«"+isSecure+"»)");
17095
17121
 
17096
-
17097
17122
  clientSocket=new WebSocket(serverURL+":"+port,/*WORKAROUND:*/{
17098
17123
  // CAUTION : SECURITY BREACH :
17099
17124
  // BUT ALSO NECESSARY TO ALLOW SELF-SIGNED CERTIFICATES USAGE WITH THE YESBOT SYSTEM ON DEV ENVIRONMENTS !
@@ -17102,28 +17127,30 @@ WebsocketImplementation={
17102
17127
  secure: isSecure
17103
17128
  });
17104
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:// !!!
17105
17133
  clientSocket.addEventListener("error", error=>{
17106
17134
  // TRACE
17107
17135
  lognow("ERROR : (NODEJS) A WebSocket client error occurred while trying to connect to server: error:", error);
17108
17136
  });
17109
17137
 
17110
17138
  }else{
17111
- // NOW : socket.io :
17112
- //client on server-side:
17139
+ clientSocket=WebsocketImplementation.implementationToUse.getClientSocket(true);
17113
17140
 
17114
- if(WebsocketImplementation.isNodeContext && typeof(io)!=="undefined"){
17115
-
17116
- // OLD SYNTAX: clientSocket=Socket.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17117
- // NO : clientSocket=new Socket.Client(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17118
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure, autoConnect:true});
17119
- // UNUSEFUL (since we have the autoconnect:true option) : clientSocket.connect();
17120
-
17121
- clientSocket.on("connect_error", error=>{
17122
- // TRACE
17123
- lognow("ERROR : (NODEJS) A SocketIO client error occurred while trying to connect to server:", error.message);
17124
- });
17125
-
17126
- }
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
+ // }
17127
17154
  }
17128
17155
 
17129
17156
  // DBG
@@ -17146,10 +17173,12 @@ WebsocketImplementation={
17146
17173
  return null;
17147
17174
  }
17148
17175
 
17149
- // TODO : FIXME : Use one single interface !
17150
17176
  // BROWSER CLIENT MODE ONLY :
17151
17177
  let clientSocket;
17152
- if(!WebsocketImplementation.useSocketIOImplementation){
17178
+
17179
+ // if(!WebsocketImplementation.useSocketIOImplementation){
17180
+ if(!WebsocketImplementation.implementationToUse){
17181
+
17153
17182
  // CAUTION : PARAMETER rejectUnauthorized:false WILL DO NOTHING,
17154
17183
  // BECAUSE THIS IS COMPLETLY HANDLED BY THE BROWSER SECURITY POLICY !
17155
17184
  // SO TO CLEAR THE SSL ERROR :
@@ -17161,17 +17190,17 @@ WebsocketImplementation={
17161
17190
  // TRACE
17162
17191
  lognow("ERROR : (BROWSER) A WebSocket client error occurred while trying to connect to server:", error.message);
17163
17192
  });
17164
-
17165
- }else if(typeof(io)!=="undefined"){
17166
- // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17167
- // ALTERNATIVE :
17168
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
17169
-
17170
- clientSocket.on("connect_error", error=>{
17171
- // TRACE
17172
- lognow("ERROR : (BROWSER) A SocketIO client error occurred while trying to connect to server:", error.message);
17173
- });
17174
-
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
+ // });
17175
17204
  }
17176
17205
 
17177
17206
  // BROWSER CLIENT INSTANCE :
@@ -17972,12 +18001,59 @@ if(typeof(window)==="undefined") window=global;
17972
18001
  // ==================================================================================================================
17973
18002
 
17974
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
+ // ==================================================================================================================
17975
18049
 
17976
18050
 
17977
18051
  // -Client :
17978
18052
 
17979
18053
  // TODO : Use everywhere it's applicable !
17980
- 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){
17981
18057
 
17982
18058
  const isSecure=(contains(url.toLowerCase(),"https:") || contains(url.toLowerCase(),"wss:"));
17983
18059
 
@@ -17989,7 +18065,9 @@ initClient=function(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false
17989
18065
  // DBG
17990
18066
  lognow("INFO : Setting up client :... (url:«"+url+"» ; port:«"+port+"»)");
17991
18067
 
17992
- 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);
17993
18071
  if(!socketToServerClientInstance){
17994
18072
  // TRACE
17995
18073
  lognow("ERROR : CLIENT : Could not get socketToServerClientInstance, aborting client connection.");
@@ -18204,12 +18282,16 @@ class ClientInstance{
18204
18282
  this.clientReceptionEntryPoints.push(clientReceptionEntryPoint);
18205
18283
  }
18206
18284
 
18207
- const clientSocket=this.clientSocket;
18208
- if(WebsocketImplementation.useSocketIOImplementation){
18209
- // FOR THE SOCKETIO IMPLEMENTATION :
18210
- 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)=>{
18211
18290
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
18212
18291
  });
18292
+ // clientSocket.on(channelNameParam, (eventOrMessage)=>{
18293
+ // clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
18294
+ // });
18213
18295
  }
18214
18296
 
18215
18297
  return this;
@@ -18236,9 +18318,13 @@ class ClientInstance{
18236
18318
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
18237
18319
  dataWrapped=stringifyObject(dataWrapped);
18238
18320
 
18239
- // TODO : FIXME : Use one single interface !
18240
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18241
- 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
+ }
18242
18328
 
18243
18329
  return this;
18244
18330
  }
@@ -18267,20 +18353,29 @@ class ClientInstance{
18267
18353
  lognow("DEBUG : CLIENT : doOnConnection !");
18268
18354
 
18269
18355
  const clientSocket=self.clientSocket;
18270
- if(!WebsocketImplementation.useSocketIOImplementation){
18356
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18357
+ if(!WebsocketImplementation.implementationToUse){
18271
18358
  // FOR THE WEBSOCKET IMPLEMENTATION :
18272
18359
  clientSocket.addEventListener("message", (eventOrMessage)=>{
18273
18360
  foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
18274
18361
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
18275
18362
  });
18276
18363
  });
18364
+ }else{
18365
+ WebsocketImplementation.implementationToUse.receive((eventOrMessage)=>{
18366
+ foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
18367
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
18368
+ });
18369
+ });
18277
18370
  }
18278
18371
 
18279
18372
  doOnConnection(self, clientSocket);
18280
18373
  };
18281
18374
 
18282
18375
 
18283
- if(!WebsocketImplementation.useSocketIOImplementation){
18376
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18377
+ if(!WebsocketImplementation.implementationToUse){
18378
+
18284
18379
  // FOR THE WEBSOCKET IMPLEMENTATION :
18285
18380
  this.clientSocket.addEventListener("open",doAllOnConnection);
18286
18381
 
@@ -18291,25 +18386,31 @@ class ClientInstance{
18291
18386
  }
18292
18387
 
18293
18388
  }else{
18294
- // FOR THE SOCKETIO IMPLEMENTATION :
18295
- this.clientSocket.on("connect",doAllOnConnection);
18296
-
18389
+ WebsocketImplementation.implementationToUse.initClientSocket(this.clientSocket);
18297
18390
  if(!empty(this.onServerLostListeners)){
18298
- this.clientSocket.on("close",()=>{
18391
+ WebsocketImplementation.implementationToUse.initOnClose(()=>{
18299
18392
  foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
18300
18393
  });
18301
18394
  }
18302
-
18303
-
18304
- // Client ping handling :
18305
- // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
18306
- // PING-PONG :
18307
- this.receive("protocol",(message)=>{
18308
- if(message.type!=="ping") return;
18309
- self.send("protocol",{type:"pong"});
18310
- // // DBG
18311
- // lognow("DEBUG : CLIENT : Pong sent.");
18312
- });
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
+ // });
18313
18414
  }
18314
18415
 
18315
18416
 
@@ -18355,7 +18456,6 @@ class ServerReceptionEntryPoint{
18355
18456
  // Channel information is stored in exchanged data :
18356
18457
  if(dataWrapped.channelName!==this.channelName) return;
18357
18458
 
18358
- // TODO : FIXME : Use one single interface !
18359
18459
  // Room information is stored in client socket object :
18360
18460
  const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
18361
18461
 
@@ -18440,11 +18540,13 @@ class NodeServerInstance{
18440
18540
  this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
18441
18541
 
18442
18542
  // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
18443
- if(WebsocketImplementation.useSocketIOImplementation){
18444
- const channelName=serverReceptionEntryPoint.channelName;
18445
- clientSocket.on(channelName, (eventOrMessage)=>{
18446
- serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
18447
- });
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
+ // });
18448
18550
  }
18449
18551
 
18450
18552
  return this;
@@ -18462,10 +18564,14 @@ class NodeServerInstance{
18462
18564
  // DBG
18463
18565
  lognow("(SERVER) (server sends to all clients)");
18464
18566
 
18465
- // TODO : FIXME : Use one single interface !
18466
18567
  let serverClients;
18467
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=this.serverSocket.clients;
18468
- 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
+ }
18469
18575
 
18470
18576
 
18471
18577
  serverClients.forEach((clientSocket)=>{
@@ -18485,9 +18591,13 @@ class NodeServerInstance{
18485
18591
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
18486
18592
  dataWrapped=stringifyObject(dataWrapped);
18487
18593
 
18488
- // TODO : FIXME : Use one single interface !
18489
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18490
- 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
+ }
18491
18601
 
18492
18602
  });
18493
18603
 
@@ -18497,10 +18607,14 @@ class NodeServerInstance{
18497
18607
  lognow("(SERVER) (server sends to a client)");
18498
18608
 
18499
18609
 
18500
- // TODO : FIXME : Use one single interface !
18501
18610
  let clientSocket=clientSocketParam;
18502
- if(!WebsocketImplementation.useSocketIOImplementation) if(clientSocket.readyState!==WebSocket.OPEN) return;
18503
- 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
+ }
18504
18618
 
18505
18619
 
18506
18620
  // Room information is stored in client socket object :
@@ -18515,9 +18629,13 @@ class NodeServerInstance{
18515
18629
  dataWrapped=stringifyObject(dataWrapped);
18516
18630
 
18517
18631
 
18518
- // TODO : FIXME : Use one single interface !
18519
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
18520
- 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
+ }
18521
18639
 
18522
18640
  }
18523
18641
 
@@ -18548,8 +18666,11 @@ class NodeServerInstance{
18548
18666
  });
18549
18667
  };
18550
18668
 
18551
- if(!WebsocketImplementation.useSocketIOImplementation){
18669
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18670
+ if(!WebsocketImplementation.implementationToUse){
18552
18671
  clientSocket.addEventListener("message", doOnMessage);
18672
+ }else{
18673
+ WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
18553
18674
  }
18554
18675
 
18555
18676
  doOnConnection(this, clientSocket);
@@ -18557,7 +18678,6 @@ class NodeServerInstance{
18557
18678
 
18558
18679
  // DBG
18559
18680
  lognow("DEBUG : Starting ping-pong with client : clientSocket.clientId:",clientSocket.clientId);
18560
- lognow("DEBUG : WebsocketImplementation.useSocketIOImplementation:",WebsocketImplementation.useSocketIOImplementation);
18561
18681
  lognow("DEBUG : clientSocket.readyState:",clientSocket.readyState);
18562
18682
 
18563
18683
 
@@ -18573,9 +18693,13 @@ class NodeServerInstance{
18573
18693
 
18574
18694
  clientSocket.removeAllListeners();
18575
18695
 
18576
- // TODO : FIXME : Use one single interface !
18577
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.terminate();
18578
- 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
+ }
18579
18703
 
18580
18704
  if(!empty(self.onClientLostListeners))
18581
18705
  foreach(self.onClientLostListeners,l=>{l.execute(clientSocket);});
@@ -18593,12 +18717,14 @@ class NodeServerInstance{
18593
18717
 
18594
18718
  clientSocket.isConnectionAlive=false;
18595
18719
 
18596
- if(!WebsocketImplementation.useSocketIOImplementation){
18720
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18721
+ if(!WebsocketImplementation.implementationToUse){
18597
18722
  // FOR THE WEBSOCKET IMPLEMENTATION :
18598
18723
  clientSocket.ping();
18599
18724
  }else{
18600
- // FOR THE SOCKETIO IMPLEMENTATION :
18601
- self.send("protocol",{type:"ping"}, null, clientSocket);
18725
+ WebsocketImplementation.implementationToUse.ping();
18726
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18727
+ // self.send("protocol",{type:"ping"}, null, clientSocket);
18602
18728
  }
18603
18729
 
18604
18730
 
@@ -18606,18 +18732,21 @@ class NodeServerInstance{
18606
18732
 
18607
18733
 
18608
18734
  // PING-PONG :
18609
- if(!WebsocketImplementation.useSocketIOImplementation){
18735
+ // if(!WebsocketImplementation.useSocketIOImplementation){
18736
+ if(!WebsocketImplementation.implementationToUse){
18610
18737
  // FOR THE WEBSOCKET IMPLEMENTATION :
18611
18738
  clientSocket.on("pong",()=>{
18612
18739
  clientSocket.isConnectionAlive=true;
18613
18740
  });
18614
18741
  }else{
18615
- // FOR THE SOCKETIO IMPLEMENTATION :
18616
- this.receive("protocol",(message)=>{
18617
- if(message.type!=="pong") return;
18742
+ WebsocketImplementation.implementationToUse.doOnPong(()=>{
18618
18743
  clientSocket.isConnectionAlive=true;
18619
18744
  });
18620
-
18745
+ // // FOR THE SOCKETIO IMPLEMENTATION :
18746
+ // this.receive("protocol",(message)=>{
18747
+ // if(message.type!=="pong") return;
18748
+ // clientSocket.isConnectionAlive=true;
18749
+ // });
18621
18750
  }
18622
18751
 
18623
18752
  });
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1888",
3
+ "version": "0.0.1891",
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)",