@evergis/api 3.0.128 → 3.0.130

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.
package/dist/api.esm.js CHANGED
@@ -939,26 +939,43 @@ var ConnectionStatus;
939
939
  })(ConnectionStatus || (ConnectionStatus = {}));
940
940
 
941
941
  const SUBSCRIPTION_DELAY = 500;
942
+ const KEEP_ALIVE_INTERVAL = 5 * 1000;
942
943
  let Notification = /*#__PURE__*/function (_NotificationService) {
943
944
  _inherits(Notification, _NotificationService);
944
945
 
945
946
  var _super = /*#__PURE__*/_createSuper(Notification);
946
947
 
947
- function Notification(http, api) {
948
+ function Notification(http, api, keepAlive) {
948
949
  var _this;
949
950
 
951
+ if (keepAlive === void 0) {
952
+ keepAlive = false;
953
+ }
954
+
950
955
  _classCallCheck(this, Notification);
951
956
 
952
957
  _this = _super.call(this, http);
953
958
  _this.api = api;
954
959
  _this.MAX_WS_RECONNECT_TRIES = 10;
960
+ _this.keepAlive = false;
955
961
  _this.reconnectTries = 0;
956
962
  _this.subscriptions = [];
957
963
  _this._connectStatus = ConnectionStatus.Initialized;
958
964
 
959
965
  _this.onWsConnected = () => {
960
- _this.connectStatus = ConnectionStatus.Connected; // TODO: comment for now. it launch endless flow of reconnections
966
+ _this.connectStatus = ConnectionStatus.Connected;
967
+
968
+ if (_this.keepAlive) {
969
+ _this.keepAliveTimeout = setInterval(() => {
970
+ if (_this.ws) {
971
+ _this.ws.send(JSON.stringify({
972
+ keepAlive: true
973
+ }));
974
+ }
975
+ }, KEEP_ALIVE_INTERVAL);
976
+ } // TODO: comment for now. it launch endless flow of reconnections
961
977
  // this.reconnectTries = 0;
978
+
962
979
  };
963
980
 
964
981
  _this.onWsClosed = event => {
@@ -979,6 +996,7 @@ let Notification = /*#__PURE__*/function (_NotificationService) {
979
996
  _this.ws = void 0;
980
997
  }
981
998
 
999
+ _this.keepAliveTimeout && clearInterval(_this.keepAliveTimeout);
982
1000
  setTimeout(() => {
983
1001
  _this.connect();
984
1002
  }, 0);
@@ -1006,6 +1024,7 @@ let Notification = /*#__PURE__*/function (_NotificationService) {
1006
1024
  };
1007
1025
 
1008
1026
  _this.emitter = new EventEmitter();
1027
+ _this.keepAlive = keepAlive;
1009
1028
  return _this;
1010
1029
  } // @ts-ignore
1011
1030
 
@@ -1022,6 +1041,11 @@ let Notification = /*#__PURE__*/function (_NotificationService) {
1022
1041
  , new NotificationEvent(connectStatus));
1023
1042
  this._connectStatus = connectStatus;
1024
1043
  }
1044
+ }, {
1045
+ key: "currentWs",
1046
+ get: function get() {
1047
+ return this.ws;
1048
+ }
1025
1049
  }, {
1026
1050
  key: "on",
1027
1051
  value: function on(tag, handler) {
@@ -6093,6 +6117,7 @@ let Api = /*#__PURE__*/function (_EventEmitter) {
6093
6117
  let {
6094
6118
  url,
6095
6119
  wsUrl,
6120
+ wsKeepAlive,
6096
6121
  snappingHubUrl,
6097
6122
  http,
6098
6123
  urlPath,
@@ -6134,7 +6159,7 @@ let Api = /*#__PURE__*/function (_EventEmitter) {
6134
6159
  _this.accountPreview = new AccountPreview(_this.http, _this.account);
6135
6160
  _this.bulk = new BulkOperations(_this.http);
6136
6161
  _this.security = new Security(_this.http, _this.account);
6137
- _this.notification = new Notification(_this.http, _assertThisInitialized(_this));
6162
+ _this.notification = new Notification(_this.http, _assertThisInitialized(_this), wsKeepAlive);
6138
6163
  _this.scheduler = new Scheduler(_this.http);
6139
6164
  _this.file = new FileUpload(_this.http);
6140
6165
  _this.filters = new Filters(_this.http);