aotrautils-srv 0.0.130 → 0.0.133

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.0.0.000 (16/07/2022-16:41:40)»*/
3
+ /*utils COMMONS library associated with aotra version : «1.0.0.000 (16/07/2022-17:08:50)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4828,7 +4828,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4828
4828
 
4829
4829
 
4830
4830
 
4831
- /*utils SERVER library associated with aotra version : «1.0.0.000 (16/07/2022-16:41:40)»*/
4831
+ /*utils SERVER library associated with aotra version : «1.0.0.000 (16/07/2022-17:08:50)»*/
4832
4832
  /*-----------------------------------------------------------------------------*/
4833
4833
 
4834
4834
 
@@ -5061,7 +5061,7 @@ WebsocketImplementation={
5061
5061
  //
5062
5062
  // NODE SERVER/CLIENT
5063
5063
  //
5064
- getStatic:(isNodeContext=true, useSocketIOImplementation=false)=>{
5064
+ getStatic:(isNodeContext=true, useSocketIOImplementation=/*DEBUG*/false)=>{
5065
5065
 
5066
5066
  WebsocketImplementation.isNodeContext=isNodeContext;
5067
5067
  WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
@@ -5070,16 +5070,18 @@ WebsocketImplementation={
5070
5070
  // TRACE
5071
5071
  lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
5072
5072
 
5073
- if(isNodeContext && typeof(Socket)==="undefined"){
5074
- // TRACE
5075
- console.log("«socket.io» SERVER library not called yet, calling it now.");
5076
- Socket=require("socket.io");
5077
- return WebsocketImplementation;
5078
- }
5079
- if(typeof(Socket)==="undefined"){
5080
- // TRACE
5081
- console.log("ERROR : «socket.io» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
5082
- return WebsocketImplementation;
5073
+ if(isNodeContext){
5074
+ if(typeof(Socket)==="undefined"){
5075
+ // TRACE
5076
+ console.log("«socket.io» SERVER library not called yet, calling it now.");
5077
+ Socket=require("socket.io");
5078
+ return WebsocketImplementation;
5079
+ }
5080
+ if(typeof(Socket)==="undefined"){
5081
+ // TRACE
5082
+ console.log("ERROR : «socket.io» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
5083
+ return WebsocketImplementation;
5084
+ }
5083
5085
  }
5084
5086
 
5085
5087
  }else{
@@ -5087,17 +5089,19 @@ WebsocketImplementation={
5087
5089
  lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
5088
5090
 
5089
5091
  // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
5090
- if(isNodeContext && typeof(WebSocket)==="undefined"){
5091
- WebSocket=require("ws");
5092
- // TRACE
5093
- console.log("«ws» SERVER library not called yet, calling it now.");
5094
- return WebsocketImplementation;
5092
+ if(isNodeContext){
5093
+ if(typeof(WebSocket)==="undefined"){
5094
+ WebSocket=require("ws");
5095
+ // TRACE
5096
+ console.log("«ws» SERVER library not called yet, calling it now.");
5097
+ return WebsocketImplementation;
5098
+ }
5099
+ if(typeof(WebSocket)==="undefined"){
5100
+ // TRACE
5101
+ console.log("ERROR : «ws» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
5102
+ return WebsocketImplementation;
5103
+ }
5095
5104
  }
5096
- if(typeof(WebSocket)==="undefined"){
5097
- // TRACE
5098
- console.log("ERROR : «ws» CONSOLE/BROWSER CLIENT/SERVER library not found. Cannot launch nodejs server. Aborting.");
5099
- return WebsocketImplementation;
5100
- }
5101
5105
 
5102
5106
  }
5103
5107
 
@@ -5319,7 +5323,10 @@ WebsocketImplementation={
5319
5323
 
5320
5324
  clientSocket.isAlive=false;
5321
5325
  try{
5322
- clientSocket.ping();
5326
+
5327
+ if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.ping();
5328
+ else clientSocket.emit("ping");
5329
+
5323
5330
  }catch(error){
5324
5331
  lognow("ERROR : A problem occurred when tried to ping client socket : ",error);
5325
5332
  // We effectively end the client connection to this server :
@@ -5338,9 +5345,16 @@ WebsocketImplementation={
5338
5345
 
5339
5346
 
5340
5347
  }, nodeServerInstance.clientTimeoutMillis);
5341
- clientSocket.on("pong",()=>{
5342
- clientSocket.isAlive=true;
5343
- });
5348
+
5349
+ if(!WebsocketImplementation.useSocketIOImplementation){
5350
+ clientSocket.on("pong",()=>{
5351
+ clientSocket.isAlive=true;
5352
+ });
5353
+ }else{
5354
+ clientSocket.on("ping",()=>{
5355
+ clientSocket.isAlive=true;
5356
+ });
5357
+ }
5344
5358
 
5345
5359
 
5346
5360
 
@@ -5816,7 +5830,7 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
5816
5830
  }
5817
5831
 
5818
5832
 
5819
- const server=WebsocketImplementation.getStatic(true, /*DEBUG*/true).getServer(listenableServer, port);
5833
+ const server=WebsocketImplementation.getStatic(true).getServer(listenableServer, port);
5820
5834
 
5821
5835
  // When a client connects, we execute the callback :
5822
5836
  // CAUTION : MUST BE CALLED ONLY ONCE !
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.130",
3
+ "version": "0.0.133",
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)",