aotrautils-srv 0.0.168 → 0.0.171

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 (17/07/2022-14:25:57)»*/
3
+ /*utils COMMONS library associated with aotra version : «1.0.0.000 (17/07/2022-14:49:17)»*/
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 (17/07/2022-14:25:57)»*/
4831
+ /*utils SERVER library associated with aotra version : «1.0.0.000 (17/07/2022-14:49:17)»*/
4832
4832
  /*-----------------------------------------------------------------------------*/
4833
4833
 
4834
4834
 
@@ -5113,6 +5113,28 @@ WebsocketImplementation={
5113
5113
  },
5114
5114
 
5115
5115
 
5116
+ /*private*/getMessageDataBothImplementations:(eventOrMessageParam)=>{
5117
+
5118
+ const eventOrMessage=(!WebsocketImplementation.useSocketIOImplementation?eventOrMessageParam.data:eventOrMessageParam);
5119
+
5120
+ let dataResult=eventOrMessage;
5121
+
5122
+ ////
5123
+ // DBG
5124
+ lognow(" SERVER RECEIVED 1:",eventOrMessage);
5125
+
5126
+ try{
5127
+ dataResult=(WebsocketImplementation.useFlatStrings || isString(eventOrMessage)?JSON.parse(eventOrMessage):eventOrMessage);
5128
+ }catch(error1){
5129
+ // TRACE
5130
+ lognow(`ERROR : Failed to parse JSON for string «${dataResult}»`,error1);
5131
+ dataResult=(isString(eventOrMessage)?eventOrMessage:JSON.stringify(eventOrMessage));
5132
+ }
5133
+
5134
+ return dataResult;
5135
+ },
5136
+
5137
+
5116
5138
  getServer:(listenableServer)=>{
5117
5139
 
5118
5140
  if(!WebsocketImplementation.isNodeContext){
@@ -5173,21 +5195,18 @@ WebsocketImplementation={
5173
5195
  // nodeServerInstance.onConnectionToClient((serverParam, clientSocketParam)=>{
5174
5196
 
5175
5197
  // TODO : Find a way to remove this !
5176
- const doOnMessage=(message)=>{
5198
+ const doOnMessage=(eventOrMessage)=>{
5177
5199
 
5178
5200
  // dataWrapped=JSON.parse(dataWrapped);
5179
5201
  // dataWrapped=getAt(dataWrapped,0);// We get the root element
5202
+
5180
5203
 
5181
- let dataWrapped=message;
5182
- try{
5183
- dataWrapped=(WebsocketImplementation.useFlatStrings || isString(message)?JSON.parse(message):message);
5184
- }catch(error1){
5185
- // TRACE
5186
- lognow(`ERROR : Failed to parse JSON for string «${dataWrapped}»`,error1);
5187
- dataWrapped=(isString(message)?message:JSON.stringify(message));
5188
- }
5189
-
5190
-
5204
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5205
+ ////
5206
+ // DBG
5207
+ lognow(" SERVER RECEIVED 2:",dataWrapped);
5208
+
5209
+
5191
5210
 
5192
5211
  // Channel information is stored in exchanged data :
5193
5212
  if(dataWrapped.channelName!==receptionEntryPoint.channelName) return;
@@ -5412,7 +5431,6 @@ WebsocketImplementation={
5412
5431
  nodeServerInstance.receive("protocol",(message, clientSocket)=>{
5413
5432
 
5414
5433
  if(message.type!=="joinRoom" || !clientSocket) return;
5415
-
5416
5434
  nodeServerInstance.addToRoom(clientSocket, message.clientRoomTag);
5417
5435
 
5418
5436
  });
@@ -5499,13 +5517,13 @@ WebsocketImplementation={
5499
5517
  clientsRoomsTag:clientsRoomsTag,
5500
5518
  execute:(clientSocketParam)=>{
5501
5519
 
5502
- const doOnMessage=(message)=>{
5520
+ const doOnMessage=(eventOrMessage)=>{
5503
5521
 
5504
5522
  // dataWrapped=JSON.parse(dataWrapped);
5505
5523
  // dataWrapped=getAt(dataWrapped,0);// We get the root element
5506
-
5507
- const dataWrapped=(WebsocketImplementation.useFlatStrings?JSON.parse(message):message);
5524
+ // const dataWrapped=(WebsocketImplementation.useFlatStrings?JSON.parse(eventOrMessage):eventOrMessage);
5508
5525
 
5526
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5509
5527
 
5510
5528
  // Channel information is stored in exchanged data :
5511
5529
  if(dataWrapped.channelName && dataWrapped.channelName!==channelName) return;
@@ -5575,9 +5593,7 @@ WebsocketImplementation={
5575
5593
  join:(clientRoomTag)=>{
5576
5594
  // Join room client part protocol :
5577
5595
  const message={type:"joinRoom",clientRoomTag:clientRoomTag};
5578
-
5579
5596
  nodeClientInstance.send("protocol",message);
5580
-
5581
5597
  },
5582
5598
 
5583
5599
 
@@ -5655,26 +5671,14 @@ WebsocketImplementation={
5655
5671
  // DBG
5656
5672
  lognow("INFO : (CLIENT-BROWSER) SETTING UP RECEIVE for :",channelName);
5657
5673
 
5658
- const doOnMessage=(message)=>{
5674
+ const doOnMessage=(eventOrMessage)=>{
5659
5675
 
5660
- // // DBG
5661
- // lognow("!!! RECEIVED : message",message);
5662
5676
 
5663
- // OLD : let dataWrapped=JSON.parse(event.data);
5664
- // const dataWrapped=JSON.parse(message);
5665
- // dataWrapped=getAt(dataWrapped,0);// We get the root element
5666
-
5667
-
5668
- let dataWrapped=message;
5669
- try{
5670
- dataWrapped=(WebsocketImplementation.useFlatStrings || isString(message)?JSON.parse(message):message);
5671
- }catch(error1){
5672
- // TRACE
5673
- lognow(`ERROR : Failed to parse JSON for string «${dataWrapped}»`,error1);
5674
- dataWrapped=(isString(message)?message:JSON.stringify(message));
5675
- }
5676
-
5677
-
5677
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5678
+
5679
+ ////
5680
+ // DBG
5681
+ lognow(" CLIENT-BROWSER RECEIVED 2:",dataWrapped);
5678
5682
 
5679
5683
 
5680
5684
  // Channel information is stored in exchanged data :
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.168",
3
+ "version": "0.0.171",
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)",