aotrautils 0.0.1477 → 0.0.1479

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:15:49)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (27/04/2025-01:02:00)»*/
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:15:49)»*/
4897
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (27/04/2025-01:02:00)»*/
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:15:49)»*/
13469
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (27/04/2025-01:02:00)»*/
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:15:49)»*/
14708
+ /*utils AI library associated with aotra version : «1_29072022-2359 (27/04/2025-01:02:00)»*/
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:15:49)»*/
14854
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (27/04/2025-01:02:00)»*/
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,47 @@ 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){
16936
+ this.channelName=channelNameParam;
16937
+ this.clientsRoomsTag=clientsRoomsTag;
16938
+ }
16939
+
16940
+ execute(eventOrMessage, clientSocketParam){
16941
+
16942
+ // With «ws» library we have no choive than register message events inside a «connection» event !
16943
+
16944
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
16945
+
16946
+ // Channel information is stored in exchanged data :
16947
+ if(dataWrapped.channelName!==this.channelName) return;
16948
+
16949
+ // TODO : FIXME : Use one single interface !
16950
+ // Room information is stored in client socket object :
16951
+ const isClientInRoom=WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
16952
+
16953
+ // DBG
16954
+ lognow("(SERVER) isClientInRoom:",isClientInRoom);
16955
+
16956
+ if(!isClientInRoom) return;
16957
+
16958
+ if(doOnIncomingMessage){
16959
+ // DBG
16960
+ lognow("(SERVER) doOnIncomingMessage:");
16961
+ doOnIncomingMessage(dataWrapped.data, clientSocketParam);
16962
+ }
16963
+
16964
+ }
16965
+ }
16966
+
16967
+
16968
+
16969
+
16970
+
16971
+
16972
+
16973
+
16932
16974
  class NodeServerInstance{
16933
16975
 
16934
16976
  constructor(serverSocket, listenableServer){
@@ -16938,7 +16980,7 @@ class NodeServerInstance{
16938
16980
  this.clientPingIntervalMillis=5000;
16939
16981
  this.serverSocket=serverSocket;
16940
16982
  this.listenableServer=listenableServer;
16941
- this.receptionEntryPoints=[];
16983
+ this.serverReceptionEntryPoints=[];
16942
16984
 
16943
16985
  }
16944
16986
 
@@ -16961,47 +17003,16 @@ class NodeServerInstance{
16961
17003
  // DBG
16962
17004
  lognow("(SERVER) Registering receive for «"+channelNameParam+"»...");
16963
17005
 
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
-
17006
+ const serverReceptionEntryPoint=new ServerReceptionEntryPoint(channelNameParam,clientsRoomsTag);
16996
17007
 
16997
17008
  ///!!!
16998
- self.receptionEntryPoints.push(receptionEntryPoint);
17009
+ this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
16999
17010
 
17000
17011
  // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
17001
17012
  if(WebsocketImplementation.useSocketIOImplementation){
17002
- const channelName=receptionEntryPoint.channelName;
17013
+ const channelName=serverReceptionEntryPoint.channelName;
17003
17014
  clientSocket.on(channelName, (eventOrMessage)=>{
17004
- receptionEntryPoint.execute(eventOrMessage, clientSocket);
17015
+ serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
17005
17016
  });
17006
17017
  }
17007
17018
 
@@ -17100,13 +17111,14 @@ class NodeServerInstance{
17100
17111
 
17101
17112
  const doOnMessage=(eventOrMessage)=>{
17102
17113
  // We execute the events registration listeners entry points:
17103
- foreach(self.receptionEntryPoints,(receptionEntryPoint,i)=>{
17104
- receptionEntryPoint.execute(eventOrMessage, clientSocket);
17114
+ foreach(self.serverReceptionEntryPoints,(serverReceptionEntryPoint,i)=>{
17115
+ serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
17105
17116
  });
17106
17117
  };
17107
17118
 
17108
- if(!WebsocketImplementation.useSocketIOImplementation)
17119
+ if(!WebsocketImplementation.useSocketIOImplementation){
17109
17120
  clientSocket.addEventListener("message", doOnMessage);
17121
+ }
17110
17122
 
17111
17123
  doOnConnection(this, clientSocket);
17112
17124
 
@@ -17146,19 +17158,26 @@ class NodeServerInstance{
17146
17158
 
17147
17159
  clientSocket.isConnectionAlive=false;
17148
17160
 
17149
- if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.ping();
17150
- else self.send("protocol",{type:"ping"}, null, clientSocket);
17161
+ if(!WebsocketImplementation.useSocketIOImplementation){
17162
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17163
+ clientSocket.ping();
17164
+ }else{
17165
+ // FOR THE SOCKETIO IMPLEMENTATION :
17166
+ self.send("protocol",{type:"ping"}, null, clientSocket);
17167
+ }
17151
17168
 
17152
17169
 
17153
17170
  }, this.clientPingIntervalMillis);
17154
17171
 
17155
-
17172
+
17173
+ // PING-PONG :
17156
17174
  if(!WebsocketImplementation.useSocketIOImplementation){
17175
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17157
17176
  clientSocket.on("pong",()=>{
17158
17177
  clientSocket.isConnectionAlive=true;
17159
17178
  });
17160
17179
  }else{
17161
-
17180
+ // FOR THE SOCKETIO IMPLEMENTATION :
17162
17181
  this.receive("protocol",(message)=>{
17163
17182
  if(message.type!=="pong") return;
17164
17183
  clientSocket.isConnectionAlive=true;
@@ -17221,6 +17240,48 @@ if(typeof(window)==="undefined") window=global;
17221
17240
 
17222
17241
  // ==================================================================================================================
17223
17242
 
17243
+
17244
+ class ClientReceptionEntryPoint{
17245
+
17246
+ constructor(channelNameParam, entryPointId, clientsRoomsTag, listenerConfig, doOnIncomingMessage){
17247
+
17248
+ this.channelName=channelNameParam;
17249
+ this.entryPointId=entryPointId;
17250
+ this.clientsRoomsTag=clientsRoomsTag;
17251
+ this.listenerConfig=listenerConfig;
17252
+ this.doOnIncomingMessage=doOnIncomingMessage;
17253
+ }
17254
+
17255
+ execute(eventOrMessage, clientSocket, clientReceptionEntryPoints){
17256
+
17257
+ const channelName=this.channelName;
17258
+
17259
+
17260
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
17261
+
17262
+ // Channel information is stored in exchanged data :
17263
+ if(dataWrapped.channelName && dataWrapped.channelName!==this.channelName) return;
17264
+
17265
+ // Room information is stored in client socket object :
17266
+ if(!WebsocketImplementation.isInRoom(clientSocket, this.clientsRoomsTag)) return;
17267
+
17268
+
17269
+ if( this.listenerConfig && this.listenerConfig.messageType && dataWrapped.type
17270
+ && this.listenerConfig.messageType===dataWrapped.type) return;
17271
+
17272
+ // We remove one-time usage listeners :
17273
+ // We remove BEFORE executing doOnIncomingMessage(), because in this reception entry point function we can have other listener registration UNDER THE SAME ID !
17274
+ if(this.listenerConfig && this.listenerConfig.destroyListenerAfterReceiving)
17275
+ remove(this, clientReceptionEntryPoints);
17276
+
17277
+ if(this.doOnIncomingMessage)
17278
+ this.doOnIncomingMessage(dataWrapped.data, clientSocket);
17279
+
17280
+ }
17281
+
17282
+ }
17283
+
17284
+
17224
17285
  //
17225
17286
  // CLIENT INSTANCE :
17226
17287
  //
@@ -17228,64 +17289,36 @@ class ClientInstance{
17228
17289
 
17229
17290
  constructor(clientSocket){
17230
17291
  this.clientSocket=clientSocket;
17231
- this.receptionEntryPoints=[];
17292
+ this.clientReceptionEntryPoints=[];
17232
17293
 
17233
17294
  }
17234
17295
 
17235
- receive(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null, receptionEntryPointId=null, listenerConfig={destroyListenerAfterReceiving:false}){
17296
+ receive(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null, entryPointId=null, listenerConfig={destroyListenerAfterReceiving:false}){
17236
17297
  const self=this;
17237
17298
 
17238
17299
  // 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);
17300
+ lognow("INFO : (CLIENT) SETTING UP RECEIVE for :",channelNameParam);
17274
17301
 
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);
17302
+ const clientReceptionEntryPoint=new ClientReceptionEntryPoint(channelNameParam, entryPointId, clientsRoomsTag, listenerConfig, doOnIncomingMessage);
17303
+ if(!contains.filter((l)=>(
17304
+ l.entryPointId && clientReceptionEntryPoint.entryPointId
17305
+ && l.entryPointId===clientReceptionEntryPoint.entryPointId
17306
+ ))(this.clientReceptionEntryPoints)){
17307
+
17308
+ this.clientReceptionEntryPoints.push(clientReceptionEntryPoint);
17309
+ }
17310
+
17311
+ const clientSocket=this.clientSocket;
17312
+ if(WebsocketImplementation.useSocketIOImplementation){
17313
+ // FOR THE SOCKETIO IMPLEMENTATION :
17314
+ clientSocket.on(channelNameParam, (eventOrMessage)=>{
17315
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, clientReceptionEntryPoint);
17280
17316
  });
17281
17317
  }
17282
-
17283
-
17318
+
17284
17319
  return this;
17285
17320
  }
17286
17321
 
17287
-
17288
- // TODO : FIXME : DUPLICATED CODE !
17289
17322
  sendChainable(channelNameParam, data, clientsRoomsTag=null){
17290
17323
  const self=this;
17291
17324
 
@@ -17318,6 +17351,7 @@ class ClientInstance{
17318
17351
  }
17319
17352
 
17320
17353
  doOnIncomingMessageForResponse(dataLocal, clientSocket);
17354
+
17321
17355
  }, resultPromise.clientsRoomsTag, listenerId, {destroyListenerAfterReceiving:true});
17322
17356
  //
17323
17357
 
@@ -17380,39 +17414,40 @@ class ClientInstance{
17380
17414
  // DBG
17381
17415
  lognow("DEBUG : CLIENT : doOnConnection !");
17382
17416
 
17383
- const doOnMessage=(eventOrMessage)=>{
17384
-
17385
- // We execute the listeners entry points registration :
17386
- foreach(self.receptionEntryPoints,(receptionEntryPoint)=>{
17387
- receptionEntryPoint.execute(eventOrMessage);
17388
- });
17389
-
17390
- };
17391
-
17392
17417
  const clientSocket=self.clientSocket;
17393
- if(!WebsocketImplementation.useSocketIOImplementation){ clientSocket.addEventListener("message", doOnMessage);
17418
+ if(!WebsocketImplementation.useSocketIOImplementation){
17419
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17420
+ clientSocket.addEventListener("message", (eventOrMessage)=>{
17421
+ foreach(self.clientReceptionEntryPoints,(clientReceptionEntryPoint)=>{
17422
+ clientReceptionEntryPoint.execute(eventOrMessage, clientSocket, self.clientReceptionEntryPoints);
17423
+ });
17424
+ });
17394
17425
  }
17395
17426
 
17396
17427
  doOnConnection(self, clientSocket);
17397
-
17398
17428
  };
17399
17429
 
17400
- if(!WebsocketImplementation.useSocketIOImplementation) this.clientSocket.addEventListener("open",doAllOnConnection);
17401
- else this.clientSocket.on("connect",doAllOnConnection);
17402
-
17403
17430
 
17404
- // Client ping handling : (SocketIO implementation only)
17405
- if(WebsocketImplementation.useSocketIOImplementation){
17431
+ if(!WebsocketImplementation.useSocketIOImplementation){
17432
+ // FOR THE WEBSOCKET IMPLEMENTATION :
17433
+ this.clientSocket.addEventListener("open",doAllOnConnection);
17434
+ }else{
17435
+ // FOR THE SOCKETIO IMPLEMENTATION :
17436
+ this.clientSocket.on("connect",doAllOnConnection);
17437
+
17438
+ // Client ping handling :
17439
+ // (SocketIO implementation only, the websocket implementation sends back a hidden pong !)
17440
+ // PING-PONG :
17406
17441
  this.receive("protocol",(message)=>{
17407
17442
  if(message.type!=="ping") return;
17408
17443
  self.send("protocol",{type:"pong"});
17409
-
17410
- // DBG
17411
- lognow("DEBUG : CLIENT : Pong sent.");
17444
+ // // DBG
17445
+ // lognow("DEBUG : CLIENT : Pong sent.");
17412
17446
  });
17413
17447
  }
17414
17448
 
17415
17449
 
17450
+
17416
17451
  }
17417
17452
 
17418
17453
  }
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1477",
3
+ "version": "0.0.1479",
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)",