chat4app-client-angular 1.0.17 → 1.0.19
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 +45 -50
- 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 +46 -51
- package/fesm2015/chat4app-client-angular.js +45 -50
- package/fesm2015/chat4app-client-angular.js.map +1 -1
- package/lib/chat4app-client-angular.service.d.ts +2 -4
- package/lib/chat4app-client-angular.service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1779,7 +1779,7 @@
|
|
|
1779
1779
|
this.debug = false;
|
|
1780
1780
|
this.chatUserExternalId = "";
|
|
1781
1781
|
this.configId = "";
|
|
1782
|
-
this.
|
|
1782
|
+
this.isConnected = false;
|
|
1783
1783
|
}
|
|
1784
1784
|
Chat4appClientAngularService.prototype.ngOnInit = function () {
|
|
1785
1785
|
};
|
|
@@ -1804,7 +1804,7 @@
|
|
|
1804
1804
|
if (chatCallback && connectionClientId) {
|
|
1805
1805
|
_this.chatUserExternalId = connectionClientId;
|
|
1806
1806
|
_this.chatCallback = chatCallback;
|
|
1807
|
-
_this.
|
|
1807
|
+
_this.setIntervalConnection();
|
|
1808
1808
|
}
|
|
1809
1809
|
subscriber.next(securityChatToken);
|
|
1810
1810
|
subscriber.complete();
|
|
@@ -2104,39 +2104,50 @@
|
|
|
2104
2104
|
};
|
|
2105
2105
|
Chat4appClientAngularService.prototype.ensureConn = function () {
|
|
2106
2106
|
var _this = this;
|
|
2107
|
-
if (this.
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
var
|
|
2123
|
-
|
|
2107
|
+
if (!this.isConnected) {
|
|
2108
|
+
var that_1 = this;
|
|
2109
|
+
this.configId = this.chatServer.split("/")[3];
|
|
2110
|
+
if (this.debug) {
|
|
2111
|
+
console.log("chatServer: " + this.chatServer);
|
|
2112
|
+
console.log("userId: " + this.chatUserExternalId);
|
|
2113
|
+
console.log("getBearerToken: " + this.getBearerToken());
|
|
2114
|
+
}
|
|
2115
|
+
try {
|
|
2116
|
+
if (this.nc) {
|
|
2117
|
+
this.nc.close();
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
catch (e) {
|
|
2121
|
+
}
|
|
2122
|
+
var uriStep1 = this.chatServer.replace(/^https/, 'wss');
|
|
2123
|
+
var server = uriStep1.replace(/(\/\/.*?)\//, '$1\/ws/');
|
|
2124
|
+
if (this.debug) {
|
|
2125
|
+
console.log("ws server: " + server);
|
|
2126
|
+
}
|
|
2127
|
+
nats_min.connect({ url: server, user: this.chatUserExternalId, pass: this.getBearerToken(), reconnect: false })
|
|
2128
|
+
.then(function (nc) {
|
|
2129
|
+
that_1.nc = nc;
|
|
2130
|
+
that_1.isConnected = true;
|
|
2131
|
+
var subject = "chat4app.config." + _this.configId + ".user." + _this.chatUserExternalId;
|
|
2132
|
+
that_1.nc.subscribe(subject, function (msg) {
|
|
2133
|
+
if (_this.debug) {
|
|
2134
|
+
console.log(msg);
|
|
2135
|
+
}
|
|
2136
|
+
_this.processAndCallback(JSON.parse(msg.data));
|
|
2137
|
+
});
|
|
2124
2138
|
if (_this.debug) {
|
|
2125
|
-
console.log(
|
|
2139
|
+
console.log("Subscribe online chat4app.user." + _this.chatUserExternalId + ".online");
|
|
2126
2140
|
}
|
|
2127
|
-
|
|
2141
|
+
})
|
|
2142
|
+
.catch(function (err) {
|
|
2143
|
+
// Notifica o chamador sobre o erro na conexão
|
|
2144
|
+
console.log("NATS Error:");
|
|
2145
|
+
console.log(err);
|
|
2146
|
+
that_1.isConnected = false;
|
|
2128
2147
|
});
|
|
2129
|
-
|
|
2130
|
-
if (_this.debug) {
|
|
2131
|
-
console.log("Subscribe online chat4app.user." + _this.chatUserExternalId + ".online");
|
|
2132
|
-
}
|
|
2133
|
-
})
|
|
2134
|
-
.catch(function (err) {
|
|
2135
|
-
// Notifica o chamador sobre o erro na conexão
|
|
2136
|
-
console.error("NATS Error:", err);
|
|
2137
|
-
});
|
|
2148
|
+
}
|
|
2138
2149
|
};
|
|
2139
|
-
Chat4appClientAngularService.prototype.
|
|
2150
|
+
Chat4appClientAngularService.prototype.setIntervalConnection = function () {
|
|
2140
2151
|
var _this = this;
|
|
2141
2152
|
if (this.interval) {
|
|
2142
2153
|
try {
|
|
@@ -2146,6 +2157,7 @@
|
|
|
2146
2157
|
}
|
|
2147
2158
|
}
|
|
2148
2159
|
this.interval = setInterval(function () {
|
|
2160
|
+
_this.ensureConn();
|
|
2149
2161
|
if (_this.debug) {
|
|
2150
2162
|
console.log("publish chat4app.user.online " + _this.chatUserExternalId + " ");
|
|
2151
2163
|
}
|
|
@@ -2153,17 +2165,14 @@
|
|
|
2153
2165
|
_this.nc.publish("chat4app.user.online", _this.chatUserExternalId);
|
|
2154
2166
|
}
|
|
2155
2167
|
catch (e) {
|
|
2168
|
+
_this.isConnected = false;
|
|
2156
2169
|
if (_this.debug) {
|
|
2157
2170
|
console.log("try reconnect...");
|
|
2158
2171
|
}
|
|
2159
|
-
_this.ensureConn();
|
|
2160
2172
|
}
|
|
2161
2173
|
}, 1000);
|
|
2162
2174
|
};
|
|
2163
2175
|
Chat4appClientAngularService.prototype.disconnect = function () {
|
|
2164
|
-
return this.disconnectInternal(false);
|
|
2165
|
-
};
|
|
2166
|
-
Chat4appClientAngularService.prototype.disconnectInternal = function (ignoreOffLine) {
|
|
2167
2176
|
// Check how we can disconnect
|
|
2168
2177
|
if (this.interval) {
|
|
2169
2178
|
try {
|
|
@@ -2172,7 +2181,7 @@
|
|
|
2172
2181
|
catch (e) {
|
|
2173
2182
|
}
|
|
2174
2183
|
}
|
|
2175
|
-
if (
|
|
2184
|
+
if (this.nc && this.chatUserExternalId && this.chatUserExternalId.length > 0 && this.getBearerToken() && this.getBearerToken().length > 0) {
|
|
2176
2185
|
try {
|
|
2177
2186
|
this.setOffLine(this.chatUserExternalId).toPromise();
|
|
2178
2187
|
if (this.debug)
|
|
@@ -2234,20 +2243,6 @@
|
|
|
2234
2243
|
}
|
|
2235
2244
|
//}
|
|
2236
2245
|
};
|
|
2237
|
-
Chat4appClientAngularService.prototype.connectWebsocket = function () {
|
|
2238
|
-
var that = this;
|
|
2239
|
-
this.disconnectInternal(true);
|
|
2240
|
-
var securityToken = this.getBearerToken();
|
|
2241
|
-
var tokenAuth = "";
|
|
2242
|
-
if (securityToken && securityToken.startsWith("Bearer ")) {
|
|
2243
|
-
tokenAuth = securityToken;
|
|
2244
|
-
}
|
|
2245
|
-
else {
|
|
2246
|
-
tokenAuth = "Bearer " + securityToken;
|
|
2247
|
-
}
|
|
2248
|
-
this.configId = this.chatServer.split("/")[3];
|
|
2249
|
-
this.ensureConn();
|
|
2250
|
-
};
|
|
2251
2246
|
Chat4appClientAngularService.prototype.convertChat4AppMessageReceiveToChatMessage4App = function (msg) {
|
|
2252
2247
|
var _a;
|
|
2253
2248
|
var message = new ChatMessage4App();
|