aotrautils-srv 0.0.126 → 0.0.129

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:00:17)»*/
3
+ /*utils COMMONS library associated with aotra version : «1.0.0.000 (16/07/2022-16:26:34)»*/
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:00:17)»*/
4831
+ /*utils SERVER library associated with aotra version : «1.0.0.000 (16/07/2022-16:26:34)»*/
4832
4832
  /*-----------------------------------------------------------------------------*/
4833
4833
 
4834
4834
 
@@ -4872,17 +4872,11 @@ if(typeof(window)==="undefined") window=global;
4872
4872
  // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
4873
4873
 
4874
4874
  // We have to import both implementations, regardless of which one is chosen :
4875
- //const {Socket}=require("socket.io");
4876
- //const {WebSocket}=require("ws");
4877
- Socket=require("socket.io");
4878
- WebSocket=require("ws");
4875
+ //Socket=require("socket.io");
4876
+ //WebSocket=require("ws");
4879
4877
 
4880
4878
 
4881
4879
 
4882
- // DBG
4883
- console.log("Socket!!!!!!>>>>",Socket);
4884
- console.log("WebSocket!!!!!!>>>>",WebSocket);
4885
-
4886
4880
 
4887
4881
  // =================================================================================
4888
4882
  // NODEJS UTILS
@@ -5052,10 +5046,8 @@ if(typeof(fs)==="undefined"){
5052
5046
 
5053
5047
  // NODE ONLY SERVER / CLIENTS :
5054
5048
  WebsocketImplementation={
5055
-
5056
- // Socket:Socket,
5057
- // WebSocket:WebSocket,
5058
-
5049
+
5050
+
5059
5051
  isNodeContext:true,
5060
5052
  useSocketIOImplementation:false,
5061
5053
  useFlatStrings:false,
@@ -5072,32 +5064,52 @@ WebsocketImplementation={
5072
5064
  getStatic:(isNodeContext=true, useSocketIOImplementation=false)=>{
5073
5065
 
5074
5066
  WebsocketImplementation.isNodeContext=isNodeContext;
5075
-
5076
5067
  WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
5077
5068
 
5078
5069
  if(WebsocketImplementation.useSocketIOImplementation){
5079
5070
  // TRACE
5080
5071
  lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
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;
5083
+ }
5081
5084
 
5082
5085
  }else{
5083
5086
  // TRACE
5084
- lognow("INFO : (SERVER/CLIENT) Using native websocket implementation.");
5087
+ lognow("INFO : (SERVER/CLIENT) Using native WebSocket implementation.");
5088
+
5089
+ // 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;
5095
+ }
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
+ }
5085
5101
 
5086
5102
  }
5103
+
5087
5104
 
5088
5105
  // *********************************************************************************
5089
-
5090
- // DBG
5091
- console.log("11111 Socket:",Socket);
5092
- console.log("11111 WebSocket:",WebSocket);
5093
5106
 
5094
-
5095
5107
 
5096
5108
  return WebsocketImplementation;
5097
5109
  },
5098
5110
 
5099
5111
 
5100
- getServer:(listenableServer, port)=>{
5112
+ getServer:(listenableServer)=>{
5101
5113
 
5102
5114
  if(!WebsocketImplementation.isNodeContext){
5103
5115
  // TRACE
@@ -5113,10 +5125,6 @@ WebsocketImplementation={
5113
5125
  serverSocket=new WebSocket.Server({ "server":listenableServer });
5114
5126
  }else{
5115
5127
 
5116
-
5117
- // DBG
5118
- console.log(">>>>>>>Socket:",Socket);
5119
- console.log(">>>>>>>WebSocket:",WebSocket);
5120
5128
 
5121
5129
  // NOW : socket.io :
5122
5130
  // Loading socket.io
@@ -5128,8 +5136,6 @@ WebsocketImplementation={
5128
5136
  serverSocket.disconnect();
5129
5137
  });
5130
5138
 
5131
- // ////
5132
- serverSocket.listen(port);
5133
5139
 
5134
5140
  }
5135
5141
 
@@ -5593,7 +5599,9 @@ WebsocketImplementation={
5593
5599
  // }else{
5594
5600
  // // TRACE
5595
5601
  // console.log("ERROR : Could not initialize socket !");
5596
- clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
5602
+ // OLD SYNTAX :clientSocket=io.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
5603
+ clientSocket=Socket(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
5604
+
5597
5605
  }
5598
5606
 
5599
5607
 
@@ -5796,12 +5804,12 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, /
5796
5804
 
5797
5805
  let listenableServer;
5798
5806
  if(sslOptions){
5799
- let httpsServer=https.createServer(sslOptions, handler); // OLD : .listen(port);
5807
+ let httpsServer=https.createServer(sslOptions, handler).listen(port);
5800
5808
  // TRACE
5801
5809
  console.log("INFO : SERVER : HTTPS Server launched and listening on port " + port + "!");
5802
5810
  listenableServer=httpsServer;
5803
5811
  }else{
5804
- let httpServer=http.createServer(handler);// OLD : .listen(port);
5812
+ let httpServer=http.createServer(handler).listen(port);
5805
5813
  // TRACE
5806
5814
  console.log("INFO : SERVER : HTTP Server launched and listening on port " + port + "!");
5807
5815
  listenableServer=httpServer;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.126",
3
+ "version": "0.0.129",
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)",