aotrautils-srv 0.0.76 → 0.0.77

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 SERVER library associated with aotra version : «1.0.0.000 (13/07/2022-02:25:54)»*/
3
+ /*utils SERVER library associated with aotra version : «1.0.0.000 (13/07/2022-09:28:37)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -30,6 +30,45 @@ if(typeof(window)==="undefined") window=global;
30
30
 
31
31
 
32
32
 
33
+ // OLD : socket.io :
34
+ // https://stackoverflow.com/questions/31156884/how-to-use-https-on-node-js-using-express-socket-io
35
+ // https://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl
36
+ // https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
37
+
38
+ if(typeof(socketIO)==="undefined"){
39
+ // TRACE
40
+ lognow("«socket.io» SERVER library not called yet, calling it now.");
41
+ socketIO=require("socket.io");
42
+ // TRACE
43
+ lognow("«socket.io» SERVER library called:",socketIO);
44
+
45
+ }
46
+ if(typeof(socketIO)==="undefined"){
47
+ // Exception
48
+ lognow("ERROR : «socket.io» SERVER library not found. Cannot launch nodejs server. Aborting.");
49
+ }
50
+
51
+ // NEW : ws :
52
+ // https://github.com/websockets/ws#installing
53
+ // https://github.com/websockets/ws/blob/master/doc/ws.md#event-message
54
+ // ON BROWSER SIDE : Native Websockets :
55
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
56
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
57
+ if(typeof(WebSocket)==="undefined"){
58
+ WebSocket=require("ws");
59
+ // TRACE
60
+ console.log("«ws» SERVER library not called yet, calling it now.");
61
+ }
62
+ if(typeof(WebSocket)==="undefined"){
63
+ // TRACE
64
+ console.log("ERROR : «ws» SERVER library not found. Cannot launch nodejs server. Aborting.");
65
+ }
66
+
67
+
68
+
69
+
70
+
71
+
33
72
  // =================================================================================
34
73
  // NODEJS UTILS
35
74
 
@@ -216,32 +255,16 @@ WebsocketImplementation={
216
255
 
217
256
  WebsocketImplementation.isNodeContext=isNodeContext;
218
257
 
258
+ //const globalContext=(WebsocketImplementation.isNodeContext?global:window);
259
+
260
+
219
261
  // cf. https://socket.io/docs/v4/client-socket-instance/
220
262
  WebsocketImplementation.useSocketIOImplementation=useSocketIOImplementation;
221
263
 
222
264
  if(WebsocketImplementation.useSocketIOImplementation){
223
-
224
265
  // TRACE
225
266
  lognow("INFO : (SERVER/CLIENT) Using socket.io websocket implementation.");
226
267
 
227
- // OLD : socket.io :
228
- // https://stackoverflow.com/questions/31156884/how-to-use-https-on-node-js-using-express-socket-io
229
- // https://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl
230
- // https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
231
-
232
- const globalContext=(WebsocketImplementation.isNodeContext?global:window);
233
- if(typeof(globalContext.socketIO)==="undefined"){
234
- // TRACE
235
- lognow("«socket.io» SERVER library not called yet, calling it now.");
236
- globalContext.socketIO=require("socket.io");
237
- // TRACE
238
- lognow("«socket.io» SERVER library called:",globalContext.socketIO);
239
-
240
- }
241
- if(typeof(globalContext.socketIO)==="undefined"){
242
- // Exception
243
- throw "ERROR : «socket.io» SERVER library not found. Cannot launch nodejs server. Aborting.";
244
- }
245
268
  }else{
246
269
  // TRACE
247
270
  lognow("INFO : (SERVER/CLIENT) Using native websocket implementation.");
@@ -250,23 +273,7 @@ WebsocketImplementation={
250
273
 
251
274
  // *********************************************************************************
252
275
 
253
- // NEW : ws :
254
- // https://github.com/websockets/ws#installing
255
- // https://github.com/websockets/ws/blob/master/doc/ws.md#event-message
256
- // ON BROWSER SIDE : Native Websockets :
257
- // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
258
- // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications
259
- if(typeof(WebSocket)==="undefined"){
260
- WebSocket=require("ws");
261
- // TRACE
262
- console.log("«ws» SERVER library not called yet, calling it now.");
263
- return WebsocketImplementation;
264
- }
265
- if(typeof(WebSocket)==="undefined"){
266
- // TRACE
267
- console.log("ERROR : «ws» SERVER library not found. Cannot launch nodejs server. Aborting.");
268
- return null;
269
- }
276
+
270
277
 
271
278
  return WebsocketImplementation;
272
279
  },
@@ -286,14 +293,13 @@ WebsocketImplementation={
286
293
  serverSocket=new WebSocket.Server({ "server":listenableServer });
287
294
  }else{
288
295
 
289
- const globalContext=(WebsocketImplementation.isNodeContext?global:window);
290
296
 
291
297
  // DBG
292
- console.log(">>>>>>>socketIO:",JSON.stringify(globalContext.socketIO));
298
+ console.log(">>>>>>>socketIO:",JSON.stringify(socketIO));
293
299
 
294
300
  // NOW : socket.io :
295
301
  // Loading socket.io
296
- serverSocket=globalContext.socketIO.listen(listenableServer);
302
+ serverSocket=socketIO.listen(listenableServer);
297
303
 
298
304
  // Setting up the disctonnect event :
299
305
  serverSocket.on("endConnection",()=>{
@@ -596,14 +602,13 @@ WebsocketImplementation={
596
602
  // NOW : socket.io :
597
603
  //client on server-side:
598
604
 
599
- const globalContext=(WebsocketImplementation.isNodeContext?global:window);
600
605
 
601
- if(WebsocketImplementation.isNodeContext && typeof(globalContext.socketIO)!=="undefined"){
606
+ if(WebsocketImplementation.isNodeContext && typeof(socketIO)!=="undefined"){
602
607
  // // Node client :
603
608
  // connectToServer=function (serverURL, port, isSecure, timeout=10000){
604
609
  // return socketIO.connect(serverURL + ":" + port,{timeout: timeout});
605
610
  // }
606
- clientSocket=globalContext.socketIO.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
611
+ clientSocket=socketIO.connect(serverURL + ":" + port,{timeout: timeout, secure: isSecure});
607
612
  }
608
613
  }
609
614
 
@@ -1322,7 +1327,7 @@ function getListManager(config){
1322
1327
 
1323
1328
 
1324
1329
 
1325
- /*utils COMMONS library associated with aotra version : «1.0.0.000 (13/07/2022-02:25:54)»*/
1330
+ /*utils COMMONS library associated with aotra version : «1.0.0.000 (13/07/2022-09:28:37)»*/
1326
1331
  /*-----------------------------------------------------------------------------*/
1327
1332
 
1328
1333
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.76",
3
+ "version": "0.0.77",
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)",