chat4app-client-angular 1.0.16 → 1.0.18

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.
@@ -1792,7 +1792,6 @@
1792
1792
  var _this = this;
1793
1793
  return new rxjs.Observable(function (subscriber) {
1794
1794
  try {
1795
- // 1. Validações Iniciais
1796
1795
  if (!_this.chatServer || _this.chatServer.trim().length === 0) {
1797
1796
  subscriber.error(new Error("Endpoint is empty"));
1798
1797
  return;
@@ -1801,14 +1800,12 @@
1801
1800
  subscriber.error(new Error("SecurityChatToken is empty"));
1802
1801
  return;
1803
1802
  }
1804
- // 2. Lógica de Negócio
1805
1803
  _this.setTokenChat4app(securityChatToken);
1806
1804
  if (chatCallback && connectionClientId) {
1807
1805
  _this.chatUserExternalId = connectionClientId;
1808
1806
  _this.chatCallback = chatCallback;
1809
1807
  _this.connectWebsocket();
1810
1808
  }
1811
- // 3. Emite o token e finaliza o fluxo
1812
1809
  subscriber.next(securityChatToken);
1813
1810
  subscriber.complete();
1814
1811
  }
@@ -2123,42 +2120,48 @@
2123
2120
  .then(function (nc) {
2124
2121
  that.nc = nc;
2125
2122
  var subject = "chat4app.config." + _this.configId + ".user." + _this.chatUserExternalId;
2126
- var sub = that.nc.subscribe(subject, function (msg) {
2123
+ that.nc.subscribe(subject, function (msg) {
2127
2124
  if (_this.debug) {
2128
2125
  console.log(msg);
2129
2126
  }
2130
2127
  _this.processAndCallback(JSON.parse(msg.data));
2131
2128
  });
2132
- if (_this.interval) {
2133
- try {
2134
- clearInterval(_this.interval);
2135
- }
2136
- catch (e) {
2137
- }
2138
- }
2139
- that.interval = setInterval(function () {
2140
- if (that.debug) {
2141
- console.log("publish chat4app.user.online " + _this.chatUserExternalId + " ");
2142
- }
2143
- try {
2144
- that.nc.publish("chat4app.user.online", _this.chatUserExternalId);
2145
- }
2146
- catch (e) {
2147
- if (_this.debug) {
2148
- console.log("try reconnect...");
2149
- }
2150
- _this.ensureConn();
2151
- }
2152
- }, 1000);
2129
+ _this.setIntervalPing();
2153
2130
  if (_this.debug) {
2154
2131
  console.log("Subscribe online chat4app.user." + _this.chatUserExternalId + ".online");
2155
2132
  }
2156
2133
  })
2157
2134
  .catch(function (err) {
2158
2135
  // Notifica o chamador sobre o erro na conexão
2159
- console.error("NATS Error:", err);
2136
+ console.log("NATS Error:");
2137
+ console.log(err);
2138
+ setTimeout(_this.ensureConn, 1000);
2160
2139
  });
2161
2140
  };
2141
+ Chat4appClientAngularService.prototype.setIntervalPing = function () {
2142
+ var _this = this;
2143
+ if (this.interval) {
2144
+ try {
2145
+ clearInterval(this.interval);
2146
+ }
2147
+ catch (e) {
2148
+ }
2149
+ }
2150
+ this.interval = setInterval(function () {
2151
+ if (_this.debug) {
2152
+ console.log("publish chat4app.user.online " + _this.chatUserExternalId + " ");
2153
+ }
2154
+ try {
2155
+ _this.nc.publish("chat4app.user.online", _this.chatUserExternalId);
2156
+ }
2157
+ catch (e) {
2158
+ if (_this.debug) {
2159
+ console.log("try reconnect...");
2160
+ }
2161
+ _this.ensureConn();
2162
+ }
2163
+ }, 1000);
2164
+ };
2162
2165
  Chat4appClientAngularService.prototype.disconnect = function () {
2163
2166
  return this.disconnectInternal(false);
2164
2167
  };