chat4app-client-angular 1.0.15 → 1.0.16
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/bundles/chat4app-client-angular.umd.js +133 -333
- package/bundles/chat4app-client-angular.umd.js.map +1 -1
- package/bundles/chat4app-client-angular.umd.min.js +2 -2
- package/bundles/chat4app-client-angular.umd.min.js.map +1 -1
- package/chat4app-client-angular.metadata.json +1 -1
- package/esm2015/lib/chat4app-client-angular.service.js +122 -273
- package/fesm2015/chat4app-client-angular.js +119 -270
- package/fesm2015/chat4app-client-angular.js.map +1 -1
- package/lib/chat4app-client-angular.service.d.ts +8 -7
- package/lib/chat4app-client-angular.service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('chat4app-client-angular', ['exports', '@angular/core', '@angular/common/http'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["chat4app-client-angular"] = {}, global.ng.core, global.ng.common.http));
|
|
5
|
-
})(this, (function (exports, i0, i1) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('rxjs')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('chat4app-client-angular', ['exports', '@angular/core', '@angular/common/http', 'rxjs'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["chat4app-client-angular"] = {}, global.ng.core, global.ng.common.http, global.rxjs));
|
|
5
|
+
})(this, (function (exports, i0, i1, rxjs) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -1778,6 +1778,7 @@
|
|
|
1778
1778
|
this.chatUrl = "";
|
|
1779
1779
|
this.debug = false;
|
|
1780
1780
|
this.chatUserExternalId = "";
|
|
1781
|
+
this.configId = "";
|
|
1781
1782
|
this.timeoutReconnect = 500;
|
|
1782
1783
|
}
|
|
1783
1784
|
Chat4appClientAngularService.prototype.ngOnInit = function () {
|
|
@@ -1787,28 +1788,34 @@
|
|
|
1787
1788
|
this.chatUrl = chat4AppConfig.endpoint + "/api/v1/";
|
|
1788
1789
|
this.debug = chat4AppConfig.debug;
|
|
1789
1790
|
};
|
|
1790
|
-
Chat4appClientAngularService.prototype.init = function (securityChatToken,
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
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*/];
|
|
1791
|
+
Chat4appClientAngularService.prototype.init = function (securityChatToken, chatCallback, connectionClientId) {
|
|
1792
|
+
var _this = this;
|
|
1793
|
+
return new rxjs.Observable(function (subscriber) {
|
|
1794
|
+
try {
|
|
1795
|
+
// 1. Validações Iniciais
|
|
1796
|
+
if (!_this.chatServer || _this.chatServer.trim().length === 0) {
|
|
1797
|
+
subscriber.error(new Error("Endpoint is empty"));
|
|
1798
|
+
return;
|
|
1810
1799
|
}
|
|
1811
|
-
|
|
1800
|
+
if (!securityChatToken || securityChatToken.trim().length === 0) {
|
|
1801
|
+
subscriber.error(new Error("SecurityChatToken is empty"));
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
// 2. Lógica de Negócio
|
|
1805
|
+
_this.setTokenChat4app(securityChatToken);
|
|
1806
|
+
if (chatCallback && connectionClientId) {
|
|
1807
|
+
_this.chatUserExternalId = connectionClientId;
|
|
1808
|
+
_this.chatCallback = chatCallback;
|
|
1809
|
+
_this.connectWebsocket();
|
|
1810
|
+
}
|
|
1811
|
+
// 3. Emite o token e finaliza o fluxo
|
|
1812
|
+
subscriber.next(securityChatToken);
|
|
1813
|
+
subscriber.complete();
|
|
1814
|
+
}
|
|
1815
|
+
catch (err) {
|
|
1816
|
+
// Captura erros inesperados e envia para o canal de erro do Observable
|
|
1817
|
+
subscriber.error(err);
|
|
1818
|
+
}
|
|
1812
1819
|
});
|
|
1813
1820
|
};
|
|
1814
1821
|
Chat4appClientAngularService.prototype.getChatUrlDownload = function (messageFileId) {
|
|
@@ -2098,250 +2105,99 @@
|
|
|
2098
2105
|
Chat4appClientAngularService.prototype.setTokenChat4app = function (chat4AppSessionToken) {
|
|
2099
2106
|
window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
|
|
2100
2107
|
};
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2108
|
+
Chat4appClientAngularService.prototype.ensureConn = function () {
|
|
2109
|
+
var _this = this;
|
|
2110
|
+
if (this.debug) {
|
|
2111
|
+
console.log("chatServer: " + this.chatServer);
|
|
2112
|
+
console.log("userId: " + this.chatUserExternalId);
|
|
2113
|
+
console.log("getBearerToken: " + this.getBearerToken());
|
|
2114
|
+
}
|
|
2115
|
+
var that = this;
|
|
2116
|
+
var uriStep1 = this.chatServer.replace(/^https/, 'wss');
|
|
2117
|
+
var server = uriStep1.replace(/(\/\/.*?)\//, '$1\/ws/');
|
|
2118
|
+
if (this.debug) {
|
|
2119
|
+
console.log("ws server: " + server);
|
|
2120
|
+
}
|
|
2121
|
+
that.disconnectInternal(true);
|
|
2122
|
+
nats_min.connect({ url: server, user: this.chatUserExternalId, pass: this.getBearerToken(), reconnect: false })
|
|
2123
|
+
.then(function (nc) {
|
|
2124
|
+
that.nc = nc;
|
|
2125
|
+
var subject = "chat4app.config." + _this.configId + ".user." + _this.chatUserExternalId;
|
|
2126
|
+
var sub = that.nc.subscribe(subject, function (msg) {
|
|
2127
|
+
if (_this.debug) {
|
|
2128
|
+
console.log(msg);
|
|
2129
|
+
}
|
|
2130
|
+
_this.processAndCallback(JSON.parse(msg.data));
|
|
2131
|
+
});
|
|
2132
|
+
if (_this.interval) {
|
|
2133
|
+
try {
|
|
2134
|
+
clearInterval(_this.interval);
|
|
2135
|
+
}
|
|
2136
|
+
catch (e) {
|
|
2137
|
+
}
|
|
2120
2138
|
}
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
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);
|
|
2153
|
+
if (_this.debug) {
|
|
2154
|
+
console.log("Subscribe online chat4app.user." + _this.chatUserExternalId + ".online");
|
|
2124
2155
|
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
for (var key in data) {
|
|
2140
|
-
datTmp.set(key, data[key]);
|
|
2156
|
+
})
|
|
2157
|
+
.catch(function (err) {
|
|
2158
|
+
// Notifica o chamador sobre o erro na conexão
|
|
2159
|
+
console.error("NATS Error:", err);
|
|
2160
|
+
});
|
|
2161
|
+
};
|
|
2162
|
+
Chat4appClientAngularService.prototype.disconnect = function () {
|
|
2163
|
+
return this.disconnectInternal(false);
|
|
2164
|
+
};
|
|
2165
|
+
Chat4appClientAngularService.prototype.disconnectInternal = function (ignoreOffLine) {
|
|
2166
|
+
// Check how we can disconnect
|
|
2167
|
+
if (this.interval) {
|
|
2168
|
+
try {
|
|
2169
|
+
clearInterval(this.interval);
|
|
2141
2170
|
}
|
|
2142
|
-
|
|
2143
|
-
chatCallback.onOffline(chat4appMessage);
|
|
2144
|
-
}
|
|
2145
|
-
else if (data.type == "read") {
|
|
2146
|
-
var chat4appMessage = new Chat4AppMessageReceive();
|
|
2147
|
-
chat4appMessage.data.chatId = data.chatId;
|
|
2148
|
-
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
2149
|
-
chat4appMessage.data.externalId = data.externalId;
|
|
2150
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2151
|
-
chat4appMessage.data.toId = data.toId;
|
|
2152
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2153
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2154
|
-
chat4appMessage.data.type = data.type;
|
|
2155
|
-
var datTmp = new Map();
|
|
2156
|
-
for (var key in data) {
|
|
2157
|
-
datTmp.set(key, data[key]);
|
|
2171
|
+
catch (e) {
|
|
2158
2172
|
}
|
|
2159
|
-
chat4appMessage.data.all = datTmp;
|
|
2160
|
-
chatCallback.onRead(chat4appMessage);
|
|
2161
2173
|
}
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2168
|
-
chat4appMessage.data.toId = data.toId;
|
|
2169
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2170
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2171
|
-
chat4appMessage.data.type = data.type;
|
|
2172
|
-
var datTmp = new Map();
|
|
2173
|
-
for (var key in data) {
|
|
2174
|
-
datTmp.set(key, data[key]);
|
|
2174
|
+
if (!ignoreOffLine && this.nc && this.chatUserExternalId && this.chatUserExternalId.length > 0 && this.getBearerToken() && this.getBearerToken().length > 0) {
|
|
2175
|
+
try {
|
|
2176
|
+
this.setOffLine(this.chatUserExternalId).toPromise();
|
|
2177
|
+
if (this.debug)
|
|
2178
|
+
console.log("had set offline");
|
|
2175
2179
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
else if (data.type == "new_user") {
|
|
2180
|
-
var chat4appMessage = new Chat4AppMessageReceive();
|
|
2181
|
-
chat4appMessage.data.chatId = data.chatId;
|
|
2182
|
-
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
2183
|
-
chat4appMessage.data.externalId = data.externalId;
|
|
2184
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2185
|
-
chat4appMessage.data.toId = data.toId;
|
|
2186
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2187
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2188
|
-
chat4appMessage.data.type = data.type;
|
|
2189
|
-
var datTmp = new Map();
|
|
2190
|
-
for (var key in data) {
|
|
2191
|
-
datTmp.set(key, data[key]);
|
|
2180
|
+
catch (e) {
|
|
2181
|
+
if (this.debug)
|
|
2182
|
+
console.error("Erro ao setar offline", e);
|
|
2192
2183
|
}
|
|
2193
|
-
chat4appMessage.data.all = datTmp;
|
|
2194
|
-
chatCallback.onNewUser(chat4appMessage);
|
|
2195
2184
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
2200
|
-
chat4appMessage.data.externalId = data.externalId;
|
|
2201
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2202
|
-
chat4appMessage.data.toId = data.toId;
|
|
2203
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2204
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2205
|
-
chat4appMessage.data.type = data.type;
|
|
2206
|
-
var datTmp = new Map();
|
|
2207
|
-
for (var key in data) {
|
|
2208
|
-
datTmp.set(key, data[key]);
|
|
2185
|
+
if (this.nc) {
|
|
2186
|
+
try {
|
|
2187
|
+
this.nc.close();
|
|
2209
2188
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
var chat4appMessage = new Chat4AppMessageReceive();
|
|
2215
|
-
chat4appMessage.data.chatId = data.chatId;
|
|
2216
|
-
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
2217
|
-
chat4appMessage.data.externalId = data.externalId;
|
|
2218
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2219
|
-
chat4appMessage.data.toId = data.toId;
|
|
2220
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2221
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2222
|
-
chat4appMessage.data.type = data.type;
|
|
2223
|
-
var datTmp = new Map();
|
|
2224
|
-
for (var key in data) {
|
|
2225
|
-
datTmp.set(key, data[key]);
|
|
2189
|
+
catch (e) {
|
|
2190
|
+
if (this.debug) {
|
|
2191
|
+
console.error(e);
|
|
2192
|
+
}
|
|
2226
2193
|
}
|
|
2227
|
-
|
|
2228
|
-
chatCallback.onChatClosed(chat4appMessage);
|
|
2194
|
+
this.nc = undefined;
|
|
2229
2195
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
chat4appMessage.data.chatId = data.chatId;
|
|
2233
|
-
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
2234
|
-
chat4appMessage.data.externalId = data.externalId;
|
|
2235
|
-
chat4appMessage.data.fromId = data.fromId;
|
|
2236
|
-
chat4appMessage.data.toId = data.toId;
|
|
2237
|
-
chat4appMessage.data.groupId = data.groupId;
|
|
2238
|
-
chat4appMessage.data.dateHour = data.dateHour;
|
|
2239
|
-
chat4appMessage.data.type = data.type;
|
|
2240
|
-
var datTmp = new Map();
|
|
2241
|
-
for (var key in data) {
|
|
2242
|
-
datTmp.set(key, data[key]);
|
|
2243
|
-
}
|
|
2244
|
-
chat4appMessage.data.all = datTmp;
|
|
2245
|
-
chatCallback.onCountNotRead(chat4appMessage);
|
|
2196
|
+
if (this.debug) {
|
|
2197
|
+
console.log("disconect");
|
|
2246
2198
|
}
|
|
2247
2199
|
};
|
|
2248
|
-
Chat4appClientAngularService.prototype.
|
|
2249
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2250
|
-
var that, uriStep1, server, _b;
|
|
2251
|
-
return __generator(this, function (_c) {
|
|
2252
|
-
switch (_c.label) {
|
|
2253
|
-
case 0:
|
|
2254
|
-
if (this.debug) {
|
|
2255
|
-
console.log("chatServer: " + this.chatServer);
|
|
2256
|
-
console.log("userId: " + chatUserExternalId);
|
|
2257
|
-
console.log("getBearerToken: " + this.getBearerToken());
|
|
2258
|
-
}
|
|
2259
|
-
that = this;
|
|
2260
|
-
uriStep1 = this.chatServer.replace(/^https/, 'wss');
|
|
2261
|
-
server = uriStep1.replace(/(\/\/.*?)\//, '$1\/ws/');
|
|
2262
|
-
if (this.debug) {
|
|
2263
|
-
console.log("ws server: " + server);
|
|
2264
|
-
}
|
|
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();
|
|
2269
|
-
_b = that;
|
|
2270
|
-
return [4 /*yield*/, nats_min.connect({ url: server, user: chatUserExternalId, pass: this.getBearerToken(), reconnect: false })];
|
|
2271
|
-
case 2:
|
|
2272
|
-
_b.nc = _c.sent();
|
|
2273
|
-
_c.label = 3;
|
|
2274
|
-
case 3:
|
|
2275
|
-
this.chatUserExternalId = chatUserExternalId;
|
|
2276
|
-
return [2 /*return*/, that.nc];
|
|
2277
|
-
}
|
|
2278
|
-
});
|
|
2279
|
-
});
|
|
2280
|
-
};
|
|
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) {
|
|
2289
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2290
|
-
var e_1, e_2;
|
|
2291
|
-
return __generator(this, function (_b) {
|
|
2292
|
-
switch (_b.label) {
|
|
2293
|
-
case 0:
|
|
2294
|
-
// Check how we can disconnect
|
|
2295
|
-
if (this.interval) {
|
|
2296
|
-
try {
|
|
2297
|
-
clearInterval(this.interval);
|
|
2298
|
-
}
|
|
2299
|
-
catch (e) {
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
if (!(!ignoreOffLine && this.nc && this.chatUserExternalId && this.chatUserExternalId.length > 0 && this.getBearerToken() && this.getBearerToken().length > 0)) return [3 /*break*/, 4];
|
|
2303
|
-
_b.label = 1;
|
|
2304
|
-
case 1:
|
|
2305
|
-
_b.trys.push([1, 3, , 4]);
|
|
2306
|
-
return [4 /*yield*/, this.setOffLine(this.chatUserExternalId).toPromise()];
|
|
2307
|
-
case 2:
|
|
2308
|
-
_b.sent();
|
|
2309
|
-
if (this.debug)
|
|
2310
|
-
console.log("had set offline");
|
|
2311
|
-
return [3 /*break*/, 4];
|
|
2312
|
-
case 3:
|
|
2313
|
-
e_1 = _b.sent();
|
|
2314
|
-
if (this.debug)
|
|
2315
|
-
console.error("Erro ao setar offline", e_1);
|
|
2316
|
-
return [3 /*break*/, 4];
|
|
2317
|
-
case 4:
|
|
2318
|
-
if (!this.nc) return [3 /*break*/, 9];
|
|
2319
|
-
_b.label = 5;
|
|
2320
|
-
case 5:
|
|
2321
|
-
_b.trys.push([5, 7, , 8]);
|
|
2322
|
-
return [4 /*yield*/, this.nc.close()];
|
|
2323
|
-
case 6:
|
|
2324
|
-
_b.sent();
|
|
2325
|
-
return [3 /*break*/, 8];
|
|
2326
|
-
case 7:
|
|
2327
|
-
e_2 = _b.sent();
|
|
2328
|
-
if (this.debug) {
|
|
2329
|
-
console.error(e_2);
|
|
2330
|
-
}
|
|
2331
|
-
return [3 /*break*/, 8];
|
|
2332
|
-
case 8:
|
|
2333
|
-
this.nc = undefined;
|
|
2334
|
-
_b.label = 9;
|
|
2335
|
-
case 9:
|
|
2336
|
-
if (this.debug) {
|
|
2337
|
-
console.log("disconect");
|
|
2338
|
-
}
|
|
2339
|
-
return [2 /*return*/];
|
|
2340
|
-
}
|
|
2341
|
-
});
|
|
2342
|
-
});
|
|
2343
|
-
};
|
|
2344
|
-
Chat4appClientAngularService.prototype.processAndCallback = function (msgObj, chatCallback) {
|
|
2200
|
+
Chat4appClientAngularService.prototype.processAndCallback = function (msgObj) {
|
|
2345
2201
|
if (this.debug && msgObj) {
|
|
2346
2202
|
console.log("Msg Received: " + JSON.stringify(msgObj));
|
|
2347
2203
|
}
|
|
@@ -2352,101 +2208,45 @@
|
|
|
2352
2208
|
}
|
|
2353
2209
|
msgObj.data.all = datTmp;
|
|
2354
2210
|
if (msgObj.data.type == "msg") {
|
|
2355
|
-
chatCallback.onMessage(msgObj);
|
|
2211
|
+
this.chatCallback.onMessage(msgObj);
|
|
2356
2212
|
}
|
|
2357
2213
|
else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
|
|
2358
|
-
chatCallback.onOffline(msgObj);
|
|
2214
|
+
this.chatCallback.onOffline(msgObj);
|
|
2359
2215
|
}
|
|
2360
2216
|
else if (msgObj.data.type == "read") {
|
|
2361
|
-
chatCallback.onRead(msgObj);
|
|
2217
|
+
this.chatCallback.onRead(msgObj);
|
|
2362
2218
|
}
|
|
2363
2219
|
else if (msgObj.data.type == "startTyping" || msgObj.data.type == "stopTyping") {
|
|
2364
|
-
chatCallback.onStartStopTyping(msgObj);
|
|
2220
|
+
this.chatCallback.onStartStopTyping(msgObj);
|
|
2365
2221
|
}
|
|
2366
2222
|
else if (msgObj.data.type == "new_user") {
|
|
2367
|
-
chatCallback.onNewUser(msgObj);
|
|
2223
|
+
this.chatCallback.onNewUser(msgObj);
|
|
2368
2224
|
}
|
|
2369
2225
|
else if (msgObj.data.type == "remove_user") {
|
|
2370
|
-
chatCallback.onRemoveUser(msgObj);
|
|
2226
|
+
this.chatCallback.onRemoveUser(msgObj);
|
|
2371
2227
|
}
|
|
2372
2228
|
else if (msgObj.data.type == "chat_closed") {
|
|
2373
|
-
chatCallback.onChatClosed(msgObj);
|
|
2229
|
+
this.chatCallback.onChatClosed(msgObj);
|
|
2374
2230
|
}
|
|
2375
2231
|
else if (msgObj.data.type == "count_notread") {
|
|
2376
|
-
chatCallback.onCountNotRead(msgObj);
|
|
2232
|
+
this.chatCallback.onCountNotRead(msgObj);
|
|
2377
2233
|
}
|
|
2378
2234
|
//}
|
|
2379
2235
|
};
|
|
2380
|
-
Chat4appClientAngularService.prototype.connectWebsocket = function (
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
that = this;
|
|
2388
|
-
this.disconnectInternal(true);
|
|
2389
|
-
securityToken = this.getBearerToken();
|
|
2390
|
-
tokenAuth = "";
|
|
2391
|
-
if (securityToken && securityToken.startsWith("Bearer ")) {
|
|
2392
|
-
tokenAuth = securityToken;
|
|
2393
|
-
}
|
|
2394
|
-
else {
|
|
2395
|
-
tokenAuth = "Bearer " + securityToken;
|
|
2396
|
-
}
|
|
2397
|
-
configId = this.chatServer.split("/")[3];
|
|
2398
|
-
return [4 /*yield*/, this.ensureConn(userId)];
|
|
2399
|
-
case 1:
|
|
2400
|
-
nc = _b.sent();
|
|
2401
|
-
subject = "chat4app.config." + configId + ".user." + userId;
|
|
2402
|
-
sub = nc.subscribe(subject, function (msg) {
|
|
2403
|
-
if (_this.debug) {
|
|
2404
|
-
console.log(msg);
|
|
2405
|
-
}
|
|
2406
|
-
_this.processAndCallback(JSON.parse(msg.data), chatCallback);
|
|
2407
|
-
});
|
|
2408
|
-
if (this.interval) {
|
|
2409
|
-
try {
|
|
2410
|
-
clearInterval(this.interval);
|
|
2411
|
-
}
|
|
2412
|
-
catch (e) {
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
that.interval = setInterval(function () {
|
|
2416
|
-
if (that.debug) {
|
|
2417
|
-
console.log("publish chat4app.user.online " + userId + " ");
|
|
2418
|
-
}
|
|
2419
|
-
try {
|
|
2420
|
-
that.nc.publish("chat4app.user.online", userId);
|
|
2421
|
-
}
|
|
2422
|
-
catch (e) {
|
|
2423
|
-
if (_this.debug) {
|
|
2424
|
-
console.log("try reconnect...");
|
|
2425
|
-
}
|
|
2426
|
-
_this.ensureConn(userId, true);
|
|
2427
|
-
}
|
|
2428
|
-
}, 1000);
|
|
2429
|
-
if (this.debug) {
|
|
2430
|
-
console.log("Subscribe online chat4app.user." + userId + ".online");
|
|
2431
|
-
}
|
|
2432
|
-
return [2 /*return*/];
|
|
2433
|
-
}
|
|
2434
|
-
});
|
|
2435
|
-
});
|
|
2436
|
-
};
|
|
2437
|
-
/*
|
|
2438
|
-
disconnect() {
|
|
2439
|
-
// console.log("disconnect")
|
|
2440
|
-
try {
|
|
2441
|
-
if (this.stompClient) {
|
|
2442
|
-
this.stompClient.disconnect();
|
|
2236
|
+
Chat4appClientAngularService.prototype.connectWebsocket = function () {
|
|
2237
|
+
var that = this;
|
|
2238
|
+
this.disconnectInternal(true);
|
|
2239
|
+
var securityToken = this.getBearerToken();
|
|
2240
|
+
var tokenAuth = "";
|
|
2241
|
+
if (securityToken && securityToken.startsWith("Bearer ")) {
|
|
2242
|
+
tokenAuth = securityToken;
|
|
2443
2243
|
}
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2244
|
+
else {
|
|
2245
|
+
tokenAuth = "Bearer " + securityToken;
|
|
2246
|
+
}
|
|
2247
|
+
this.configId = this.chatServer.split("/")[3];
|
|
2248
|
+
this.ensureConn();
|
|
2249
|
+
};
|
|
2450
2250
|
Chat4appClientAngularService.prototype.convertChat4AppMessageReceiveToChatMessage4App = function (msg) {
|
|
2451
2251
|
var _a;
|
|
2452
2252
|
var message = new ChatMessage4App();
|