chat4app-client-angular 1.0.10 → 1.0.12

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.
@@ -1788,17 +1788,28 @@
1788
1788
  this.debug = chat4AppConfig.debug;
1789
1789
  };
1790
1790
  Chat4appClientAngularService.prototype.init = function (securityChatToken, callback, chatCallback, connectionClientId) {
1791
- if (!this.chatServer || this.chatServer.trim().length == 0) {
1792
- throw new Error("Endpoint is empty");
1793
- }
1794
- if (!securityChatToken || securityChatToken.trim().length == 0) {
1795
- throw new Error("SecurityChatToken is empty");
1796
- }
1797
- this.setTokenChat4app(securityChatToken);
1798
- if (chatCallback && connectionClientId) {
1799
- this.connectWebsocket(chatCallback, connectionClientId);
1800
- }
1801
- callback(securityChatToken);
1791
+ return __awaiter(this, void 0, void 0, function () {
1792
+ return __generator(this, function (_b) {
1793
+ switch (_b.label) {
1794
+ case 0:
1795
+ if (!this.chatServer || this.chatServer.trim().length == 0) {
1796
+ throw new Error("Endpoint is empty");
1797
+ }
1798
+ if (!securityChatToken || securityChatToken.trim().length == 0) {
1799
+ throw new Error("SecurityChatToken is empty");
1800
+ }
1801
+ this.setTokenChat4app(securityChatToken);
1802
+ if (!(chatCallback && connectionClientId)) return [3 /*break*/, 2];
1803
+ return [4 /*yield*/, this.connectWebsocket(chatCallback, connectionClientId)];
1804
+ case 1:
1805
+ _b.sent();
1806
+ _b.label = 2;
1807
+ case 2:
1808
+ callback(securityChatToken);
1809
+ return [2 /*return*/];
1810
+ }
1811
+ });
1812
+ });
1802
1813
  };
1803
1814
  Chat4appClientAngularService.prototype.getChatUrlDownload = function (messageFileId) {
1804
1815
  return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId + "&token=" + this.getBearerToken();
@@ -2217,8 +2228,6 @@
2217
2228
  chatCallback.onChatClosed(chat4appMessage);
2218
2229
  }
2219
2230
  else if (data.type == "count_notread") {
2220
- console.log("count_notread");
2221
- console.log(data);
2222
2231
  var chat4appMessage = new Chat4AppMessageReceive();
2223
2232
  chat4appMessage.data.chatId = data.chatId;
2224
2233
  chat4appMessage.data.chatMessageId = data.chatMessageId;
@@ -2236,7 +2245,7 @@
2236
2245
  chatCallback.onCountNotRead(chat4appMessage);
2237
2246
  }
2238
2247
  };
2239
- Chat4appClientAngularService.prototype.ensureConn = function (chatUserExternalId) {
2248
+ Chat4appClientAngularService.prototype.ensureConn = function (chatUserExternalId, forceReconnectNats) {
2240
2249
  return __awaiter(this, void 0, void 0, function () {
2241
2250
  var that, uriStep1, server, _b;
2242
2251
  return __generator(this, function (_c) {
@@ -2253,13 +2262,16 @@
2253
2262
  if (this.debug) {
2254
2263
  console.log("ws server: " + server);
2255
2264
  }
2256
- if (!(!this.nc || (this.nc.isClose && this.nc.isClose()))) return [3 /*break*/, 2];
2265
+ if (!(forceReconnectNats || !this.nc || (this.nc.isClose && this.nc.isClose()))) return [3 /*break*/, 3];
2266
+ return [4 /*yield*/, that.disconnectInternal(true)];
2267
+ case 1:
2268
+ _c.sent();
2257
2269
  _b = that;
2258
2270
  return [4 /*yield*/, nats_min.connect({ url: server, user: chatUserExternalId, pass: this.getBearerToken(), reconnect: false })];
2259
- case 1:
2260
- _b.nc = _c.sent();
2261
- _c.label = 2;
2262
2271
  case 2:
2272
+ _b.nc = _c.sent();
2273
+ _c.label = 3;
2274
+ case 3:
2263
2275
  this.chatUserExternalId = chatUserExternalId;
2264
2276
  return [2 /*return*/, that.nc];
2265
2277
  }
@@ -2267,6 +2279,13 @@
2267
2279
  });
2268
2280
  };
2269
2281
  Chat4appClientAngularService.prototype.disconnect = function () {
2282
+ return __awaiter(this, void 0, void 0, function () {
2283
+ return __generator(this, function (_b) {
2284
+ return [2 /*return*/, this.disconnectInternal(false)];
2285
+ });
2286
+ });
2287
+ };
2288
+ Chat4appClientAngularService.prototype.disconnectInternal = function (ignoreOffLine) {
2270
2289
  return __awaiter(this, void 0, void 0, function () {
2271
2290
  var e_1;
2272
2291
  var _this = this;
@@ -2281,7 +2300,7 @@
2281
2300
  catch (e) {
2282
2301
  }
2283
2302
  }
2284
- if (this.nc && this.chatUserExternalId && this.chatUserExternalId.length > 0 && this.getBearerToken() && this.getBearerToken().length > 0) {
2303
+ if (!ignoreOffLine && this.nc && this.chatUserExternalId && this.chatUserExternalId.length > 0 && this.getBearerToken() && this.getBearerToken().length > 0) {
2285
2304
  this.setOffLine(this.chatUserExternalId).subscribe(function () {
2286
2305
  if (_this.debug) {
2287
2306
  console.log("had set offline");
@@ -2358,7 +2377,7 @@
2358
2377
  switch (_b.label) {
2359
2378
  case 0:
2360
2379
  that = this;
2361
- this.disconnect();
2380
+ this.disconnectInternal(true);
2362
2381
  securityToken = this.getBearerToken();
2363
2382
  tokenAuth = "";
2364
2383
  if (securityToken && securityToken.startsWith("Bearer ")) {