@magic-xpa/engine 4.1300.0-dev4130.161 → 4.1300.0-dev4130.170

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.
@@ -5,7 +5,6 @@ import { HttpHeaders, HttpErrorResponse } from '@angular/common/http';
5
5
  import { timer, Subject } from 'rxjs';
6
6
  import * as CryptoJS from 'crypto-js';
7
7
  import { io } from 'socket.io-client';
8
- import { filter } from 'rxjs/operators';
9
8
 
10
9
  ///
11
10
  /// This class is used to hold references to global objects, using their interfaces/base classes. This allows other objects to access those global objects
@@ -13846,8 +13845,6 @@ class SubscriberClient {
13846
13845
  static instance;
13847
13846
  socket;
13848
13847
  subscribedTopics = new Set();
13849
- messageSubject = new Subject();
13850
- subscriptionsDataSubject = new Subject();
13851
13848
  constructor(task) {
13852
13849
  // Connect to the Socket.IO server with subscriber role
13853
13850
  const serverUrl = EnvParamsTable.Instance.get(ConstInterface.MG_TAG_PUBSUB_SERVER_URI);
@@ -13860,37 +13857,65 @@ class SubscriberClient {
13860
13857
  });
13861
13858
  // Handle connection
13862
13859
  this.socket.on('connect', () => {
13863
- console.log('Connected to server as subscriber:', this.socket.id);
13860
+ Logger.Instance.WriteDevToLog("SubscriberClient connected to server : " + this.socket.id);
13861
+ // Case 1: Subscribe to all topics initially
13862
+ // Case 2: Subscribe to topics that were subscribed with previous session (reconnected after a disconnection)
13863
+ if (this.subscribedTopics.size > 0) {
13864
+ this.subscribedTopics.forEach(topic => {
13865
+ this.socket.emit('subscribe', topic);
13866
+ });
13867
+ }
13864
13868
  });
13865
13869
  // Handle disconnection
13866
- this.socket.on('disconnect', () => {
13867
- console.log('Disconnected from server');
13868
- this.subscribedTopics.clear(); //TODO: Check what happens if we disconnect and reconnect.
13870
+ this.socket.on('disconnect', (reason) => {
13871
+ let disconnectReason;
13872
+ switch (reason) {
13873
+ case "ping timeout":
13874
+ disconnectReason = "Connection lost due to timeout";
13875
+ break;
13876
+ case "transport close":
13877
+ disconnectReason = "Network connection closed";
13878
+ break;
13879
+ case "io server disconnect":
13880
+ disconnectReason = "Disconnected by server";
13881
+ break;
13882
+ default:
13883
+ disconnectReason = "Disconnected:";
13884
+ }
13885
+ Logger.Instance.WriteDevToLog("SubscriberClient disconnected from server : " + reason + " : " + disconnectReason);
13886
+ });
13887
+ // Handle reconnection
13888
+ this.socket.on("reconnect", (attemptNumber) => {
13889
+ Logger.Instance.WriteDevToLog("Reconnected after " + attemptNumber + "attempts");
13890
+ });
13891
+ // Handle reconnection attempts
13892
+ this.socket.on("reconnect_attempt", (attemptNumber) => {
13893
+ Logger.Instance.WriteDevToLog("Reconnect attempt: " + attemptNumber);
13894
+ });
13895
+ // Handle reconnection errors
13896
+ this.socket.on("connect_error", (err) => {
13897
+ Logger.Instance.WriteDevToLog("Connection error: " + err.name + " Message: " + err.message);
13869
13898
  });
13870
13899
  // Handle subscription confirmation
13871
13900
  this.socket.on('subscribed', (data) => {
13872
13901
  this.subscribedTopics.add(data.topic);
13873
- console.log('Subscribed to topic:', data.topic, data.message);
13902
+ Logger.Instance.WriteDevToLog("SubscriberClient subscribed to topic : " + data.topic + " : " + data.message);
13874
13903
  });
13875
13904
  // Handle unsubscription confirmation
13876
13905
  this.socket.on('unsubscribed', (data) => {
13877
13906
  this.subscribedTopics.delete(data.topic);
13878
- console.log('Unsubscribed from topic:', data.topic, data.message);
13907
+ Logger.Instance.WriteDevToLog("SubscriberClient unsubscribed from topic : " + data.topic + " : " + data.message);
13879
13908
  });
13880
13909
  // Handle errors
13881
13910
  this.socket.on('error', (error) => {
13882
- console.error('Socket error:', error.message);
13911
+ Logger.Instance.WriteErrorToLog("SubscriberClient error : " + error.message);
13883
13912
  });
13884
13913
  // Handle incoming messages
13885
13914
  this.socket.on('message', (data) => {
13886
- this.messageSubject.next(data);
13887
- console.warn("message", data);
13915
+ //this.messageSubject.next(data);
13916
+ Logger.Instance.WriteDevToLog("SubscriberClient received message from topic : " + data.topic + " : " + data.message);
13888
13917
  EventsManager.Instance.AddTopicPublishedEvent(taskRef, data.topic, data.message);
13889
13918
  });
13890
- // Handle subscriptions data
13891
- this.socket.on('subscriptionsData', (data) => {
13892
- this.subscriptionsDataSubject.next(data);
13893
- });
13894
13919
  }
13895
13920
  /**
13896
13921
  * Get the singleton instance of SubscriberClient
@@ -13901,89 +13926,38 @@ class SubscriberClient {
13901
13926
  }
13902
13927
  return SubscriberClient.instance;
13903
13928
  }
13904
- /**
13905
- * Subscribe to a specific topic
13906
- * @param topic The topic to subscribe to
13907
- */
13908
- subscribe(topic) {
13909
- if (!this.subscribedTopics.has(topic)) {
13910
- this.socket.emit('subscribe', topic);
13911
- }
13912
- }
13913
13929
  /**
13914
13930
  * Subscribe to multiple topics at once
13915
13931
  * @param topics Array of topics to subscribe to
13916
13932
  */
13917
- subscribeToTopics(topics) {
13918
- topics.forEach(topic => this.subscribe(topic));
13919
- }
13920
- /**
13921
- * Unsubscribe from a specific topic
13922
- * @param topic The topic to unsubscribe from
13923
- */
13924
- unsubscribe(topic) {
13925
- if (this.subscribedTopics.has(topic)) {
13926
- this.socket.emit('unsubscribe', topic);
13927
- }
13933
+ subscribe(topics) {
13934
+ topics.forEach(topic => {
13935
+ if (!this.subscribedTopics.has(topic)) {
13936
+ this.socket.emit('subscribe', topic);
13937
+ }
13938
+ });
13928
13939
  }
13929
13940
  /**
13930
13941
  * Unsubscribe from multiple topics at once
13931
13942
  * @param topics Array of topics to unsubscribe from
13932
13943
  */
13933
- unsubscribeFromTopics(topics) {
13934
- topics.forEach(topic => this.unsubscribe(topic));
13944
+ unsubscribe(topics) {
13945
+ topics.forEach(topic => {
13946
+ if (this.subscribedTopics.has(topic)) {
13947
+ this.socket.emit('unsubscribe', topic);
13948
+ }
13949
+ });
13935
13950
  }
13936
13951
  /**
13937
13952
  * Unsubscribe from all topics
13953
+ * TODO: To be called when client explicitly disconnects from the server. Alternately, if middleware receives a disconnect request, it can also unsubscribe from all topics from its own side.
13938
13954
  */
13939
13955
  unsubscribeFromAll() {
13940
- this.subscribedTopics.forEach(topic => this.unsubscribe(topic));
13941
- }
13942
- /**
13943
- * Check if subscribed to a specific topic
13944
- * @param topic The topic to check
13945
- * @returns true if subscribed, false otherwise
13946
- */
13947
- isSubscribed(topic) {
13948
- return this.subscribedTopics.has(topic);
13949
- }
13950
- /**
13951
- * Get all currently subscribed topics
13952
- * @returns Array of subscribed topics
13953
- */
13954
- getSubscribedTopics() {
13955
- return Array.from(this.subscribedTopics);
13956
- }
13957
- /**
13958
- * Get an Observable for incoming messages from all subscribed topics
13959
- * @returns Observable that emits message data
13960
- */
13961
- onMessage() {
13962
- return this.messageSubject.asObservable();
13963
- }
13964
- /**
13965
- * Get an Observable for incoming messages from a specific topic
13966
- * @param topic The topic to filter messages for
13967
- * @returns Observable that emits message data for the specified topic
13968
- */
13969
- onMessageForTopic(topic) {
13970
- return this.messageSubject.asObservable().pipe(filter((data) => data.topic === topic));
13971
- }
13972
- /**
13973
- * Get current subscriptions (for debugging)
13974
- */
13975
- getSubscriptions() {
13976
- this.socket.emit('getSubscriptions');
13977
- }
13978
- /**
13979
- * Listen for subscriptions data
13980
- * @returns Observable that emits subscriptions list
13981
- */
13982
- onSubscriptionsData() {
13983
- return this.subscriptionsDataSubject.asObservable();
13956
+ this.subscribedTopics.forEach(topic => this.socket.emit('unsubscribe', topic));
13984
13957
  }
13985
13958
  /**
13986
13959
  * Disconnect from the server
13960
+ * TODO: To be called when client explicitly disconnects from the server.
13987
13961
  */
13988
13962
  disconnect() {
13989
13963
  this.socket.disconnect();
@@ -15631,24 +15605,12 @@ class ExpressionEvaluator extends GuiExpressionEvaluator {
15631
15605
  expStrTracker.resetNullResult();
15632
15606
  break;
15633
15607
  case ExpressionInterface.EXP_OP_SUBSCRIBE:
15634
- nArgs = valStack.pop();
15635
- if (nArgs > 0) {
15636
- // get the parameters
15637
- Exp_params = new Array(nArgs);
15638
- for (j = 0; j < nArgs; j++)
15639
- Exp_params[nArgs - 1 - j] = valStack.pop();
15640
- this.eval_op_Subscribe(Exp_params, resVal);
15641
- }
15608
+ resVal.Attr = StorageAttribute.BOOLEAN;
15609
+ resVal.BoolVal = this.eval_op_Subscribe(valStack);
15642
15610
  break;
15643
15611
  case ExpressionInterface.EXP_OP_UNSUBSCRIBE:
15644
- nArgs = valStack.pop();
15645
- if (nArgs > 0) {
15646
- // get the parameters
15647
- Exp_params = new Array(nArgs);
15648
- for (j = 0; j < nArgs; j++)
15649
- Exp_params[nArgs - 1 - j] = valStack.pop();
15650
- this.eval_op_UnSubscribe(Exp_params, resVal);
15651
- }
15612
+ resVal.Attr = StorageAttribute.BOOLEAN;
15613
+ resVal.BoolVal = this.eval_op_UnSubscribe(valStack);
15652
15614
  break;
15653
15615
  default:
15654
15616
  return;
@@ -18742,19 +18704,44 @@ class ExpressionEvaluator extends GuiExpressionEvaluator {
18742
18704
  }
18743
18705
  return CryptoJS.lib.WordArray.create(words, u8.length);
18744
18706
  }
18745
- eval_op_Subscribe(val1, resVal) {
18746
- resVal.Attr = StorageAttribute.BOOLEAN;
18747
- resVal.BoolVal = false;
18748
- let sc = SubscriberClient.getInstance(this.ExpTask);
18749
- let topics = this.params2arguments(val1, 0, val1.length);
18750
- sc.subscribeToTopics(topics);
18707
+ eval_op_Subscribe(valStack) {
18708
+ let nArgs = valStack.pop();
18709
+ let result = false;
18710
+ if (nArgs > 0) {
18711
+ // get the parameters
18712
+ let Exp_params = new Array(nArgs);
18713
+ for (let j = 0; j < nArgs; j++) {
18714
+ Exp_params[nArgs - 1 - j] = valStack.pop();
18715
+ }
18716
+ let sc = SubscriberClient.getInstance(this.ExpTask);
18717
+ let topics = this.params2arguments(Exp_params, 0, Exp_params.length);
18718
+ sc.subscribe(topics);
18719
+ result = true;
18720
+ }
18721
+ else {
18722
+ Logger.Instance.WriteExceptionToLogWithMsg('ExpressionEvaluator.Subscribe() there is problem with the arguments');
18723
+ result = false;
18724
+ }
18725
+ return result;
18751
18726
  }
18752
- eval_op_UnSubscribe(val1, resVal) {
18753
- resVal.Attr = StorageAttribute.BOOLEAN;
18754
- resVal.BoolVal = false;
18755
- let sc = SubscriberClient.getInstance(this.ExpTask);
18756
- let topics = this.params2arguments(val1, 0, val1.length);
18757
- sc.unsubscribeFromTopics(topics);
18727
+ eval_op_UnSubscribe(valStack) {
18728
+ let nArgs = valStack.pop();
18729
+ let result = false;
18730
+ if (nArgs > 0) {
18731
+ // get the parameters
18732
+ let Exp_params = new Array(nArgs);
18733
+ for (let j = 0; j < nArgs; j++) {
18734
+ Exp_params[nArgs - 1 - j] = valStack.pop();
18735
+ }
18736
+ let sc = SubscriberClient.getInstance(this.ExpTask);
18737
+ let topics = this.params2arguments(Exp_params, 0, Exp_params.length);
18738
+ sc.unsubscribe(topics);
18739
+ }
18740
+ else {
18741
+ Logger.Instance.WriteExceptionToLogWithMsg('ExpressionEvaluator.UnSubscribe() there is problem with the arguments');
18742
+ result = false;
18743
+ }
18744
+ return result;
18758
18745
  }
18759
18746
  }
18760
18747
  /// <summary>
@@ -39859,7 +39846,7 @@ class CommandsTable {
39859
39846
  }
39860
39847
  }
39861
39848
 
39862
- let CurrentClientVersion = '4.1300.0-dev4130.161';
39849
+ let CurrentClientVersion = '4.1300.0-dev4130.170';
39863
39850
 
39864
39851
  // @dynamic
39865
39852
  class ClientManager {