aotrautils 0.0.1478 → 0.0.1480

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 (26/04/2025-16:16:42)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (27/04/2025-01:10:12)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4894,7 +4894,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4894
4894
 
4895
4895
 
4896
4896
 
4897
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (26/04/2025-16:16:42)»*/
4897
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (27/04/2025-01:10:12)»*/
4898
4898
  /*-----------------------------------------------------------------------------*/
4899
4899
  /* ## Utility global methods in a browser (htmljs) client environment.
4900
4900
  *
@@ -13466,7 +13466,7 @@ getAORTACClient=function(clientId=getUUID(), serverNodeOrigin="ws://127.0.0.1:40
13466
13466
 
13467
13467
 
13468
13468
 
13469
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (26/04/2025-16:16:42)»*/
13469
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (27/04/2025-01:10:12)»*/
13470
13470
  /*-----------------------------------------------------------------------------*/
13471
13471
 
13472
13472
 
@@ -14705,7 +14705,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
14705
14705
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14706
14706
 
14707
14707
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14708
- /*utils AI library associated with aotra version : «1_29072022-2359 (26/04/2025-16:16:42)»*/
14708
+ /*utils AI library associated with aotra version : «1_29072022-2359 (27/04/2025-01:10:12)»*/
14709
14709
  /*-----------------------------------------------------------------------------*/
14710
14710
 
14711
14711
 
@@ -14851,7 +14851,7 @@ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
14851
14851
 
14852
14852
 
14853
14853
 
14854
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (26/04/2025-16:16:42)»*/
14854
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (27/04/2025-01:10:12)»*/
14855
14855
  /*-----------------------------------------------------------------------------*/
14856
14856
 
14857
14857
 
@@ -15105,7 +15105,25 @@ WebsocketImplementation={
15105
15105
  WebsocketImplementation.isNodeContext=isNodeContext;
15106
15106
  WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
15107
15107
 
15108
- if(WebsocketImplementation.useSocketIOImplementation){
15108
+ if(!WebsocketImplementation.useSocketIOImplementation){
15109
+ // TRACE
15110
+ lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
15111
+
15112
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
15113
+ if(isNodeContext){
15114
+ if(typeof(WebSocket)==="undefined"){
15115
+ // TRACE
15116
+ console.log("«ws» SERVER library not called yet, calling it now.");
15117
+
15118
+ WebSocket=require("ws");
15119
+ if(typeof(WebSocket)==="undefined"){
15120
+ // TRACE
15121
+ console.log("ERROR : «ws» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
15122
+ }
15123
+ }
15124
+ }
15125
+
15126
+ }else{
15109
15127
  // TRACE
15110
15128
  lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
15111
15129
 
@@ -15138,23 +15156,6 @@ WebsocketImplementation={
15138
15156
  }
15139
15157
  }
15140
15158
 
15141
- }else{
15142
- // TRACE
15143
- lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
15144
-
15145
- // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
15146
- if(isNodeContext){
15147
- if(typeof(WebSocket)==="undefined"){
15148
- // TRACE
15149
- console.log("«ws» SERVER library not called yet, calling it now.");
15150
-
15151
- WebSocket=require("ws");
15152
- if(typeof(WebSocket)==="undefined"){
15153
- // TRACE
15154
- console.log("ERROR : «ws» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
15155
- }
15156
- }
15157
- }
15158
15159
 
15159
15160
  }
15160
15161
 
@@ -16929,6 +16930,48 @@ getAORTACNode=function(nodeId=getUUID(), selfOrigin="ws://127.0.0.1:40000", outc
16929
16930
 
16930
16931
  // ==================================================================================================================
16931
16932
 
16933
+ class ServerReceptionEntryPoint{
16934
+
16935
+ constructor(channelNameParam, clientsRoomsTag, doOnIncomingMessage){
16936
+ this.channelName=channelNameParam;
16937
+ this.clientsRoomsTag=clientsRoomsTag;
16938
+ this.doOnIncomingMessage=doOnIncomingMessage;
16939
+ }
16940
+
16941
+ execute(eventOrMessage, clientSocketParam){
16942
+
16943
+ // With «ws» library we have no choive than register message events inside a «connection» event !
16944
+
16945
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
16946
+
16947
+ // Channel information is stored in exchanged data :
16948
+ if(dataWrapped.channelName!==this.channelName) return;
16949
+
16950
+ // TODO : FIXME : Use one single interface !
16951
+ // Room information is stored in client socket object :
16952
+ const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
16953
+
16954
+ // DBG
16955
+ lognow("(SERVER) isClientInRoom:",isClientInRoom);
16956
+
16957
+ if(!isClientInRoom) return;
16958
+
16959
+ if(this.doOnIncomingMessage){
16960
+ // DBG
16961
+ lognow("(SERVER) this.doOnIncomingMessage:");
16962
+ this.doOnIncomingMessage(dataWrapped.data, clientSocketParam);
16963
+ }
16964
+
16965
+ }
16966
+ }
16967
+
16968
+
16969
+
16970
+
16971
+
16972
+
16973
+
16974
+
16932
16975
  class NodeServerInstance{
16933
16976
 
16934
16977
  constructor(serverSocket, listenableServer){
@@ -16938,7 +16981,7 @@ class NodeServerInstance{
16938
16981
  this.clientPingIntervalMillis=5000;
16939
16982
  this.serverSocket=serverSocket;
16940
16983
  this.listenableServer=listenableServer;
16941
- this.receptionEntryPoints=[];
16984
+ this.serverReceptionEntryPoints=[];
16942
16985
 
16943
16986
  }
16944
16987
 
@@ -16961,54 +17004,28 @@ class NodeServerInstance{
16961
17004
  // DBG
16962
17005
  lognow("(SERVER) Registering receive for «"+channelNameParam+"»...");
16963
17006
 
16964
-
16965
- const receptionEntryPoint={
16966
- channelName:channelNameParam,
16967
- clientsRoomsTag:clientsRoomsTag,
16968
- execute:(eventOrMessage, clientSocketParam)=>{
16969
-
16970
- // With «ws» library we have no choive than register message events inside a «connection» event !
16971
-
16972
- const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
16973
-
16974
- // Channel information is stored in exchanged data :
16975
- if(dataWrapped.channelName!==receptionEntryPoint.channelName) return;
16976
-
16977
-
16978
- // TODO : FIXME : Use one single interface !
16979
- // Room information is stored in client socket object :
16980
- const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, receptionEntryPoint.clientsRoomsTag);
16981
-
16982
- // DBG
16983
- lognow("(SERVER) isClientInRoom:",isClientInRoom);
16984
-
16985
- if(!isClientInRoom) return;
16986
-
16987
- if(doOnIncomingMessage){
16988
- // DBG
16989
- lognow("(SERVER) doOnIncomingMessage:");
16990
- doOnIncomingMessage(dataWrapped.data, clientSocketParam);
16991
- }
16992
-
16993
- },
16994
- };
16995
-
17007
+ const serverReceptionEntryPoint=new ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, doOnIncomingMessage);
16996
17008
 
16997
17009
  ///!!!
16998
- self.receptionEntryPoints.push(receptionEntryPoint);
17010
+ this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
16999
17011
 
17000
17012
  // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
17001
17013
  if(WebsocketImplementation.useSocketIOImplementation){
17002
- const channelName=receptionEntryPoint.channelName;
17014
+ const channelName=serverReceptionEntryPoint.channelName;
17003
17015
  clientSocket.on(channelName, (eventOrMessage)=>{
17004
- receptionEntryPoint.execute(eventOrMessage, clientSocket);
17016
+ serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
17005
17017
  });
17006
17018
  }
17007
17019
 
17008
17020
  return this;
17009
17021
  }
17010
-
17011
-
17022
+
17023
+
17024
+ // TODO : DEVELOP...
17025
+ //sendChainable(channelNameParam, data, clientsRoomsTag=null){
17026
+ //}
17027
+
17028
+
17012
17029
  send(channelName, data, clientsRoomsTag=null, clientSocketParam=null){
17013
17030
 
17014
17031
  // DBG
@@ -17100,13 +17117,14 @@ class NodeServerInstance{
17100
17117
 
17101
17118
  const doOnMessage=(eventOrMessage)=>{
17102
17119
  // We execute the events registration listeners entry points:
17103
- foreach(self.receptionEntryPoints,(receptionEntryPoint,i)=>{
17104
- receptionEntryPoint.execute(eventOrMessage, clientSocket);
17120
+ foreach(self.serverReceptionEntryPoints,(serverReceptionEntryPoint,i)=>{
17121
+ serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
17105
17122
  });
17106
17123
  };
17107
17124
 
17108
- if(!WebsocketImplementation.useSocketIOImplementation)
17125
+ if(!WebsocketImplementation.useSocketIOImplementation){
17109
17126
  clientSocket.addEventListener("message", doOnMessage);
17127
+ }
17110
17128
 
17111
17129
  doOnConnection(this, clientSocket);
17112
17130
 
@@ -17146,19 +17164,26 @@ class NodeServerInstance{
17146
17164
 
17147
17165
  clientSocket.isConnectionAlive=false;
17148
17166
 
17149
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.ping();
17150
- else self.send("protocol",{type:"ping"}, null, clientSocket);
17167
+ if(!WebsocketImplementation.useSocketIOImplementation){
17168
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17169
+ clientSocket.ping();
17170
+ }else{
17171
+ // FOR THE SOCKETIO IMPLEMENTATION :
17172
+ self.send("protocol",{type:"ping"}, null, clientSocket);
17173
+ }
17151
17174
 
17152
17175
 
17153
17176
  }, this.clientPingIntervalMillis);
17154
17177
 
17155
-
17178
+
17179
+ // PING-PONG :
17156
17180
  if(!WebsocketImplementation.useSocketIOImplementation){
17181
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17157
17182
  clientSocket.on("pong",()=>{
17158
17183
  clientSocket.isConnectionAlive=true;
17159
17184
  });
17160
17185
  }else{
17161
-
17186
+ // FOR THE SOCKETIO IMPLEMENTATION :
17162
17187
  this.receive("protocol",(message)=>{
17163
17188
  if(message.type!=="pong") return;
17164
17189
  clientSocket.isConnectionAlive=true;
@@ -17221,6 +17246,47 @@ if(typeof(window)==="undefined") window=global;
17221
17246
 
17222
17247
  // ==================================================================================================================
17223
17248
 
17249
+
17250
+ class ClientReceptionEntryPoint{
17251
+
17252
+ constructor(channelNameParam, entryPointId, clientsRoomsTag, listenerConfig, doOnIncomingMessage){
17253
+ this.channelName=channelNameParam;
17254
+ this.entryPointId=entryPointId;
17255
+ this.clientsRoomsTag=clientsRoomsTag;
17256
+ this.listenerConfig=listenerConfig;
17257
+ this.doOnIncomingMessage=doOnIncomingMessage;
17258
+ }
17259
+
17260
+ execute(eventOrMessage, clientSocket, clientReceptionEntryPoints){
17261
+
17262
+ const channelName=this.channelName;
17263
+
17264
+
17265
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
17266
+
17267
+ // Channel information is stored in exchanged data :
17268
+ if(dataWrapped.channelName && dataWrapped.channelName!==this.channelName) return;
17269
+
17270
+ // Room information is stored in client socket object :
17271
+ if(!WebsocketImplementation.isInRoom(clientSocket, this.clientsRoomsTag)) return;
17272
+
17273
+
17274
+ if( this.listenerConfig && this.listenerConfig.messageType && dataWrapped.type
17275
+ && this.listenerConfig.messageType===dataWrapped.type) return;
17276
+
17277
+ // We remove one-time usage listeners :
17278
+ // We remove BEFORE executing doOnIncomingMessage(), because in this reception entry point function we can have other listener registration UNDER THE SAME ID !
17279
+ if(this.listenerConfig && this.listenerConfig.destroyListenerAfterReceiving)
17280
+ remove(this, clientReceptionEntryPoints);
17281
+
17282
+ if(this.doOnIncomingMessage)
17283
+ this.doOnIncomingMessage(dataWrapped.data, clientSocket);
17284
+
17285
+ }
17286
+
17287
+ }
17288
+
17289
+
17224
17290
  //
17225
17291
  // CLIENT INSTANCE :
17226
17292
  //
@@ -17228,59 +17294,33 @@ class ClientInstance{
17228
17294
 
17229
17295
  constructor(clientSocket){
17230
17296
  this.clientSocket=clientSocket;
17231
- this.receptionEntryPoints=[];
17297
+ this.clientReceptionEntryPoints=[];
17232
17298
 
17233
17299
  }
17234
17300
 
17235
- receive(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null, receptionEntryPointId=null, listenerConfig={destroyListenerAfterReceiving:false}){
17301
+ receive(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null, entryPointId=null, listenerConfig={destroyListenerAfterReceiving:false}){
17236
17302
  const self=this;
17237
17303
 
17238
17304
  // DBG
17239
- lognow("INFO : (CLIENT-BROWSER) SETTING UP RECEIVE for :",channelNameParam);
17240
-
17241
- const receptionEntryPoint={
17242
- channelName:channelNameParam,
17243
- clientsRoomsTag:clientsRoomsTag,
17244
- // TODO : ADD TO ALL OTHER SUBSYSTEMS !
17245
- id:receptionEntryPointId,
17246
- listenerConfig:listenerConfig,
17247
- doOnIncomingMessage:doOnIncomingMessage,
17248
- execute:(eventOrMessage)=>{
17249
-
17250
- const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
17251
-
17252
- // Channel information is stored in exchanged data :
17253
- if(dataWrapped.channelName && dataWrapped.channelName!==receptionEntryPoint.channelName) return;
17254
-
17255
- // Room information is stored in client socket object :
17256
- const clientSocket=self.clientSocket;
17257
- if(!WebsocketImplementation.isInRoom(clientSocket, receptionEntryPoint.clientsRoomsTag)) return;
17258
-
17259
- // We remove one-time usage listeners :
17260
- // We remove BEFORE executing doOnIncomingMessage(), because in receptionEntryPoint function we can have other listener registration UNDER THE SAME ID !
17261
- if(receptionEntryPoint.listenerConfig && receptionEntryPoint.listenerConfig.destroyListenerAfterReceiving)
17262
- remove(self.receptionEntryPoints, receptionEntryPoint);
17263
-
17264
- if(receptionEntryPoint.doOnIncomingMessage)
17265
- receptionEntryPoint.doOnIncomingMessage(dataWrapped.data, clientSocket);
17266
-
17267
- }
17268
- };
17269
-
17270
- ///!!!
17271
- // TODO : ADD TO ALL OTHER SUBSYSTEMS !
17272
- if(!contains.filter((l)=>(l.id && receptionEntryPoint.id && l.id===receptionEntryPoint.id))(this.receptionEntryPoints))
17273
- this.receptionEntryPoints.push(receptionEntryPoint);
17305
+ lognow("INFO : (CLIENT) SETTING UP RECEIVE for :",channelNameParam);
17274
17306
 
17275
- // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
17276
- if(WebsocketImplementation.useSocketIOImplementation){
17277
- const channelName=receptionEntryPoint.channelName;
17278
- clientSocket.on(channelName, (eventOrMessage)=>{
17279
- receptionEntryPoint.execute(eventOrMessage, clientSocket);
17307
+ const clientReceptionEntryPoint=new ClientReceptionEntryPoint(channelNameParam, entryPointId, clientsRoomsTag, listenerConfig, doOnIncomingMessage);
17308
+ if(!contains.filter((l)=>(
17309
+ l.entryPointId && clientReceptionEntryPoint.entryPointId
17310
+ && l.entryPointId===clientReceptionEntryPoint.entryPointId
17311
+ ))(this.clientReceptionEntryPoints)){
17312
+
17313
+ this.clientReceptionEntryPoints.push(clientReceptionEntryPoint);
17314
+ }
17315
+
17316
+ const clientSocket=this.clientSocket;
17317
+ if(WebsocketImplementation.useSocketIOImplementation){
17318
+ // FOR THE SOCKETIO IMPLEMENTATION :
17319
+ clientSocket.on(channelNameParam, (eventOrMessage)=>{
17320
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, clientReceptionEntryPoint);
17280
17321
  });
17281
17322
  }
17282
-
17283
-
17323
+
17284
17324
  return this;
17285
17325
  }
17286
17326
 
@@ -17316,6 +17356,7 @@ class ClientInstance{
17316
17356
  }
17317
17357
 
17318
17358
  doOnIncomingMessageForResponse(dataLocal, clientSocket);
17359
+
17319
17360
  }, resultPromise.clientsRoomsTag, listenerId, {destroyListenerAfterReceiving:true});
17320
17361
  //
17321
17362
 
@@ -17378,39 +17419,40 @@ class ClientInstance{
17378
17419
  // DBG
17379
17420
  lognow("DEBUG : CLIENT : doOnConnection !");
17380
17421
 
17381
- const doOnMessage=(eventOrMessage)=>{
17382
-
17383
- // We execute the listeners entry points registration :
17384
- foreach(self.receptionEntryPoints,(receptionEntryPoint)=>{
17385
- receptionEntryPoint.execute(eventOrMessage);
17386
- });
17387
-
17388
- };
17389
-
17390
17422
  const clientSocket=self.clientSocket;
17391
- if(!WebsocketImplementation.useSocketIOImplementation){ clientSocket.addEventListener("message", doOnMessage);
17423
+ if(!WebsocketImplementation.useSocketIOImplementation){
17424
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17425
+ clientSocket.addEventListener("message", (eventOrMessage)=>{
17426
+ foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
17427
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
17428
+ });
17429
+ });
17392
17430
  }
17393
17431
 
17394
17432
  doOnConnection(self, clientSocket);
17395
-
17396
17433
  };
17397
17434
 
17398
- if(!WebsocketImplementation.useSocketIOImplementation) this.clientSocket.addEventListener("open",doAllOnConnection);
17399
- else this.clientSocket.on("connect",doAllOnConnection);
17400
-
17401
17435
 
17402
- // Client ping handling : (SocketIO implementation only)
17403
- if(WebsocketImplementation.useSocketIOImplementation){
17436
+ if(!WebsocketImplementation.useSocketIOImplementation){
17437
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17438
+ this.clientSocket.addEventListener("open",doAllOnConnection);
17439
+ }else{
17440
+ // FOR THE SOCKETIO IMPLEMENTATION :
17441
+ this.clientSocket.on("connect",doAllOnConnection);
17442
+
17443
+ // Client ping handling :
17444
+ // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
17445
+ // PING-PONG :
17404
17446
  this.receive("protocol",(message)=>{
17405
17447
  if(message.type!=="ping") return;
17406
17448
  self.send("protocol",{type:"pong"});
17407
-
17408
- // DBG
17409
- lognow("DEBUG : CLIENT : Pong sent.");
17449
+ // // DBG
17450
+ // lognow("DEBUG : CLIENT : Pong sent.");
17410
17451
  });
17411
17452
  }
17412
17453
 
17413
17454
 
17455
+
17414
17456
  }
17415
17457
 
17416
17458
  }
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1478",
3
+ "version": "0.0.1480",
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)",