aotrautils-srv 0.0.1887 → 0.0.1890

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:40:10)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (25/07/2026-21:59:01)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5470,7 +5470,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5470
5470
 
5471
5471
 
5472
5472
 
5473
- /*utils AI library associated with aotra version : «1_29072022-2359 (19/06/2026-22:40:10)»*/
5473
+ /*utils AI library associated with aotra version : «1_29072022-2359 (25/07/2026-21:59:01)»*/
5474
5474
  /*-----------------------------------------------------------------------------*/
5475
5475
 
5476
5476
 
@@ -5730,7 +5730,7 @@ getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProviderName=DE
5730
5730
 
5731
5731
 
5732
5732
 
5733
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (19/06/2026-22:40:10)»*/
5733
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (25/07/2026-21:59:01)»*/
5734
5734
  /*-----------------------------------------------------------------------------*/
5735
5735
 
5736
5736
 
@@ -5773,7 +5773,7 @@ if(typeof(window)==="undefined") window=global;
5773
5773
 
5774
5774
  class AORTACClientCell{
5775
5775
 
5776
- constructor(serverCellOrigin, model, view, isNodeContext=false){
5776
+ constructor(serverCellOrigin, model, view, isNodeContext=true){
5777
5777
 
5778
5778
  this.clientId=getUUID();
5779
5779
 
@@ -5816,7 +5816,9 @@ class AORTACClientCell{
5816
5816
 
5817
5817
 
5818
5818
  // 1) Initial connection
5819
- self.initialClientInstance=initClient(self.isNodeContext, false, (socketToServerClientInstance, initialClientInstanceLocal)=>{
5819
+ self.initialClientInstance=initClient(self.isNodeContext
5820
+ // ,false
5821
+ ,(socketToServerClientInstance, initialClientInstanceLocal)=>{
5820
5822
 
5821
5823
  // DBG
5822
5824
  lognow("DEBUG : Starting client...");
@@ -5910,7 +5912,9 @@ class AORTACClientCell{
5910
5912
  const host=nonull(infos.host,"localhost");
5911
5913
  const port=nonull(infos.port,"30000");
5912
5914
 
5913
- const reconnectedClientInstance=initClient(self.isNodeContext, false, (socketToServerClientInstance, reconnectedClientInstanceLocal)=>{
5915
+ const reconnectedClientInstance=initClient(self.isNodeContext
5916
+ // ,false
5917
+ ,(socketToServerClientInstance, reconnectedClientInstanceLocal)=>{
5914
5918
 
5915
5919
  // DBG
5916
5920
  lognow("DEBUG : Starting reconnected client...");
@@ -6092,7 +6096,7 @@ class ClientLobule{
6092
6096
 
6093
6097
 
6094
6098
 
6095
- window.getAORTACClient=function(serverCellOrigin="ws://127.0.0.1:40000", model, view, isNodeContext=false){
6099
+ window.getAORTACClient=function(serverCellOrigin="ws://127.0.0.1:40000", model, view, isNodeContext=true){
6096
6100
  if(nothing(serverCellOrigin)){
6097
6101
  // TRACE
6098
6102
  lognow("ERROR : No known server node, cannot connect to servers cells blob. Aborting AORTAC client setup.");
@@ -6307,7 +6311,9 @@ class AORTACServerCell{
6307
6311
  const outcomingCellHost=nonull(infos.host,"localhost");
6308
6312
  const outcomingCellPort=nonull(infos.port,"40000");
6309
6313
 
6310
- const clientInstance=initClient(true, false, (socketToServerClientInstance)=>{
6314
+ const clientInstance=initClient(true
6315
+ // ,false
6316
+ ,(socketToServerClientInstance)=>{
6311
6317
 
6312
6318
 
6313
6319
  const channelsNames=[];
@@ -7845,9 +7851,11 @@ window.fileExists=(filePath)=>{
7845
7851
  //- WEBSOCKETS AND NODEJS :
7846
7852
 
7847
7853
  function isConnected(clientSocket){
7848
- if(!WebsocketImplementation.useSocketIOImplementation)
7849
- return (clientSocket.readyState===WebSocket.OPEN)
7850
- return (clientSocket.connected);
7854
+ // if(!WebsocketImplementation.useSocketIOImplementation)
7855
+ if(!WebsocketImplementation.implementationToUse)
7856
+ return (clientSocket.readyState===WebSocket.OPEN)
7857
+ return WebsocketImplementation.implementationToUse.isConnected(clientSocket);
7858
+ // return (clientSocket.connected);
7851
7859
  }
7852
7860
 
7853
7861
  // Client-side or Server-side :
@@ -7984,7 +7992,8 @@ WebsocketImplementation={
7984
7992
 
7985
7993
 
7986
7994
  isNodeContext:true,
7987
- useSocketIOImplementation:false,
7995
+ // useSocketIOImplementation:false,
7996
+ implementationToUse:null,// null is default (WebSocket)
7988
7997
  useFlatStrings:false,
7989
7998
 
7990
7999
  // COMMON METHODS
@@ -7996,12 +8005,16 @@ WebsocketImplementation={
7996
8005
  //
7997
8006
  // CONSOLE NODE SERVER/CLIENT
7998
8007
  //
7999
- getStatic:(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false)=>{
8008
+ getStatic:(isNodeContext=true
8009
+ // , useSocketIOImplementation=/*DEBUG*/false
8010
+ )=>{
8000
8011
 
8001
8012
  WebsocketImplementation.isNodeContext=isNodeContext;
8002
- WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
8013
+ // WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
8014
+
8015
+ // if(!WebsocketImplementation.useSocketIOImplementation){
8016
+ if(!WebsocketImplementation.implementationToUse){
8003
8017
 
8004
- if(!WebsocketImplementation.useSocketIOImplementation){
8005
8018
  // TRACE
8006
8019
  lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
8007
8020
 
@@ -8021,40 +8034,40 @@ WebsocketImplementation={
8021
8034
  }
8022
8035
 
8023
8036
  }else{
8024
- // TRACE
8025
- lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
8026
-
8027
- if(isNodeContext){
8028
-
8029
- // NODE SERVER :
8030
- // DBG
8031
- lognow("INFO : Loading NODE SERVER socket.io libraries.")
8032
- if(typeof(Socket)==="undefined"){
8033
- // TRACE
8034
- console.log("«socket.io» NODE SERVER library not called yet, calling it now.");
8035
- Socket=require("socket.io");
8036
- }
8037
- if(typeof(Socket)==="undefined"){
8038
- // TRACE
8039
- console.log("ERROR : «socket.io» NODE CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
8040
- }
8041
-
8042
- // NODE CLIENT :
8043
- // DBG
8044
- lognow("INFO : Loading NODE CLIENT socket.io libraries.")
8045
- if(typeof(io)==="undefined"){
8046
- // TRACE
8047
- console.log("«socket.io-client» NODE CLIENT library not called yet, calling it now.");
8048
- io=require("socket.io-client");
8049
- }
8050
- if(typeof(io)==="undefined"){
8051
- // TRACE
8052
- console.log("ERROR : «socket-client.io» NODE CLIENT library not found. Cannot launch nodejs server. Aborting.");
8053
- }
8054
- }
8055
-
8056
-
8037
+ window.WebSocket=WebsocketImplementation.implementationToUse.getSocketClass();
8057
8038
  }
8039
+ // // TRACE
8040
+ // lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
8041
+ //
8042
+ // if(isNodeContext){
8043
+ //
8044
+ // // NODE SERVER :
8045
+ // // DBG
8046
+ // lognow("INFO : Loading NODE SERVER socket.io libraries.")
8047
+ // if(typeof(Socket)==="undefined"){
8048
+ // // TRACE
8049
+ // console.log("«socket.io» NODE SERVER library not called yet, calling it now.");
8050
+ // Socket=require("socket.io");
8051
+ // }
8052
+ // if(typeof(Socket)==="undefined"){
8053
+ // // TRACE
8054
+ // console.log("ERROR : «socket.io» NODE CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
8055
+ // }
8056
+ //
8057
+ // // NODE CLIENT :
8058
+ // // DBG
8059
+ // lognow("INFO : Loading NODE CLIENT socket.io libraries.")
8060
+ // if(typeof(io)==="undefined"){
8061
+ // // TRACE
8062
+ // console.log("«socket.io-client» NODE CLIENT library not called yet, calling it now.");
8063
+ // io=require("socket.io-client");
8064
+ // }
8065
+ // if(typeof(io)==="undefined"){
8066
+ // // TRACE
8067
+ // console.log("ERROR : «socket-client.io» NODE CLIENT library not found. Cannot launch nodejs server. Aborting.");
8068
+ // }
8069
+ // }
8070
+ // }
8058
8071
 
8059
8072
  // *********************************************************************************
8060
8073
 
@@ -8064,8 +8077,12 @@ WebsocketImplementation={
8064
8077
 
8065
8078
  /*public*//*static*/getMessageDataBothImplementations:(eventOrMessageParam)=>{
8066
8079
 
8067
- const eventOrMessage=(!WebsocketImplementation.useSocketIOImplementation?eventOrMessageParam.data:eventOrMessageParam);
8068
-
8080
+ // const eventOrMessage=(!WebsocketImplementation.useSocketIOImplementation?eventOrMessageParam.data:eventOrMessageParam);
8081
+ const eventOrMessage=
8082
+ (!WebsocketImplementation.implementationToUse)?
8083
+ eventOrMessageParam.data
8084
+ :WebsocketImplementation.implementationToUse.getData(eventOrMessageParam);
8085
+
8069
8086
  let dataResult=eventOrMessage;
8070
8087
 
8071
8088
  try{
@@ -8087,41 +8104,43 @@ WebsocketImplementation={
8087
8104
  throw new Error("ERROR : SERVER : Server launch is not supported in a non-nodejs context for any implementation.");
8088
8105
  }
8089
8106
 
8090
-
8091
- // TODO : FIXME : Use one single interface !
8092
8107
  // NODE SERVER MODE ONLY :
8093
8108
  let serverSocket;
8094
- if(!WebsocketImplementation.useSocketIOImplementation){
8095
-
8096
- // if(typeof(WebSocketServer)==="undefined")
8097
- // window.WebSocketServer=require("ws");
8098
- // if(typeof(WebSocketServer)==="undefined")
8099
- // // TRACE
8100
- // lognow("ERROR : «ws» CONSOLE SERVER library not found. Cannot launch nodejs server. Aborting.");
8101
- // serverSocket=new window.WebSocketServer.WebSocketServer({
8109
+ // if(!WebsocketImplementation.useSocketIOImplementation){
8110
+ if(!WebsocketImplementation.implementationToUse){
8111
+ if(typeof(WebSocketServer)==="undefined")
8112
+ window.WebSocketServer=require("ws");
8113
+ if(typeof(WebSocketServer)==="undefined")
8114
+ // TRACE
8115
+ lognow("ERROR : «ws» CONSOLE SERVER library not found. Cannot launch nodejs server. Aborting.");
8102
8116
 
8103
- // ??? :
8104
- serverSocket=new WebSocket.Server({
8117
+ // DOES NOT WORK ANYMORE : (< node v20)
8118
+ // serverSocket=new WebSocket.Server({
8119
+ // DOES WORK NOW : (> node v20)
8120
+ serverSocket=new WebSocketServer.Server({
8121
+ // DOES WORK ALSO : (> node v20)
8122
+ // serverSocket=new window.WebSocketServer.WebSocketServer({
8105
8123
  server:listenableServer,
8106
- perMessageDeflate: false,
8124
+ perMessageDeflate: false, // (to improve a bit the security)
8107
8125
  });
8108
8126
 
8109
8127
  }else{
8110
-
8111
- // NOW : socket.io :
8112
- // Loading socket.io
8113
- // OLD SYNTAX : serverSocket=Socket.listen(listenableServer);
8114
- serverSocket=new Socket.Server(listenableServer);
8115
-
8116
- if(listenableServer.cert || listenableServer.key){
8117
- // TRACE :
8118
- 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 !!!");
8119
- }
8120
-
8121
- // Setting up the disconnect event for a client :
8122
- serverSocket.on("endConnection",()=>{
8123
- serverSocket.disconnect();
8124
- });
8128
+ serverSocket=WebsocketImplementation.implementationToUse.getServerSocket(listenableServer);
8129
+
8130
+ //
8131
+ // // Loading socket.io
8132
+ //// OLD SYNTAX : serverSocket=Socket.listen(listenableServer);
8133
+ // serverSocket=new Socket.Server(listenableServer);
8134
+ //
8135
+ // if(listenableServer.cert || listenableServer.key){
8136
+ // // TRACE :
8137
+ // 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 !!!");
8138
+ // }
8139
+ //
8140
+ // // Setting up the disconnect event for a client :
8141
+ // serverSocket.on("endConnection",()=>{
8142
+ // serverSocket.disconnect();
8143
+ // });
8125
8144
  }
8126
8145
 
8127
8146
  serverSocket.on("error",(error)=>{
@@ -8141,10 +8160,13 @@ WebsocketImplementation={
8141
8160
  // To make the server aware of the clients connections states :
8142
8161
  nodeServerInstance.serverSocket.on("close", function close() {
8143
8162
 
8144
- // TODO : FIXME : Use one single interface !
8145
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=nodeServerInstance.serverSocket.clients;
8146
- // OLD : else serverClients=nodeServerInstance.serverSocket.sockets.clients();
8147
- else serverClients=nodeServerInstance.serverSocket.sockets.sockets;
8163
+ // if(!WebsocketImplementation.useSocketIOImplementation)
8164
+ if(!WebsocketImplementation.implementationToUse){
8165
+ serverClients=nodeServerInstance.serverSocket.clients;
8166
+ }else{
8167
+ serverClients=WebsocketImplementation.implementationToUse.getClientSockets();
8168
+ // serverClients=nodeServerInstance.serverSocket.sockets.sockets;
8169
+ }
8148
8170
 
8149
8171
  serverClients.forEach((clientSocket)=>{
8150
8172
  clearInterval(clientSocket.stateCheckInterval);
@@ -8175,8 +8197,9 @@ WebsocketImplementation={
8175
8197
 
8176
8198
  // NODE CLIENT MODE ONLY :
8177
8199
  let clientSocket;
8178
- if(!WebsocketImplementation.useSocketIOImplementation){
8179
-
8200
+ // if(!WebsocketImplementation.useSocketIOImplementation){
8201
+ if(!WebsocketImplementation.implementationToUse){
8202
+
8180
8203
  // NEW : ws :
8181
8204
  if(typeof(WebSocket)==="undefined"){
8182
8205
  // TRACE
@@ -8187,7 +8210,6 @@ WebsocketImplementation={
8187
8210
  // TRACE
8188
8211
  lognow("INFO : CLIENT : Trying to establish connection to server (serverURL:«"+serverURL+"» ; port:«"+port+"» ; isSecure:«"+isSecure+"»)");
8189
8212
 
8190
-
8191
8213
  clientSocket=new WebSocket(serverURL+":"+port,/*WORKAROUND:*/{
8192
8214
  // CAUTION : SECURITY BREACH :
8193
8215
  // BUT ALSO NECESSARY TO ALLOW SELF-SIGNED CERTIFICATES USAGE WITH THE YESBOT SYSTEM ON DEV ENVIRONMENTS !
@@ -8196,28 +8218,30 @@ WebsocketImplementation={
8196
8218
  secure: isSecure
8197
8219
  });
8198
8220
 
8221
+ // TODO : FIXME :
8222
+ // !!! CAUTION !!! ON TODAY (06/2026) IT DOES NOT WORK ON NODE VERSIONS > v20 !!!
8223
+ // MEANING IT WILL TRIGGER THE error EVENT FOR NO REASON WITH wss:// !!!
8199
8224
  clientSocket.addEventListener("error", error=>{
8200
8225
  // TRACE
8201
8226
  lognow("ERROR : (NODEJS) A WebSocket client error occurred while trying to connect to server: error:", error);
8202
8227
  });
8203
8228
 
8204
8229
  }else{
8205
- // NOW : socket.io :
8206
- //client on server-side:
8207
-
8208
- if(WebsocketImplementation.isNodeContext && typeof(io)!=="undefined"){
8209
-
8210
- // OLD SYNTAX: clientSocket=Socket.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8211
- // NO : clientSocket=new Socket.Client(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8212
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure, autoConnect:true});
8213
- // UNUSEFUL (since we have the autoconnect:true option) : clientSocket.connect();
8214
-
8215
- clientSocket.on("connect_error", error=>{
8216
- // TRACE
8217
- lognow("ERROR : (NODEJS) A SocketIO client error occurred while trying to connect to server:", error.message);
8218
- });
8219
-
8220
- }
8230
+ clientSocket=WebsocketImplementation.implementationToUse.getClientSocket(true);
8231
+
8232
+ // // NOW : socket.io :
8233
+ // //client on server-side:
8234
+ // if(WebsocketImplementation.isNodeContext && typeof(io)!=="undefined"){
8235
+ //// OLD SYNTAX: clientSocket=Socket.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8236
+ //// NO : clientSocket=new Socket.Client(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8237
+ // clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure, autoConnect:true});
8238
+ // // UNUSEFUL (since we have the autoconnect:true option) : clientSocket.connect();
8239
+ //
8240
+ // clientSocket.on("connect_error", error=>{
8241
+ // // TRACE
8242
+ // lognow("ERROR : (NODEJS) A SocketIO client error occurred while trying to connect to server:", error.message);
8243
+ // });
8244
+ // }
8221
8245
  }
8222
8246
 
8223
8247
  // DBG
@@ -8240,10 +8264,12 @@ WebsocketImplementation={
8240
8264
  return null;
8241
8265
  }
8242
8266
 
8243
- // TODO : FIXME : Use one single interface !
8244
8267
  // BROWSER CLIENT MODE ONLY :
8245
8268
  let clientSocket;
8246
- if(!WebsocketImplementation.useSocketIOImplementation){
8269
+
8270
+ // if(!WebsocketImplementation.useSocketIOImplementation){
8271
+ if(!WebsocketImplementation.implementationToUse){
8272
+
8247
8273
  // CAUTION : PARAMETER rejectUnauthorized:false WILL DO NOTHING,
8248
8274
  // BECAUSE THIS IS COMPLETLY HANDLED BY THE BROWSER SECURITY POLICY !
8249
8275
  // SO TO CLEAR THE SSL ERROR :
@@ -8255,17 +8281,17 @@ WebsocketImplementation={
8255
8281
  // TRACE
8256
8282
  lognow("ERROR : (BROWSER) A WebSocket client error occurred while trying to connect to server:", error.message);
8257
8283
  });
8258
-
8259
- }else if(typeof(io)!=="undefined"){
8260
- // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8261
- // ALTERNATIVE :
8262
- clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8263
-
8264
- clientSocket.on("connect_error", error=>{
8265
- // TRACE
8266
- lognow("ERROR : (BROWSER) A SocketIO client error occurred while trying to connect to server:", error.message);
8267
- });
8268
-
8284
+ }else{
8285
+ // }else if(typeof(io)!=="undefined"){
8286
+ WebsocketImplementation.implementationToUse.getClientSocket();
8287
+ // // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8288
+ // // ALTERNATIVE :
8289
+ // clientSocket=io(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
8290
+ //
8291
+ // clientSocket.on("connect_error", error=>{
8292
+ // // TRACE
8293
+ // lognow("ERROR : (BROWSER) A SocketIO client error occurred while trying to connect to server:", error.message);
8294
+ // });
8269
8295
  }
8270
8296
 
8271
8297
  // BROWSER CLIENT INSTANCE :
@@ -9066,12 +9092,59 @@ if(typeof(window)==="undefined") window=global;
9066
9092
  // ==================================================================================================================
9067
9093
 
9068
9094
 
9095
+ // TODO : FIXME : DEVELOP...
9096
+ // THIS IS HOW A implementationToUse FOR WEBSOCKET TECHNOLOGY MUST BE :
9097
+ //
9098
+ //return WebsocketImplementation.implementationToUse.isConnected(clientSocket);
9099
+ //
9100
+ //return WebsocketImplementation.implementationToUse.getSocketClass();
9101
+ //
9102
+ //return WebsocketImplementation.implementationToUse.getData(eventOrMessageParam)
9103
+ // serverSocket=WebsocketImplementation.implementationToUse.getServerSocket(listenableServer);
9104
+ //
9105
+ //serverClients=WebsocketImplementation.implementationToUse.getClientSockets();
9106
+ //
9107
+ //clientSocket=WebsocketImplementation.implementationToUse.getClientSocket(isNodeContext=true);
9108
+ //
9109
+ //WebsocketImplementation.implementationToUse.send(dataWrapped);
9110
+ //WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
9111
+ //
9112
+ //WebsocketImplementation.implementationToUse.receive((eventOrMessage)=>{ });
9113
+ //
9114
+ //
9115
+ //WebsocketImplementation.implementationToUse.initClientSocket(clientSocket);
9116
+ //WebsocketImplementation.implementationToUse.initOnClose(()=>{
9117
+ // foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
9118
+ //});
9119
+ //
9120
+ //WebsocketImplementation.implementationToUse.initOnReceiveBrowserContext(channelNameParam, (eventOrMessage)=>{ });
9121
+ //
9122
+ //WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
9123
+ //
9124
+ //WebsocketImplementation.implementationToUse.getServerClients();
9125
+ //
9126
+ //if(WebsocketImplementation.implementationToUse.isReady(clientSocket)) return;
9127
+ // WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
9128
+ // WebsocketImplementation.implementationToUse.terminate();
9129
+ //
9130
+ //WebsocketImplementation.implementationToUse.ping();
9131
+ //
9132
+ //WebsocketImplementation.implementationToUse.doOnPong(()=>{
9133
+ // clientSocket.isConnectionAlive=true;
9134
+ //});
9135
+
9136
+
9137
+
9138
+
9139
+ // ==================================================================================================================
9069
9140
 
9070
9141
 
9071
9142
  // -Client :
9072
9143
 
9073
9144
  // TODO : Use everywhere it's applicable !
9074
- initClient=function(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false, doOnServerConnection=null, url, /*OPTIONAL*/port=25000, /*OPTIONAL*/timeout=10000, /*OPTIONAL*/selfParam=null){
9145
+ initClient=function(isNodeContext=true
9146
+ // ,useSocketIOImplementation=/*DEBUG*/false
9147
+ ,doOnServerConnection=null, url, /*OPTIONAL*/port=25000, /*OPTIONAL*/timeout=10000, /*OPTIONAL*/selfParam=null){
9075
9148
 
9076
9149
  const isSecure=(contains(url.toLowerCase(),"https:") || contains(url.toLowerCase(),"wss:"));
9077
9150
 
@@ -9083,7 +9156,9 @@ initClient=function(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false
9083
9156
  // DBG
9084
9157
  lognow("INFO : Setting up client :... (url:«"+url+"» ; port:«"+port+"»)");
9085
9158
 
9086
- let socketToServerClientInstance=WebsocketImplementation.getStatic(isNodeContext, useSocketIOImplementation).connectToServer(url, port, isSecure, timeout);
9159
+ let socketToServerClientInstance=WebsocketImplementation.getStatic(isNodeContext
9160
+ // , useSocketIOImplementation
9161
+ ).connectToServer(url, port, isSecure, timeout);
9087
9162
  if(!socketToServerClientInstance){
9088
9163
  // TRACE
9089
9164
  lognow("ERROR : CLIENT : Could not get socketToServerClientInstance, aborting client connection.");
@@ -9298,12 +9373,16 @@ class ClientInstance{
9298
9373
  this.clientReceptionEntryPoints.push(clientReceptionEntryPoint);
9299
9374
  }
9300
9375
 
9301
- const clientSocket=this.clientSocket;
9302
- if(WebsocketImplementation.useSocketIOImplementation){
9303
- // FOR THE SOCKETIO IMPLEMENTATION :
9304
- clientSocket.on(channelNameParam, (eventOrMessage)=>{
9376
+ // // FOR THE SOCKETIO IMPLEMENTATION :
9377
+ // const clientSocket=this.clientSocket;
9378
+ // if(WebsocketImplementation.useSocketIOImplementation){
9379
+ if(WebsocketImplementation.implementationToUse){
9380
+ WebsocketImplementation.implementationToUse.initOnReceiveBrowserContext(channelNameParam, (eventOrMessage)=>{
9305
9381
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
9306
9382
  });
9383
+ // clientSocket.on(channelNameParam, (eventOrMessage)=>{
9384
+ // clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, this.clientReceptionEntryPoints);
9385
+ // });
9307
9386
  }
9308
9387
 
9309
9388
  return this;
@@ -9330,9 +9409,13 @@ class ClientInstance{
9330
9409
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
9331
9410
  dataWrapped=stringifyObject(dataWrapped);
9332
9411
 
9333
- // TODO : FIXME : Use one single interface !
9334
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
9335
- else clientSocket.emit(channelNameParam,dataWrapped);
9412
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9413
+ if(!WebsocketImplementation.implementationToUse){
9414
+ clientSocket.send(dataWrapped);
9415
+ }else{
9416
+ WebsocketImplementation.implementationToUse.send(dataWrapped);
9417
+ // clientSocket.emit(channelNameParam,dataWrapped);
9418
+ }
9336
9419
 
9337
9420
  return this;
9338
9421
  }
@@ -9361,20 +9444,29 @@ class ClientInstance{
9361
9444
  lognow("DEBUG : CLIENT : doOnConnection !");
9362
9445
 
9363
9446
  const clientSocket=self.clientSocket;
9364
- if(!WebsocketImplementation.useSocketIOImplementation){
9447
+ // if(!WebsocketImplementation.useSocketIOImplementation){
9448
+ if(!WebsocketImplementation.implementationToUse){
9365
9449
  // FOR THE WEBSOCKET IMPLEMENTATION :
9366
9450
  clientSocket.addEventListener("message", (eventOrMessage)=>{
9367
9451
  foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
9368
9452
  clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
9369
9453
  });
9370
9454
  });
9455
+ }else{
9456
+ WebsocketImplementation.implementationToUse.receive((eventOrMessage)=>{
9457
+ foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
9458
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
9459
+ });
9460
+ });
9371
9461
  }
9372
9462
 
9373
9463
  doOnConnection(self, clientSocket);
9374
9464
  };
9375
9465
 
9376
9466
 
9377
- if(!WebsocketImplementation.useSocketIOImplementation){
9467
+ // if(!WebsocketImplementation.useSocketIOImplementation){
9468
+ if(!WebsocketImplementation.implementationToUse){
9469
+
9378
9470
  // FOR THE WEBSOCKET IMPLEMENTATION :
9379
9471
  this.clientSocket.addEventListener("open",doAllOnConnection);
9380
9472
 
@@ -9385,25 +9477,31 @@ class ClientInstance{
9385
9477
  }
9386
9478
 
9387
9479
  }else{
9388
- // FOR THE SOCKETIO IMPLEMENTATION :
9389
- this.clientSocket.on("connect",doAllOnConnection);
9390
-
9480
+ WebsocketImplementation.implementationToUse.initClientSocket(this.clientSocket);
9391
9481
  if(!empty(this.onServerLostListeners)){
9392
- this.clientSocket.on("close",()=>{
9482
+ WebsocketImplementation.implementationToUse.initOnClose(()=>{
9393
9483
  foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
9394
9484
  });
9395
9485
  }
9396
-
9397
-
9398
- // Client ping handling :
9399
- // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
9400
- // PING-PONG :
9401
- this.receive("protocol",(message)=>{
9402
- if(message.type!=="ping") return;
9403
- self.send("protocol",{type:"pong"});
9404
- // // DBG
9405
- // lognow("DEBUG : CLIENT : Pong sent.");
9406
- });
9486
+ // // FOR THE SOCKETIO IMPLEMENTATION :
9487
+ // this.clientSocket.on("connect",doAllOnConnection);
9488
+ //
9489
+ // if(!empty(this.onServerLostListeners)){
9490
+ // this.clientSocket.on("close",()=>{
9491
+ // foreach(self.onServerLostListeners,l=>{l.execute(self.clientSocket);});
9492
+ // });
9493
+ // }
9494
+ //
9495
+ //
9496
+ // // Client ping handling :
9497
+ // // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
9498
+ // // PING-PONG :
9499
+ // this.receive("protocol",(message)=>{
9500
+ // if(message.type!=="ping") return;
9501
+ // self.send("protocol",{type:"pong"});
9502
+ // // // DBG
9503
+ // // lognow("DEBUG : CLIENT : Pong sent.");
9504
+ // });
9407
9505
  }
9408
9506
 
9409
9507
 
@@ -9449,7 +9547,6 @@ class ServerReceptionEntryPoint{
9449
9547
  // Channel information is stored in exchanged data :
9450
9548
  if(dataWrapped.channelName!==this.channelName) return;
9451
9549
 
9452
- // TODO : FIXME : Use one single interface !
9453
9550
  // Room information is stored in client socket object :
9454
9551
  const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
9455
9552
 
@@ -9534,11 +9631,13 @@ class NodeServerInstance{
9534
9631
  this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
9535
9632
 
9536
9633
  // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
9537
- if(WebsocketImplementation.useSocketIOImplementation){
9538
- const channelName=serverReceptionEntryPoint.channelName;
9539
- clientSocket.on(channelName, (eventOrMessage)=>{
9540
- serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
9541
- });
9634
+ // if(WebsocketImplementation.useSocketIOImplementation){
9635
+ if(WebsocketImplementation.implementationToUse){
9636
+ WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
9637
+ // const channelName=serverReceptionEntryPoint.channelName;
9638
+ // clientSocket.on(channelName, (eventOrMessage)=>{
9639
+ // serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
9640
+ // });
9542
9641
  }
9543
9642
 
9544
9643
  return this;
@@ -9556,10 +9655,14 @@ class NodeServerInstance{
9556
9655
  // DBG
9557
9656
  lognow("(SERVER) (server sends to all clients)");
9558
9657
 
9559
- // TODO : FIXME : Use one single interface !
9560
9658
  let serverClients;
9561
- if(!WebsocketImplementation.useSocketIOImplementation) serverClients=this.serverSocket.clients;
9562
- else serverClients=this.serverSocket.sockets.sockets;
9659
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9660
+ if(!WebsocketImplementation.implementationToUse){
9661
+ serverClients=this.serverSocket.clients;
9662
+ }else{
9663
+ WebsocketImplementation.implementationToUse.getServerClients();
9664
+ // serverClients=this.serverSocket.sockets.sockets;
9665
+ }
9563
9666
 
9564
9667
 
9565
9668
  serverClients.forEach((clientSocket)=>{
@@ -9579,9 +9682,13 @@ class NodeServerInstance{
9579
9682
  // (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
9580
9683
  dataWrapped=stringifyObject(dataWrapped);
9581
9684
 
9582
- // TODO : FIXME : Use one single interface !
9583
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
9584
- else clientSocket.emit(channelName, dataWrapped);
9685
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9686
+ if(!WebsocketImplementation.implementationToUse){
9687
+ clientSocket.send(dataWrapped);
9688
+ }else{
9689
+ WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
9690
+ // clientSocket.emit(channelName, dataWrapped);
9691
+ }
9585
9692
 
9586
9693
  });
9587
9694
 
@@ -9591,10 +9698,14 @@ class NodeServerInstance{
9591
9698
  lognow("(SERVER) (server sends to a client)");
9592
9699
 
9593
9700
 
9594
- // TODO : FIXME : Use one single interface !
9595
9701
  let clientSocket=clientSocketParam;
9596
- if(!WebsocketImplementation.useSocketIOImplementation) if(clientSocket.readyState!==WebSocket.OPEN) return;
9597
- else if(clientSocket.connected) return;
9702
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9703
+ if(!WebsocketImplementation.implementationToUse){
9704
+ if(clientSocket.readyState!==WebSocket.OPEN) return;
9705
+ }else{
9706
+ if(WebsocketImplementation.implementationToUse.isReady(clientSocket)) return;
9707
+ // if(clientSocket.connected) return;
9708
+ }
9598
9709
 
9599
9710
 
9600
9711
  // Room information is stored in client socket object :
@@ -9609,9 +9720,13 @@ class NodeServerInstance{
9609
9720
  dataWrapped=stringifyObject(dataWrapped);
9610
9721
 
9611
9722
 
9612
- // TODO : FIXME : Use one single interface !
9613
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
9614
- else clientSocket.emit(channelName,dataWrapped);
9723
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9724
+ if(!WebsocketImplementation.implementationToUse){
9725
+ clientSocket.send(dataWrapped);
9726
+ }else{
9727
+ WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrapped);
9728
+ // clientSocket.emit(channelName,dataWrapped);
9729
+ }
9615
9730
 
9616
9731
  }
9617
9732
 
@@ -9642,8 +9757,11 @@ class NodeServerInstance{
9642
9757
  });
9643
9758
  };
9644
9759
 
9645
- if(!WebsocketImplementation.useSocketIOImplementation){
9760
+ // if(!WebsocketImplementation.useSocketIOImplementation){
9761
+ if(!WebsocketImplementation.implementationToUse){
9646
9762
  clientSocket.addEventListener("message", doOnMessage);
9763
+ }else{
9764
+ WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
9647
9765
  }
9648
9766
 
9649
9767
  doOnConnection(this, clientSocket);
@@ -9651,7 +9769,6 @@ class NodeServerInstance{
9651
9769
 
9652
9770
  // DBG
9653
9771
  lognow("DEBUG : Starting ping-pong with client : clientSocket.clientId:",clientSocket.clientId);
9654
- lognow("DEBUG : WebsocketImplementation.useSocketIOImplementation:",WebsocketImplementation.useSocketIOImplementation);
9655
9772
  lognow("DEBUG : clientSocket.readyState:",clientSocket.readyState);
9656
9773
 
9657
9774
 
@@ -9667,9 +9784,13 @@ class NodeServerInstance{
9667
9784
 
9668
9785
  clientSocket.removeAllListeners();
9669
9786
 
9670
- // TODO : FIXME : Use one single interface !
9671
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.terminate();
9672
- else clientSocket.emit("endConnection");
9787
+ // if(!WebsocketImplementation.useSocketIOImplementation)
9788
+ if(!WebsocketImplementation.implementationToUse){
9789
+ clientSocket.terminate();
9790
+ }else{
9791
+ WebsocketImplementation.implementationToUse.terminate();
9792
+ // clientSocket.emit("endConnection");
9793
+ }
9673
9794
 
9674
9795
  if(!empty(self.onClientLostListeners))
9675
9796
  foreach(self.onClientLostListeners,l=>{l.execute(clientSocket);});
@@ -9687,12 +9808,14 @@ class NodeServerInstance{
9687
9808
 
9688
9809
  clientSocket.isConnectionAlive=false;
9689
9810
 
9690
- if(!WebsocketImplementation.useSocketIOImplementation){
9811
+ // if(!WebsocketImplementation.useSocketIOImplementation){
9812
+ if(!WebsocketImplementation.implementationToUse){
9691
9813
  // FOR THE WEBSOCKET IMPLEMENTATION :
9692
9814
  clientSocket.ping();
9693
9815
  }else{
9694
- // FOR THE SOCKETIO IMPLEMENTATION :
9695
- self.send("protocol",{type:"ping"}, null, clientSocket);
9816
+ WebsocketImplementation.implementationToUse.ping();
9817
+ // // FOR THE SOCKETIO IMPLEMENTATION :
9818
+ // self.send("protocol",{type:"ping"}, null, clientSocket);
9696
9819
  }
9697
9820
 
9698
9821
 
@@ -9700,18 +9823,21 @@ class NodeServerInstance{
9700
9823
 
9701
9824
 
9702
9825
  // PING-PONG :
9703
- if(!WebsocketImplementation.useSocketIOImplementation){
9826
+ // if(!WebsocketImplementation.useSocketIOImplementation){
9827
+ if(!WebsocketImplementation.implementationToUse){
9704
9828
  // FOR THE WEBSOCKET IMPLEMENTATION :
9705
9829
  clientSocket.on("pong",()=>{
9706
9830
  clientSocket.isConnectionAlive=true;
9707
9831
  });
9708
9832
  }else{
9709
- // FOR THE SOCKETIO IMPLEMENTATION :
9710
- this.receive("protocol",(message)=>{
9711
- if(message.type!=="pong") return;
9833
+ WebsocketImplementation.implementationToUse.doOnPong(()=>{
9712
9834
  clientSocket.isConnectionAlive=true;
9713
9835
  });
9714
-
9836
+ // // FOR THE SOCKETIO IMPLEMENTATION :
9837
+ // this.receive("protocol",(message)=>{
9838
+ // if(message.type!=="pong") return;
9839
+ // clientSocket.isConnectionAlive=true;
9840
+ // });
9715
9841
  }
9716
9842
 
9717
9843
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1887",
3
+ "version": "0.0.1890",
4
4
  "main": "aotrautils-srv.build.js",
5
5
  "description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",