aotrautils-srv 0.0.169 → 0.0.172

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:32:32)»*/
3
+ /*utils COMMONS library associated with aotra version : «1.0.0.000 (17/07/2022-14:50:25)»*/
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:32:32)»*/
4831
+ /*utils SERVER library associated with aotra version : «1.0.0.000 (17/07/2022-14:50:25)»*/
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,27 +5195,13 @@ 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
-
5182
- ////
5183
- // DBG
5184
- lognow(" SERVER RECEIVED 1:",message);
5185
-
5186
-
5187
- let dataWrapped=message;
5188
- try{
5189
- dataWrapped=(WebsocketImplementation.useFlatStrings || isString(message)?JSON.parse(message):message);
5190
- }catch(error1){
5191
- // TRACE
5192
- lognow(`ERROR : Failed to parse JSON for string «${dataWrapped}»`,error1);
5193
- dataWrapped=(isString(message)?message:JSON.stringify(message));
5194
- }
5195
-
5196
-
5204
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5197
5205
  ////
5198
5206
  // DBG
5199
5207
  lognow(" SERVER RECEIVED 2:",dataWrapped);
@@ -5423,7 +5431,6 @@ WebsocketImplementation={
5423
5431
  nodeServerInstance.receive("protocol",(message, clientSocket)=>{
5424
5432
 
5425
5433
  if(message.type!=="joinRoom" || !clientSocket) return;
5426
-
5427
5434
  nodeServerInstance.addToRoom(clientSocket, message.clientRoomTag);
5428
5435
 
5429
5436
  });
@@ -5510,13 +5517,13 @@ WebsocketImplementation={
5510
5517
  clientsRoomsTag:clientsRoomsTag,
5511
5518
  execute:(clientSocketParam)=>{
5512
5519
 
5513
- const doOnMessage=(message)=>{
5520
+ const doOnMessage=(eventOrMessage)=>{
5514
5521
 
5515
5522
  // dataWrapped=JSON.parse(dataWrapped);
5516
5523
  // dataWrapped=getAt(dataWrapped,0);// We get the root element
5517
-
5518
- const dataWrapped=(WebsocketImplementation.useFlatStrings?JSON.parse(message):message);
5524
+ // const dataWrapped=(WebsocketImplementation.useFlatStrings?JSON.parse(eventOrMessage):eventOrMessage);
5519
5525
 
5526
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5520
5527
 
5521
5528
  // Channel information is stored in exchanged data :
5522
5529
  if(dataWrapped.channelName && dataWrapped.channelName!==channelName) return;
@@ -5586,9 +5593,7 @@ WebsocketImplementation={
5586
5593
  join:(clientRoomTag)=>{
5587
5594
  // Join room client part protocol :
5588
5595
  const message={type:"joinRoom",clientRoomTag:clientRoomTag};
5589
-
5590
5596
  nodeClientInstance.send("protocol",message);
5591
-
5592
5597
  },
5593
5598
 
5594
5599
 
@@ -5666,26 +5671,14 @@ WebsocketImplementation={
5666
5671
  // DBG
5667
5672
  lognow("INFO : (CLIENT-BROWSER) SETTING UP RECEIVE for :",channelName);
5668
5673
 
5669
- const doOnMessage=(message)=>{
5674
+ const doOnMessage=(eventOrMessage)=>{
5670
5675
 
5671
- // // DBG
5672
- // lognow("!!! RECEIVED : message",message);
5673
5676
 
5674
- // OLD : let dataWrapped=JSON.parse(event.data);
5675
- // const dataWrapped=JSON.parse(message);
5676
- // dataWrapped=getAt(dataWrapped,0);// We get the root element
5677
-
5678
-
5679
- let dataWrapped=message;
5680
- try{
5681
- dataWrapped=(WebsocketImplementation.useFlatStrings || isString(message)?JSON.parse(message):message);
5682
- }catch(error1){
5683
- // TRACE
5684
- lognow(`ERROR : Failed to parse JSON for string «${dataWrapped}»`,error1);
5685
- dataWrapped=(isString(message)?message:JSON.stringify(message));
5686
- }
5687
-
5688
-
5677
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5678
+
5679
+ ////
5680
+ // DBG
5681
+ lognow(" CLIENT-BROWSER RECEIVED 2:",dataWrapped);
5689
5682
 
5690
5683
 
5691
5684
  // Channel information is stored in exchanged data :
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.169",
3
+ "version": "0.0.172",
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)",