@resolveio/server-lib 12.4.2 → 12.4.3
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/managers/method.manager.js +33 -37
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +90 -95
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +86 -100
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +1 -0
- package/server-app.js +139 -126
- package/server-app.js.map +1 -1
|
@@ -170,37 +170,31 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
170
170
|
_this._debugRemoveCacheHits = 0;
|
|
171
171
|
}, 60000);
|
|
172
172
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
173
|
-
var
|
|
173
|
+
var ws_1, sendItem, queueArr, mongoQueue_1, promises, _loop_1, this_1, j;
|
|
174
174
|
var _this = this;
|
|
175
175
|
return __generator(this, function (_a) {
|
|
176
176
|
if (!this._runningQueue) {
|
|
177
177
|
this._runningQueue = true;
|
|
178
178
|
if (this._sendQueue.length) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
_this.unsubscribeAll(ws);
|
|
179
|
+
// let startDate = new Date();
|
|
180
|
+
this._debugSendQueueHits += 1;
|
|
181
|
+
ws_1 = this._mainServer.getWS(this._sendQueue[this._sendQueue.length - 1].id_ws);
|
|
182
|
+
if (ws_1 && ws_1.readyState === ws_1.OPEN) {
|
|
183
|
+
if (ws_1.bufferedAmount < 20480) {
|
|
184
|
+
sendItem = this._sendQueue.pop();
|
|
185
|
+
ws_1.send(JSON.stringify(sendItem.data), function (error) {
|
|
186
|
+
if (error) {
|
|
187
|
+
console.log('Error on WS: ', error);
|
|
188
|
+
if (_this.getEnableDebug()) {
|
|
189
|
+
console.log(new Date(), 'Sub Manager', 'Unsub WS', ws_1['user'], ws_1['id_socket'], 1);
|
|
192
190
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
else {
|
|
197
|
-
this_1._sendQueue.splice(i, 1);
|
|
191
|
+
_this.unsubscribeAll(ws_1);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
198
194
|
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
for (i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
203
|
-
_loop_1(i);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this._sendQueue.splice(this._sendQueue.length - 1, 1);
|
|
204
198
|
}
|
|
205
199
|
// let endDate = new Date();
|
|
206
200
|
// this.currentPerfomanceMonitor.push({
|
|
@@ -216,71 +210,63 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
216
210
|
}
|
|
217
211
|
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
218
212
|
if (queueArr.length) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
var
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
|
|
243
|
-
return null;
|
|
244
|
-
}));
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
for (var j = 0; j < mongoQueue.subscription.clients.length; j++) {
|
|
248
|
-
_loop_3(j);
|
|
213
|
+
this._debugMongoQueueHits += 1;
|
|
214
|
+
mongoQueue_1 = queueArr[queueArr.length - 1];
|
|
215
|
+
mongoQueue_1.running = true;
|
|
216
|
+
if (!this._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })) {
|
|
217
|
+
this._debugMongoQueueCollections.push({
|
|
218
|
+
collection: mongoQueue_1.collection,
|
|
219
|
+
publication: mongoQueue_1.subscription.publication,
|
|
220
|
+
hits: 1
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })[0].hits += 1;
|
|
225
|
+
}
|
|
226
|
+
if (this._publications[mongoQueue_1.subscription.publication].user_specific) {
|
|
227
|
+
promises = [];
|
|
228
|
+
_loop_1 = function (j) {
|
|
229
|
+
var client = mongoQueue_1.subscription.clients[j];
|
|
230
|
+
var ws = this_1._mainServer.getWS(client.id_socket);
|
|
231
|
+
if (ws && ws['id_socket'] === client.id_socket) {
|
|
232
|
+
promises.push(this_1.sendDataToOne(ws, client.messageId, mongoQueue_1.subscription, mongoQueue_1.type, mongoQueue_1.collection).catch(function (err) {
|
|
233
|
+
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue_1.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
|
|
234
|
+
return null;
|
|
235
|
+
}));
|
|
249
236
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
257
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
237
|
+
};
|
|
238
|
+
this_1 = this;
|
|
239
|
+
for (j = 0; j < mongoQueue_1.subscription.clients.length; j++) {
|
|
240
|
+
_loop_1(j);
|
|
261
241
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
271
|
-
}
|
|
242
|
+
Promise.all(promises).then(function () {
|
|
243
|
+
if (mongoQueue_1.run_again) {
|
|
244
|
+
mongoQueue_1.running = false;
|
|
245
|
+
mongoQueue_1.run_again = false;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
249
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
272
250
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
this.sendDataToAll(mongoQueue_1).then(function () {
|
|
256
|
+
if (mongoQueue_1.run_again) {
|
|
257
|
+
mongoQueue_1.running = false;
|
|
258
|
+
mongoQueue_1.run_again = false;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
262
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
276
263
|
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
_loop_2(i);
|
|
264
|
+
}
|
|
265
|
+
}, function () {
|
|
266
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
267
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
284
270
|
}
|
|
285
271
|
// let endDate = new Date();
|
|
286
272
|
// this.currentPerfomanceMonitor.push({
|
|
@@ -300,7 +286,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
300
286
|
});
|
|
301
287
|
}); }, 50);
|
|
302
288
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
303
|
-
var _a, userCopy,
|
|
289
|
+
var _a, userCopy, _loop_2, this_2, i, i, sub, _loop_3, this_3, j;
|
|
304
290
|
return __generator(this, function (_b) {
|
|
305
291
|
switch (_b.label) {
|
|
306
292
|
case 0:
|
|
@@ -309,17 +295,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
309
295
|
case 1:
|
|
310
296
|
_a._loggedInUsers = _b.sent();
|
|
311
297
|
userCopy = common_1.deepCopy(this._loggedInUsers);
|
|
312
|
-
|
|
298
|
+
_loop_2 = function (i) {
|
|
313
299
|
var loggedInUser = userCopy[i];
|
|
314
300
|
if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
|
|
315
|
-
if (
|
|
316
|
-
if (
|
|
317
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS',
|
|
301
|
+
if (this_2._mainServer.getWS(loggedInUser.id_ws)) {
|
|
302
|
+
if (this_2.getEnableDebug()) {
|
|
303
|
+
console.log(new Date(), 'Sub Manager', 'Unsub WS', this_2._mainServer.getWS(loggedInUser.id_ws)['user'], this_2._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);
|
|
318
304
|
}
|
|
319
|
-
|
|
305
|
+
this_2.unsubscribeAll(this_2._mainServer.getWS(loggedInUser.id_ws));
|
|
320
306
|
}
|
|
321
307
|
else {
|
|
322
|
-
|
|
308
|
+
this_2._subscriptions.forEach(function (sub) {
|
|
323
309
|
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
324
310
|
var client = sub.clients[j];
|
|
325
311
|
if (client.id_socket === loggedInUser.id_ws) {
|
|
@@ -328,27 +314,27 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
328
314
|
}
|
|
329
315
|
});
|
|
330
316
|
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
331
|
-
if (
|
|
332
|
-
|
|
317
|
+
if (this_2._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }) >= 0) {
|
|
318
|
+
this_2._loggedInUsers.splice(this_2._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }), 1);
|
|
333
319
|
}
|
|
334
320
|
}
|
|
335
321
|
}
|
|
336
322
|
};
|
|
337
|
-
|
|
323
|
+
this_2 = this;
|
|
338
324
|
for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
|
|
339
|
-
|
|
325
|
+
_loop_2(i);
|
|
340
326
|
}
|
|
341
327
|
for (i = 0; i < this._subscriptions.length; i++) {
|
|
342
328
|
sub = this._subscriptions[i];
|
|
343
|
-
|
|
329
|
+
_loop_3 = function (j) {
|
|
344
330
|
var client = sub.clients[j];
|
|
345
|
-
if (!
|
|
331
|
+
if (!this_3._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
|
|
346
332
|
sub.clients.splice(j, 1);
|
|
347
333
|
}
|
|
348
334
|
};
|
|
349
|
-
|
|
335
|
+
this_3 = this;
|
|
350
336
|
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
351
|
-
|
|
337
|
+
_loop_3(j);
|
|
352
338
|
}
|
|
353
339
|
}
|
|
354
340
|
return [2 /*return*/];
|