aotrautils-srv 0.0.435 → 0.0.436

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_29072022-2359 (22/01/2023-20:08:43)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (23/01/2023-21:41:10)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -2858,32 +2858,40 @@ window.contains=function(container, objectToFind,/*OPTIONAL*/useRegexp=false,sea
2858
2858
  // console.log("WARN : Container is empty ! Cannot search for «"+objectToFind+"».");
2859
2859
  return false;
2860
2860
  }
2861
- if(isArray(container)){
2862
- // for (var i=0; i<container.length; i++){
2863
- // if(container[i] === objectToFind) return true;
2864
- // }
2865
- // return false;
2866
- return container.indexOf(objectToFind) >= 0;
2867
- } else if((container instanceof Object) && (typeof container !== "string")){
2868
- for (key in container){
2869
- if(!container.hasOwnProperty(key)) continue;
2870
- if(!searchInKeysOnly){
2871
- if(container[key] === objectToFind)
2872
- return true;
2873
- }else{
2874
- if(key === (typeof(objectToFind)!=="string"?(""+objectToFind):objectToFind)) // CAUTION : Associative arrays keys are always strings !
2875
- return true;
2861
+ if(!isString(container) && objectToFind && isFunction(objectToFind)){
2862
+ return !!foreach(container, (item, keyOrIndex)=>{
2863
+ if(objectToFind(item, keyOrIndex)) return true;
2864
+ });
2865
+ }else{
2866
+ // Note : We also allow the search of null plain items in a container !
2867
+
2868
+ if(isArray(container)){
2869
+ // for (var i=0; i<container.length; i++){
2870
+ // if(container[i] === objectToFind) return true;
2871
+ // }
2872
+ // return false;
2873
+ return container.indexOf(objectToFind) >= 0;
2874
+ } else if((container instanceof Object) && (typeof container !== "string")){
2875
+ for (key in container){
2876
+ if(!container.hasOwnProperty(key)) continue;
2877
+ if(!searchInKeysOnly){
2878
+ if(container[key] === objectToFind)
2879
+ return true;
2880
+ }else{
2881
+ if(key === (typeof(objectToFind)!=="string"?(""+objectToFind):objectToFind)) // CAUTION : Associative arrays keys are always strings !
2882
+ return true;
2883
+ }
2876
2884
  }
2885
+ return false;
2877
2886
  }
2878
- return false;
2887
+
2888
+ // Container is a string case :
2889
+ var str=container;
2890
+ var chunk=objectToFind;
2891
+ if(!useRegexp)
2892
+ return str.indexOf(chunk) !== -1;
2893
+ return new RegExp(chunk, "gm").test(str);
2879
2894
  }
2880
-
2881
- // Container is a string case :
2882
- var str=container;
2883
- var chunk=objectToFind;
2884
- if(!useRegexp)
2885
- return str.indexOf(chunk) !== -1;
2886
- return new RegExp(chunk, "gm").test(str);
2887
2895
  };
2888
2896
 
2889
2897
  window.hasKey=function(container, keyToFind){
@@ -4856,7 +4864,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4856
4864
 
4857
4865
 
4858
4866
 
4859
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (22/01/2023-20:08:43)»*/
4867
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (23/01/2023-21:41:10)»*/
4860
4868
  /*-----------------------------------------------------------------------------*/
4861
4869
 
4862
4870
 
@@ -5608,6 +5616,11 @@ WebsocketImplementation={
5608
5616
 
5609
5617
  send:(channelNameParam, data, clientsRoomsTag=null)=>{
5610
5618
 
5619
+ // DBG
5620
+ lognow("(CLIENT) (NODEJS) CLIENT TRIES TO SEND !");
5621
+
5622
+
5623
+
5611
5624
  const clientSocket=nodeClientInstance.clientSocket;
5612
5625
 
5613
5626
 
@@ -5662,7 +5675,7 @@ WebsocketImplementation={
5662
5675
  nodeClientInstance.hasConnectEventFired=true;
5663
5676
 
5664
5677
  // DBG
5665
- lognow("DEBUG : CLIENT : doOnConnection !");
5678
+ lognow("DEBUG : CLIENT (NODEJS) : doOnConnection !");
5666
5679
 
5667
5680
  const doOnMessage=(eventOrMessage)=>{
5668
5681
 
@@ -5679,7 +5692,6 @@ WebsocketImplementation={
5679
5692
 
5680
5693
  doOnConnection(nodeClientInstance, clientSocket);
5681
5694
 
5682
-
5683
5695
  };
5684
5696
 
5685
5697
 
@@ -5741,43 +5753,84 @@ WebsocketImplementation={
5741
5753
  const browserInstance={
5742
5754
  clientSocket:clientSocket,
5743
5755
 
5744
- receive:(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null)=>{
5756
+ receptionEntryPoints:[],
5757
+
5758
+ receive:(channelNameParam, doOnIncomingMessage, clientsRoomsTag=null, receptionEntryPointId=null)=>{
5759
+
5745
5760
 
5746
5761
  // DBG
5747
5762
  lognow("INFO : (CLIENT-BROWSER) SETTING UP RECEIVE for :",channelNameParam);
5763
+
5764
+
5765
+ const receptionEntryPoint={
5766
+ channelName:channelNameParam,
5767
+ clientsRoomsTag:clientsRoomsTag,
5768
+ // TODO : ADD TO ALL OTHER SUBSYSTEMS !
5769
+ id:receptionEntryPointId,
5770
+
5771
+ execute:(eventOrMessage)=>{
5772
+
5773
+ const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5774
+
5775
+ // // DBG
5776
+ // lognow("(CLIENT) (DEBUG) CLIENT RECEIVED SOMETHING FROM SERVER :",dataWrapped);
5777
+
5778
+ // Channel information is stored in exchanged data :
5779
+ if(dataWrapped.channelName && dataWrapped.channelName!==channelNameParam) return;
5780
+
5781
+ const clientSocket=browserInstance.clientSocket;
5782
+
5783
+ // Room information is stored in client socket object :
5784
+ if(!WebsocketImplementation.isInRoom(clientSocket,clientsRoomsTag)) return;
5785
+
5786
+ if(doOnIncomingMessage) doOnIncomingMessage(dataWrapped.data, clientSocket);
5787
+
5788
+
5789
+ }
5790
+ };
5748
5791
 
5792
+ // TODO : ADD TO ALL OTHER SUBSYSTEMS !
5793
+ if(!contains(browserInstance.receptionEntryPoints,(l)=>(l.id && receptionEntryPoint.id && l.id===receptionEntryPoint.id)))
5794
+ browserInstance.receptionEntryPoints.push(receptionEntryPoint);
5749
5795
 
5750
- const doOnMessage=(eventOrMessage)=>{
5751
-
5752
- const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
5753
-
5754
- // // DBG
5755
- // lognow("(CLIENT) (DEBUG) CLIENT RECEIVED SOMETHING FROM SERVER :",dataWrapped);
5756
-
5757
-
5758
- // Channel information is stored in exchanged data :
5759
- if(dataWrapped.channelName && dataWrapped.channelName!==channelNameParam) return;
5760
-
5761
- const clientSocket=browserInstance.clientSocket;
5796
+
5797
+ return browserInstance;
5798
+ },
5799
+
5800
+
5801
+
5762
5802
 
5763
- // Room information is stored in client socket object :
5764
- if(!WebsocketImplementation.isInRoom(clientSocket, clientsRoomsTag)) return;
5765
5803
 
5766
- doOnIncomingMessage(dataWrapped.data, clientSocket);
5767
-
5768
- };
5769
-
5770
-
5771
- if(!WebsocketImplementation.useSocketIOImplementation) browserInstance.clientSocket.addEventListener("message", doOnMessage);
5772
- else browserInstance.clientSocket.on(channelNameParam, doOnMessage);
5773
5804
 
5805
+
5806
+ // CURRENT
5807
+ sendChainable:(channelNameParam, data, clientsRoomsTag=null)=>{
5774
5808
 
5775
- return browserInstance;
5809
+ browserInstance.send(channelNameParam, data, clientsRoomsTag);
5810
+
5811
+ const resultPromise={
5812
+ clientsRoomsTag:clientsRoomsTag,
5813
+ thenWhenReceiveMessageType:(channelNameForResponse, messageTypeForResponse, doOnIncomingMessageForResponse)=>{
5814
+ const listenerId=messageTypeForResponse;
5815
+ browserInstance.receive(channelNameForResponse, doOnIncomingMessageForResponse, this.clientsRoomsTag, listenerId);
5816
+ return this;
5817
+ }
5818
+ };
5819
+
5820
+
5821
+ return resultPromise;
5776
5822
  },
5777
5823
 
5778
5824
 
5825
+
5826
+
5827
+
5828
+
5779
5829
  send:(channelNameParam, data, clientsRoomsTag=null)=>{
5780
5830
 
5831
+ // DBG
5832
+ lognow("(CLIENT) (BROWSER) CLIENT TRIES TO SEND !");
5833
+
5781
5834
  const clientSocket=browserInstance.clientSocket;
5782
5835
 
5783
5836
 
@@ -5825,8 +5878,23 @@ WebsocketImplementation={
5825
5878
  if(browserInstance.hasConnectEventFired) return;
5826
5879
  browserInstance.hasConnectEventFired=true;
5827
5880
 
5828
- const clientSocket=browserInstance.clientSocket;
5881
+
5882
+
5883
+ // DBG
5884
+ lognow("DEBUG : CLIENT (BROWSER) : doOnConnection !");
5885
+
5886
+ const doOnMessage=(eventOrMessage)=>{
5887
+
5888
+ // We execute the listeners entry points registration :
5889
+ foreach(browserInstance.receptionEntryPoints,(receptionEntryPoint)=>{
5890
+ receptionEntryPoint.execute(eventOrMessage);
5891
+ });
5829
5892
 
5893
+ };
5894
+
5895
+ const clientSocket=browserInstance.clientSocket;
5896
+ if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.addEventListener("message", doOnMessage);
5897
+ else clientSocket.on(channelNameParam, doOnMessage);
5830
5898
 
5831
5899
  doOnConnection(browserInstance, clientSocket);
5832
5900
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.435",
3
+ "version": "0.0.436",
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)",