@resolveio/server-lib 12.4.7 → 12.4.9
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/subscription.manager.js +117 -67
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +5 -3
- package/server-app.js +30 -16
- package/server-app.js.map +1 -1
|
@@ -170,7 +170,7 @@ 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 _loop_1, this_1, i, queueArr, _loop_2, this_2,
|
|
173
|
+
var _loop_1, this_1, i, queueArr, mongoQueue_1, promises, _loop_2, this_2, j;
|
|
174
174
|
var _this = this;
|
|
175
175
|
return __generator(this, function (_a) {
|
|
176
176
|
if (!this._runningQueue) {
|
|
@@ -216,71 +216,121 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
216
216
|
}
|
|
217
217
|
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
218
218
|
if (queueArr.length) {
|
|
219
|
-
queueArr.forEach(
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
219
|
+
// queueArr.forEach(entry => {
|
|
220
|
+
// entry.running = true;
|
|
221
|
+
// });
|
|
222
|
+
// for (let i = queueArr.length - 1; i >= 0; i--) {
|
|
223
|
+
// this._debugMongoQueueHits += 1;
|
|
224
|
+
// let mongoQueue = queueArr[i];
|
|
225
|
+
// if (!this._debugMongoQueueCollections.some(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)) {
|
|
226
|
+
// this._debugMongoQueueCollections.push({
|
|
227
|
+
// collection: mongoQueue.collection,
|
|
228
|
+
// publication: mongoQueue.subscription.publication,
|
|
229
|
+
// hits: 1
|
|
230
|
+
// });
|
|
231
|
+
// }
|
|
232
|
+
// else {
|
|
233
|
+
// this._debugMongoQueueCollections.filter(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)[0].hits += 1;
|
|
234
|
+
// }
|
|
235
|
+
// if (this._publications[mongoQueue.subscription.publication].user_specific) {
|
|
236
|
+
// let promises = [];
|
|
237
|
+
// for (let j = 0; j < mongoQueue.subscription.clients.length; j++) {
|
|
238
|
+
// let client = mongoQueue.subscription.clients[j];
|
|
239
|
+
// let ws = this._mainServer.getWS(client.id_socket);
|
|
240
|
+
// if (ws && ws['id_socket'] === client.id_socket) {
|
|
241
|
+
// promises.push(this.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch((err) => {
|
|
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
|
+
// Promise.all(promises).then(() => {
|
|
248
|
+
// if (mongoQueue.run_again) {
|
|
249
|
+
// mongoQueue.running = false;
|
|
250
|
+
// mongoQueue.run_again = false;
|
|
251
|
+
// }
|
|
252
|
+
// else {
|
|
253
|
+
// if (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {
|
|
254
|
+
// this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
|
|
255
|
+
// }
|
|
256
|
+
// }
|
|
257
|
+
// });
|
|
258
|
+
// }
|
|
259
|
+
// else {
|
|
260
|
+
// this.sendDataToAll(mongoQueue).then(() => {
|
|
261
|
+
// if (mongoQueue.run_again) {
|
|
262
|
+
// mongoQueue.running = false;
|
|
263
|
+
// mongoQueue.run_again = false;
|
|
264
|
+
// }
|
|
265
|
+
// else {
|
|
266
|
+
// if (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {
|
|
267
|
+
// this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
|
|
268
|
+
// }
|
|
269
|
+
// }
|
|
270
|
+
// }, () => {
|
|
271
|
+
// if (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {
|
|
272
|
+
// this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
|
|
273
|
+
// }
|
|
274
|
+
// });
|
|
275
|
+
// }
|
|
276
|
+
// }
|
|
277
|
+
this._debugMongoQueueHits += 1;
|
|
278
|
+
mongoQueue_1 = queueArr[queueArr.length - 1];
|
|
279
|
+
mongoQueue_1.running = true;
|
|
280
|
+
if (!this._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })) {
|
|
281
|
+
this._debugMongoQueueCollections.push({
|
|
282
|
+
collection: mongoQueue_1.collection,
|
|
283
|
+
publication: mongoQueue_1.subscription.publication,
|
|
284
|
+
hits: 1
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
this._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })[0].hits += 1;
|
|
289
|
+
}
|
|
290
|
+
if (this._publications[mongoQueue_1.subscription.publication].user_specific) {
|
|
291
|
+
promises = [];
|
|
292
|
+
_loop_2 = function (j) {
|
|
293
|
+
var client = mongoQueue_1.subscription.clients[j];
|
|
294
|
+
var ws = this_2._mainServer.getWS(client.id_socket);
|
|
295
|
+
if (ws && ws['id_socket'] === client.id_socket) {
|
|
296
|
+
promises.push(this_2.sendDataToOne(ws, client.messageId, mongoQueue_1.subscription, mongoQueue_1.type, mongoQueue_1.collection).catch(function (err) {
|
|
297
|
+
_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));
|
|
298
|
+
return null;
|
|
299
|
+
}));
|
|
249
300
|
}
|
|
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
|
-
});
|
|
301
|
+
};
|
|
302
|
+
this_2 = this;
|
|
303
|
+
for (j = 0; j < mongoQueue_1.subscription.clients.length; j++) {
|
|
304
|
+
_loop_2(j);
|
|
261
305
|
}
|
|
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
|
-
}
|
|
306
|
+
Promise.all(promises).then(function () {
|
|
307
|
+
if (mongoQueue_1.run_again) {
|
|
308
|
+
mongoQueue_1.running = false;
|
|
309
|
+
mongoQueue_1.run_again = false;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
313
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
272
314
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
this.sendDataToAll(mongoQueue_1).then(function () {
|
|
320
|
+
if (mongoQueue_1.run_again) {
|
|
321
|
+
mongoQueue_1.running = false;
|
|
322
|
+
mongoQueue_1.run_again = false;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
326
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
276
327
|
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
_loop_2(i);
|
|
328
|
+
}
|
|
329
|
+
}, function () {
|
|
330
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
331
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
284
334
|
}
|
|
285
335
|
// let endDate = new Date();
|
|
286
336
|
// this.currentPerfomanceMonitor.push({
|
|
@@ -300,7 +350,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
300
350
|
});
|
|
301
351
|
}); }, 25);
|
|
302
352
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
303
|
-
var _a, userCopy,
|
|
353
|
+
var _a, userCopy, _loop_3, this_3, i, i, sub, _loop_4, this_4, j;
|
|
304
354
|
return __generator(this, function (_b) {
|
|
305
355
|
switch (_b.label) {
|
|
306
356
|
case 0:
|
|
@@ -309,7 +359,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
309
359
|
case 1:
|
|
310
360
|
_a._loggedInUsers = _b.sent();
|
|
311
361
|
userCopy = common_1.deepCopy(this._loggedInUsers);
|
|
312
|
-
|
|
362
|
+
_loop_3 = function (i) {
|
|
313
363
|
var loggedInUser = userCopy[i];
|
|
314
364
|
if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
|
|
315
365
|
if (this_3._mainServer.getWS(loggedInUser.id_ws)) {
|
|
@@ -336,11 +386,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
336
386
|
};
|
|
337
387
|
this_3 = this;
|
|
338
388
|
for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
|
|
339
|
-
|
|
389
|
+
_loop_3(i);
|
|
340
390
|
}
|
|
341
391
|
for (i = 0; i < this._subscriptions.length; i++) {
|
|
342
392
|
sub = this._subscriptions[i];
|
|
343
|
-
|
|
393
|
+
_loop_4 = function (j) {
|
|
344
394
|
var client = sub.clients[j];
|
|
345
395
|
if (!this_4._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
|
|
346
396
|
sub.clients.splice(j, 1);
|
|
@@ -348,7 +398,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
348
398
|
};
|
|
349
399
|
this_4 = this;
|
|
350
400
|
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
351
|
-
|
|
401
|
+
_loop_4(j);
|
|
352
402
|
}
|
|
353
403
|
}
|
|
354
404
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,6CAA2D;AAC3D,yDAAuE;AACvE,+CAA6D;AAC7D,2DAAyE;AACzE,wFAA0E;AAC1E,uD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ACJ,CAAC;IAEO,oCAAM,GAAd,UAAe,EAAa,EAAE,IAAyB;QACtD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE;YAC5B,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC;YACtB,IAAI,EAAE,IAAI;SACV,CAAC,CAAC;IACJ,CAAC;IAEM,4CAAc,GAArB;QACC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACF,0BAAC;AAAD,CAlnCA,AAknCC,IAAA;AAlnCY,kDAAmB","file":"subscription.manager.js","sourcesContent":["import { ServerResponseModel } from '../models/server-response.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport * as WebSocket from 'ws';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadFilePublications } from '../publications/files';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadMethodResponsePublications } from '../publications/method-responses';\nimport ResolveIOMainServer from '../server-app';\nimport { ResolveIOServer } from '../index';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\n\nimport { ChangeStream, ResumeToken } from 'mongodb';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { objectIdHexString } from './mongo.manager';\nimport { dateReviver, deepCopy } from '../util/common';\nimport * as NodeCache from 'node-cache';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { Flags } from '../collections/flag.collection';\nimport { cpus } from 'os';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\t\n\tprivate _oplog: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate serverConfig;\n\n\tprivate _heapStats = v8.getHeapStatistics();\n\tprivate _heapLimit = this._heapStats.heap_size_limit / numCPUs / 8;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tconstructor(mainServer, wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadMethodResponsePublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tthis.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tthis._runningQueue = true;\n\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\t// let startDate = new Date();\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugSendQueueHits += 1;\n\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.data), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._sendQueue.splice(i, 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendInterval',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\n\n\t\t\t\tconst queueArr = this._mongoQueue.filter(a => !a.running);\n\t\t\t\tif (queueArr.length) {\n\t\t\t\t\tqueueArr.forEach(entry => {\n\t\t\t\t\t\tentry.running = true;\n\t\t\t\t\t});\n\n\t\t\t\t\t// let startDate = new Date();\n\n\t\t\t\t\tfor (let i = queueArr.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugMongoQueueHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tlet mongoQueue = queueArr[i];\n\n\t\t\t\t\t\tif (!this._debugMongoQueueCollections.some(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)) {\n\t\t\t\t\t\t\tthis._debugMongoQueueCollections.push({\n\t\t\t\t\t\t\t\tcollection: mongoQueue.collection,\n\t\t\t\t\t\t\t\tpublication: mongoQueue.subscription.publication,\n\t\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._debugMongoQueueCollections.filter(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)[0].hits += 1;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this._publications[mongoQueue.subscription.publication].user_specific) {\n\t\t\t\t\t\t\tlet promises = [];\n\t\t\t\t\t\t\tfor (let j = 0; j < mongoQueue.subscription.clients.length; j++) {\n\t\t\t\t\t\t\t\tlet client = mongoQueue.subscription.clients[j];\n\t\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\t\t\t\t\t\t\t\tif (ws && ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\t\tpromises.push(this.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch((err) => {\n\t\t\t\t\t\t\t\t\t\tthis._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));\n\t\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tPromise.all(promises).then(() => {\n\t\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis.sendDataToAll(mongoQueue).then(() => {\n\t\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, () => {\n\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'mongoQueue',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\t\n\n\t\t\t\tthis._runningQueue = false;\n\t\t\t}\n\t\t}, 25);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._mainServer.getWS(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._mainServer.getWS(loggedInUser.id_ws)['user'], this._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.unsubscribeAll(this._mainServer.getWS(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addToQueue(mongoQueue: MongoQueueModel) {\n\t\t// let startDate = new Date();\n\n\t\tlet _mongoQueue = this._mongoQueue.filter(a => a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData))[0];\n\t\t\n\t\tif (_mongoQueue) {\n\t\t\tif (_mongoQueue.running) {\n\t\t\t\t_mongoQueue.run_again = true;\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'addToQueue',\n\t\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Run Again'\n\t\t\t\t// });\n\t\t\t}\n\t\t\t// else {\n\t\t\t// \tlet endDate = new Date();\n\t\t\t// \tthis.currentPerfomanceMonitor.push({\n\t\t\t// \t\t_id: this.idPerformance++,\n\t\t\t// \t\tfunction: 'addToQueue',\n\t\t\t// \t\tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \t\tsubscriptionData: [],\n\t\t\t// \t\tdate_start: startDate,\n\t\t\t// \t\tdate_end: endDate,\n\t\t\t// \t\tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \t\tresult: 'Not Running Yet'\n\t\t\t// \t});\n\t\t\t// }\n\t\t}\n\t\telse {\n\t\t\tmongoQueue._id = this._mongoQueueId;\n\t\t\tthis._mongoQueueId += 1;\n\n\t\t\tthis._mongoQueue.splice(0, 0, mongoQueue);\n\t\t\t\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'addToQueue',\n\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Add to Queue'\n\t\t\t// });\n\t\t}\n\t}\n\n\tpublic invalidatePubsCache(collection, type) {\n\t\t// let startDate = new Date();\n\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\t\t\n\t\tlet collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\n\t\tfor (let i = collSubs.length - 1; i >= 0; i--) {\n\t\t\tlet sub = collSubs[i];\n\t\t\t\n\t\t\tthis.addToQueue({\n\t\t\t\t_id: 0,\n\t\t\t\ttype: type,\n\t\t\t\tcollection: collection,\n\t\t\t\tsubscription: sub,\n\t\t\t\trunning: false,\n\t\t\t\trun_again: false\n\t\t\t});\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'invalidatePubsCache',\n\t\t// \tpublication: collection,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.filter(a => a.id_ws === ws['id_socket'])[0];\n\n\t\tif (loggedInUser) {\n\t\t\tloggedInUser.date = new Date();\n\n\t\t\tLoggedInUsers.updateOne({id_ws: ws['id_socket']}, {$set: {latency: ws['latency'], date: loggedInUser.date}}).then(res => {\n\t\t\t\tif (!res) {\n\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {\n\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\t// let startDate = new Date();\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.filter(a => a.publication === publication)[0].hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\t\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\t\t\t\t\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\t\t\t\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionData: subscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\t\t\t}\n\n\t\t\tif (!sub.cacheId && !this._mongoQueue.some(a => a.subscription.publication === sub.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub.subscriptionData))) {\n\t\t\t\tthis.addToQueue({\n\t\t\t\t\t_id: 0,\n\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tsubscription: sub,\n\t\t\t\t\trunning: false,\n\t\t\t\t\trun_again: false\n\t\t\t\t});\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Add to Queue'\n\t\t\t\t// });\n\t\t\t}\n\t\t\telse if (sub.cacheId) {\n\t\t\t\tthis.sendDataToOne(ws, messageId, sub, 'newSub', publication);\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Send Pub Data Once'\n\t\t\t\t// });\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet ws = this._mainServer.getWS(id_ws);\n\n\t\t\tif (ws) {\n\t\t\t\tlet user = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tid_ws: ws['id_socket']\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tthis._loggedInUsers.push(user);\n\t\t\t\tLoggedInUsers.insertOne(user);\n\t\t\t\t\n\t\t\t\tresolve(user);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t});\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugUnSubHits += 1;\n\t\t// let startDate = new Date();\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'unsubscribe',\n\t\t// \tpublication: publication,\n\t\t// // \tsubscriptionData: subscriptionData,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\t// let startDate = new Date();\n\n\t\tif (ws) {\n\t\t\tlet loggedInUser = await LoggedInUsers.findOne({id_ws: ws['id_socket']});\n\n\t\t\tif (loggedInUser) {\t\n\t\t\t\tif (this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id) >= 0) {\n\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id), 1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\t\t\t}\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tws.close();\n\n\t\t\tprocess.nextTick(() => {\n\t\t\t\tif ([ws.OPEN, ws.CLOSING].includes(<any>ws.readyState)) {\n\t\t\t\t\t// Socket still hangs, hard close\n\t\t\t\t\tws.terminate();\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'unsubscribeAll',\n\t\t\t// \tpublication: '',\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Done'\n\t\t\t// });\n\t\t}\n\n\t\t// console.log('After');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (!this._oplog || this._oplog.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 10) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************')\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch([], {resumeAfter: resumeToken});\n\t\t\t\t}\n\t\t\t\tcatch(errOp) {\n\t\t\t\t\tif (this._oplog && !this._oplog.closed) {\n\t\t\t\t\t\tthis._oplog.close();\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch();\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog.on('change', doc => {\n\t\t\t\t// let startDate = new Date();\n\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.filter(a => a.collection === doc.ns.coll && a.type === doc.operationType)[0].hits += 1;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// console.log(new Date(), 'Op log doc', doc.operationType, collection);\n\n\t\t\t\t\tif (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Insert'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'update');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Update'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'delete');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Delete'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tthis._oplog.on('error', error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tthis._oplog.close();\n\t\t\t});\n\n\t\t\tthis._oplog.on('end', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tthis._oplog.close();\n\t\t\t});\n\n\t\t\tthis._oplog.on('close', () => {\n\t\t\t\tthis._oplog = null;\n\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._oplog.close();\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToOne(ws: WebSocket, messageId: number, subscription: ActiveSubscriptionModel, type: string, collection: string) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\n\t\t\tif (!this._publications[subscription.publication].user_specific) { // Same pub for all users\n\t\t\t\tif (subscription.cacheId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(subscription.cacheId), dateReviver);\n\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t\t};\n\t\n\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t}\n\t\t\t\t\tcatch(err) {\n\t\t\t\t\t\tthis._nodeCache.del(subscription.cacheId);\n\t\t\t\t\t\tsubscription.cacheId = 0;\n\n\t\t\t\t\t\tthis.addToQueue({\n\t\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\t\trunning: false,\n\t\t\t\t\t\t\trun_again: false\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send cache'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - No Cache! - ' + subscription.publication + '\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2));\n\n\t\t\t\t\tresolve(false);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);\n\t\t\t\tthis._publications[subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: res\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send ws spec data'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\t\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\tdata: err\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToAll(mongoQueue: MongoQueueModel) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\t\t\tif (!mongoQueue.subscription.clients.length) {\t\t\t\t\n\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t}\n\n\t\t\t\tif (this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)) >= 0) {\n\t\t\t\t\tthis._subscriptions.splice(this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)), 1);\n\t\t\t\t}\n\n\t\t\t\tresolve(false);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {\n\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));\n\t\t\t\t}\n\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);\n\t\t\t\tthis._publications[mongoQueue.subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...mongoQueue.subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tif (!mongoQueue.subscription.clients.length) {\n\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\n\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\n\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\n\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t// \tresult: 'No clients'\n\t\t\t\t\t\t// });\n\n\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!mongoQueue.subscription.cacheId || this._nodeCache.get(mongoQueue.subscription.cacheId) !== JSON.stringify(res)) {\n\t\t\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\n\t\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\n\t\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\n\t\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\t\n\t\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Same data'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + mongoQueue.subscription.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(mongoQueue.subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\tif (ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._sendQueue.splice(0, 0, {\n\t\t\tid_ws: ws['id_socket'],\n\t\t\tdata: data\n\t\t});\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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,WAAW,GAAG,6BAA6B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;wBAErW,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,UAAA,MAAM;4BAC7C,IAAI,EAAE,GAAG,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;4BAElD,IAAI,EAAE,EAAE;gCACP,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,MAAM,CAAC,SAAS,EAAE;oCACzC,IAAI,SAAS,GAAwB;wCACpC,SAAS,EAAE,MAAM,CAAC,SAAS;wCAC3B,QAAQ,EAAE,IAAI;wCACd,IAAI,EAAE,GAAG;qCACT,CAAC;oCAEF,KAAI,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;iCAC3B;6BACD;wBACF,CAAC,CAAC,CAAC;wBAEH,MAAM,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC,CAAC,CAAC;iBACH;;;aACD,CAAC,CAAC;IACJ,CAAC;IAEO,oCAAM,GAAd,UAAe,EAAa,EAAE,IAAyB;QACtD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE;YAC5B,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC;YACtB,IAAI,EAAE,IAAI;SACV,CAAC,CAAC;IACJ,CAAC;IAEM,4CAAc,GAArB;QACC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IACF,0BAAC;AAAD,CA3qCA,AA2qCC,IAAA;AA3qCY,kDAAmB","file":"subscription.manager.js","sourcesContent":["import { ServerResponseModel } from '../models/server-response.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport * as WebSocket from 'ws';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadFilePublications } from '../publications/files';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadMethodResponsePublications } from '../publications/method-responses';\nimport ResolveIOMainServer from '../server-app';\nimport { ResolveIOServer } from '../index';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\n\nimport { ChangeStream, ResumeToken } from 'mongodb';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { objectIdHexString } from './mongo.manager';\nimport { dateReviver, deepCopy } from '../util/common';\nimport * as NodeCache from 'node-cache';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { Flags } from '../collections/flag.collection';\nimport { cpus } from 'os';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\t\n\tprivate _oplog: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate serverConfig;\n\n\tprivate _heapStats = v8.getHeapStatistics();\n\tprivate _heapLimit = this._heapStats.heap_size_limit / numCPUs / 8;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tconstructor(mainServer, wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadMethodResponsePublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tthis.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tthis._runningQueue = true;\n\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\t// let startDate = new Date();\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugSendQueueHits += 1;\n\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.data), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._sendQueue.splice(i, 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendInterval',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\n\n\t\t\t\tconst queueArr = this._mongoQueue.filter(a => !a.running);\n\t\t\t\tif (queueArr.length) {\n\t\t\t\t\t// queueArr.forEach(entry => {\n\t\t\t\t\t// \tentry.running = true;\n\t\t\t\t\t// });\n\n\t\t\t\t\t// for (let i = queueArr.length - 1; i >= 0; i--) {\n\t\t\t\t\t// \tthis._debugMongoQueueHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t// \tlet mongoQueue = queueArr[i];\n\n\t\t\t\t\t// \tif (!this._debugMongoQueueCollections.some(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)) {\n\t\t\t\t\t// \t\tthis._debugMongoQueueCollections.push({\n\t\t\t\t\t// \t\t\tcollection: mongoQueue.collection,\n\t\t\t\t\t// \t\t\tpublication: mongoQueue.subscription.publication,\n\t\t\t\t\t// \t\t\thits: 1\n\t\t\t\t\t// \t\t});\n\t\t\t\t\t// \t}\n\t\t\t\t\t// \telse {\n\t\t\t\t\t// \t\tthis._debugMongoQueueCollections.filter(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)[0].hits += 1;\n\t\t\t\t\t// \t}\n\n\t\t\t\t\t// \tif (this._publications[mongoQueue.subscription.publication].user_specific) {\n\t\t\t\t\t// \t\tlet promises = [];\n\t\t\t\t\t// \t\tfor (let j = 0; j < mongoQueue.subscription.clients.length; j++) {\n\t\t\t\t\t// \t\t\tlet client = mongoQueue.subscription.clients[j];\n\t\t\t\t\t// \t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\t\t\t\t\t// \t\t\tif (ws && ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t// \t\t\t\tpromises.push(this.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch((err) => {\n\t\t\t\t\t// \t\t\t\t\tthis._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));\n\t\t\t\t\t// \t\t\t\t\treturn null;\n\t\t\t\t\t// \t\t\t\t}));\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}\n\n\t\t\t\t\t// \t\tPromise.all(promises).then(() => {\n\t\t\t\t\t// \t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t// \t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t// \t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t\telse {\n\t\t\t\t\t// \t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t// \t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t// \t\t\t\t}\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t});\n\t\t\t\t\t// \t}\n\t\t\t\t\t// \telse {\n\t\t\t\t\t// \t\tthis.sendDataToAll(mongoQueue).then(() => {\n\t\t\t\t\t// \t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t// \t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t// \t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t\telse {\n\t\t\t\t\t// \t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t// \t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t// \t\t\t\t}\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t}, () => {\n\t\t\t\t\t// \t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t// \t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t// \t\t\t}\n\t\t\t\t\t// \t\t});\n\t\t\t\t\t// \t}\n\t\t\t\t\t// }\n\n\t\t\t\t\tthis._debugMongoQueueHits += 1;\n\t\t\t\t\t\n\t\t\t\t\tlet mongoQueue = queueArr[queueArr.length - 1];\n\t\t\t\t\tmongoQueue.running = true;\n\n\t\t\t\t\tif (!this._debugMongoQueueCollections.some(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)) {\n\t\t\t\t\t\tthis._debugMongoQueueCollections.push({\n\t\t\t\t\t\t\tcollection: mongoQueue.collection,\n\t\t\t\t\t\t\tpublication: mongoQueue.subscription.publication,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugMongoQueueCollections.filter(a => a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication)[0].hits += 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._publications[mongoQueue.subscription.publication].user_specific) {\n\t\t\t\t\t\tlet promises = [];\n\t\t\t\t\t\tfor (let j = 0; j < mongoQueue.subscription.clients.length; j++) {\n\t\t\t\t\t\t\tlet client = mongoQueue.subscription.clients[j];\n\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\t\t\t\t\t\t\tif (ws && ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\tpromises.push(this.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch((err) => {\n\t\t\t\t\t\t\t\t\tthis._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));\n\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tPromise.all(promises).then(() => {\n\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.sendDataToAll(mongoQueue).then(() => {\n\t\t\t\t\t\t\tif (mongoQueue.run_again) {\n\t\t\t\t\t\t\t\tmongoQueue.running = false;\n\t\t\t\t\t\t\t\tmongoQueue.run_again = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, () => {\n\t\t\t\t\t\t\tif (this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id) >= 0) {\n\t\t\t\t\t\t\t\tthis._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'mongoQueue',\n\t\t\t\t\t// \tpublication: '',\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Done'\n\t\t\t\t\t// });\n\t\t\t\t}\t\n\n\t\t\t\tthis._runningQueue = false;\n\t\t\t}\n\t\t}, 25);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._mainServer.getWS(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._mainServer.getWS(loggedInUser.id_ws)['user'], this._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.unsubscribeAll(this._mainServer.getWS(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\tif (flag && flag.value) {\n\t\t\t\tthis._enableDebug = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._enableDebug = false;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addToQueue(mongoQueue: MongoQueueModel) {\n\t\t// let startDate = new Date();\n\n\t\tlet _mongoQueue = this._mongoQueue.filter(a => a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData))[0];\n\t\t\n\t\tif (_mongoQueue) {\n\t\t\tif (_mongoQueue.running) {\n\t\t\t\t_mongoQueue.run_again = true;\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'addToQueue',\n\t\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Run Again'\n\t\t\t\t// });\n\t\t\t}\n\t\t\t// else {\n\t\t\t// \tlet endDate = new Date();\n\t\t\t// \tthis.currentPerfomanceMonitor.push({\n\t\t\t// \t\t_id: this.idPerformance++,\n\t\t\t// \t\tfunction: 'addToQueue',\n\t\t\t// \t\tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \t\tsubscriptionData: [],\n\t\t\t// \t\tdate_start: startDate,\n\t\t\t// \t\tdate_end: endDate,\n\t\t\t// \t\tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \t\tresult: 'Not Running Yet'\n\t\t\t// \t});\n\t\t\t// }\n\t\t}\n\t\telse {\n\t\t\tmongoQueue._id = this._mongoQueueId;\n\t\t\tthis._mongoQueueId += 1;\n\n\t\t\tthis._mongoQueue.splice(0, 0, mongoQueue);\n\t\t\t\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'addToQueue',\n\t\t\t// \tpublication: mongoQueue.subscription.publication,\n\t\t\t// // \tsubscriptionData: mongoQueue.subscription.subscriptionData,\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Add to Queue'\n\t\t\t// });\n\t\t}\n\t}\n\n\tpublic invalidatePubsCache(collection, type) {\n\t\t// let startDate = new Date();\n\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\t\t\n\t\tlet collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\n\t\tfor (let i = collSubs.length - 1; i >= 0; i--) {\n\t\t\tlet sub = collSubs[i];\n\t\t\t\n\t\t\tthis.addToQueue({\n\t\t\t\t_id: 0,\n\t\t\t\ttype: type,\n\t\t\t\tcollection: collection,\n\t\t\t\tsubscription: sub,\n\t\t\t\trunning: false,\n\t\t\t\trun_again: false\n\t\t\t});\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'invalidatePubsCache',\n\t\t// \tpublication: collection,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.filter(a => a.id_ws === ws['id_socket'])[0];\n\n\t\tif (loggedInUser) {\n\t\t\tloggedInUser.date = new Date();\n\n\t\t\tLoggedInUsers.updateOne({id_ws: ws['id_socket']}, {$set: {latency: ws['latency'], date: loggedInUser.date}}).then(res => {\n\t\t\t\tif (!res) {\n\t\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {\n\t\t\t\tthis.unsubscribeAll(ws);\n\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\t// let startDate = new Date();\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.filter(a => a.publication === publication)[0].hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\t\t\t\t\t\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\t\t\t\t\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\t\t\t\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionData: subscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\t\t\t}\n\n\t\t\tif (!sub.cacheId && !this._mongoQueue.some(a => a.subscription.publication === sub.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub.subscriptionData))) {\n\t\t\t\tthis.addToQueue({\n\t\t\t\t\t_id: 0,\n\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tsubscription: sub,\n\t\t\t\t\trunning: false,\n\t\t\t\t\trun_again: false\n\t\t\t\t});\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Add to Queue'\n\t\t\t\t// });\n\t\t\t}\n\t\t\telse if (sub.cacheId) {\n\t\t\t\tthis.sendDataToOne(ws, messageId, sub, 'newSub', publication);\n\n\t\t\t\t// let endDate = new Date();\n\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t// \tfunction: 'subscribe',\n\t\t\t\t// \tpublication: publication,\n\t\t\t\t// // \tsubscriptionData: subscriptionData,\n\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t// \tresult: 'Send Pub Data Once'\n\t\t\t\t// });\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet ws = this._mainServer.getWS(id_ws);\n\n\t\t\tif (ws) {\n\t\t\t\tlet user = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tid_ws: ws['id_socket']\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tthis._loggedInUsers.push(user);\n\t\t\t\tLoggedInUsers.insertOne(user);\n\t\t\t\t\n\t\t\t\tresolve(user);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tresolve(null);\n\t\t\t}\n\t\t});\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugUnSubHits += 1;\n\t\t// let startDate = new Date();\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet sub = this._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// let endDate = new Date();\n\t\t// this.currentPerfomanceMonitor.push({\n\t\t// \t_id: this.idPerformance++,\n\t\t// \tfunction: 'unsubscribe',\n\t\t// \tpublication: publication,\n\t\t// // \tsubscriptionData: subscriptionData,\n\t\t// \tsubscriptionData: [],\n\t\t// \tdate_start: startDate,\n\t\t// \tdate_end: endDate,\n\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t// \tresult: 'Done'\n\t\t// });\n\t}\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\t\t// console.log('Before');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\n\t\t// let startDate = new Date();\n\n\t\tif (ws) {\n\t\t\tlet loggedInUser = await LoggedInUsers.findOne({id_ws: ws['id_socket']});\n\n\t\t\tif (loggedInUser) {\t\n\t\t\t\tif (this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id) >= 0) {\n\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id), 1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tLoggedInUsers.deleteOne({_id: loggedInUser._id});\n\t\t\t}\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tws.close();\n\n\t\t\tprocess.nextTick(() => {\n\t\t\t\tif ([ws.OPEN, ws.CLOSING].includes(<any>ws.readyState)) {\n\t\t\t\t\t// Socket still hangs, hard close\n\t\t\t\t\tws.terminate();\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// let endDate = new Date();\n\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t// \t_id: this.idPerformance++,\n\t\t\t// \tfunction: 'unsubscribeAll',\n\t\t\t// \tpublication: '',\n\t\t\t// \tsubscriptionData: [],\n\t\t\t// \tdate_start: startDate,\n\t\t\t// \tdate_end: endDate,\n\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t// \tresult: 'Done'\n\t\t\t// });\n\t\t}\n\n\t\t// console.log('After');\n\t\t// console.dir(this._subscriptions.map(a => a.publication));\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (!this._oplog || this._oplog.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 10) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************')\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch([], {resumeAfter: resumeToken});\n\t\t\t\t}\n\t\t\t\tcatch(errOp) {\n\t\t\t\t\tif (this._oplog && !this._oplog.closed) {\n\t\t\t\t\t\tthis._oplog.close();\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog = ResolveIOServer.getMainDB().watch();\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog.on('change', doc => {\n\t\t\t\t// let startDate = new Date();\n\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.filter(a => a.collection === doc.ns.coll && a.type === doc.operationType)[0].hits += 1;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// console.log(new Date(), 'Op log doc', doc.operationType, collection);\n\n\t\t\t\t\tif (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'insert');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Insert'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'update');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Update'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tthis.invalidatePubsCache(collection, 'delete');\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'oplog',\n\t\t\t\t\t\t\t// \tpublication: collection,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Delete'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tFlags.findOne({type: 'Enable Debug'}).then(flag => {\n\t\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tthis._oplog.on('error', error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tthis._oplog.close();\n\t\t\t});\n\n\t\t\tthis._oplog.on('end', () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tthis._oplog.close();\n\t\t\t});\n\n\t\t\tthis._oplog.on('close', () => {\n\t\t\t\tthis._oplog = null;\n\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._oplog.close();\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToOne(ws: WebSocket, messageId: number, subscription: ActiveSubscriptionModel, type: string, collection: string) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\n\t\t\tif (!this._publications[subscription.publication].user_specific) { // Same pub for all users\n\t\t\t\tif (subscription.cacheId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(subscription.cacheId), dateReviver);\n\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t\t};\n\t\n\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t}\n\t\t\t\t\tcatch(err) {\n\t\t\t\t\t\tthis._nodeCache.del(subscription.cacheId);\n\t\t\t\t\t\tsubscription.cacheId = 0;\n\n\t\t\t\t\t\tthis.addToQueue({\n\t\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\t\ttype: 'newSub',\n\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\t\t\trunning: false,\n\t\t\t\t\t\t\trun_again: false\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send cache'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - No Cache! - ' + subscription.publication + '\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2));\n\n\t\t\t\t\tresolve(false);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);\n\t\t\t\tthis._publications[subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: res\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t// \tfunction: 'sendDataToOne',\n\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t// \tresult: 'Send ws spec data'\n\t\t\t\t\t// });\n\n\t\t\t\t\tresolve(true);\n\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\t\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\tdata: err\n\t\t\t\t\t};\n\n\t\t\t\t\t// console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate sendDataToAll(mongoQueue: MongoQueueModel) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t// let startDate = new Date();\n\t\t\tif (!mongoQueue.subscription.clients.length) {\t\t\t\t\n\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t}\n\n\t\t\t\tif (this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)) >= 0) {\n\t\t\t\t\tthis._subscriptions.splice(this._subscriptions.findIndex(a => a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData)), 1);\n\t\t\t\t}\n\n\t\t\t\tresolve(false);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {\n\t\t\t\t\tthis._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));\n\t\t\t\t}\n\n\t\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);\n\t\t\t\tthis._publications[mongoQueue.subscription.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...mongoQueue.subscription.subscriptionData)\n\t\t\t\t.then(res => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tif (!mongoQueue.subscription.clients.length) {\n\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\n\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\n\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\n\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t// \tresult: 'No clients'\n\t\t\t\t\t\t// });\n\n\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!mongoQueue.subscription.cacheId || this._nodeCache.get(mongoQueue.subscription.cacheId) !== JSON.stringify(res)) {\n\t\t\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\n\t\t\t\t\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\t\tlet deleteCount = 0;\n\n\t\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\n\t\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\n\t\t\t\t\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\t\n\t\t\t\t\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tconsole.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (mongoQueue.subscription.cacheId) {\n\t\t\t\t\t\t\t\tthis._nodeCache.del(mongoQueue.subscription.cacheId);\n\t\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\t\tlet cacheId = this._cacheId;\n\t\t\t\t\t\t\tthis._cacheId += 1;\n\n\t\t\t\t\t\t\tthis._nodeCache.set(cacheId, JSON.stringify(res));\n\t\t\t\t\t\t\tmongoQueue.subscription.cacheId = cacheId;\n\n\t\t\t\t\t\t\t// let endDate = new Date();\n\t\t\t\t\t\t\t// this.currentPerfomanceMonitor.push({\n\t\t\t\t\t\t\t// \t_id: this.idPerformance++,\n\t\t\t\t\t\t\t// \tfunction: 'sendPubData',\n\t\t\t\t\t\t\t// \tpublication: subscription.publication,\n\t\t\t\t\t\t\t// // \tsubscriptionData: subscription.subscriptionData,\n\t\t\t\t\t\t\t// \tsubscriptionData: [],\n\t\t\t\t\t\t\t// \tdate_start: startDate,\n\t\t\t\t\t\t\t// \tdate_end: endDate,\n\t\t\t\t\t\t\t// \tduration: moment(endDate).diff(moment(startDate), 'milliseconds', false),\n\t\t\t\t\t\t\t// \tresult: 'Same data'\n\t\t\t\t\t\t\t// });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tthis._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t\t\tthis._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + mongoQueue.subscription.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(mongoQueue.subscription.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\n\t\t\t\t\tmongoQueue.subscription.clients.forEach(client => {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(client.id_socket);\n\n\t\t\t\t\t\tif (ws) {\n\t\t\t\t\t\t\tif (ws['id_socket'] === client.id_socket) {\n\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._sendQueue.splice(0, 0, {\n\t\t\tid_ws: ws['id_socket'],\n\t\t\tdata: data\n\t\t});\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n}\n"]}
|
package/package.json
CHANGED
package/server-app.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ import { SubscriptionManager } from './managers/subscription.manager';
|
|
|
8
8
|
import { MonitorManager } from './managers/monitor.manager';
|
|
9
9
|
export default class ResolveIOMainServer {
|
|
10
10
|
private _app;
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
11
|
+
private _serverHTTP;
|
|
12
|
+
private _portHTTP;
|
|
13
|
+
private _serverWSS;
|
|
14
|
+
private _portWSS;
|
|
14
15
|
private _serverConfig;
|
|
15
16
|
private _clientDir;
|
|
16
17
|
private _offlineUpdates;
|
|
@@ -39,6 +40,7 @@ export default class ResolveIOMainServer {
|
|
|
39
40
|
getMethodManager(): MethodManager;
|
|
40
41
|
getSubscriptionManager(): SubscriptionManager;
|
|
41
42
|
getMonitorManager(): MonitorManager;
|
|
43
|
+
getRebootFlag(): boolean;
|
|
42
44
|
private createServer;
|
|
43
45
|
private setUpMongo;
|
|
44
46
|
private listen;
|
package/server-app.js
CHANGED
|
@@ -174,6 +174,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
174
174
|
//PM2 wants to reboot/restart
|
|
175
175
|
process.on('SIGINT', function (err) {
|
|
176
176
|
_this._rebootFlag = true;
|
|
177
|
+
_this._serverHTTP.close();
|
|
177
178
|
var interval = setInterval(function () {
|
|
178
179
|
if (!_this._monitorManagerFunction.getActiveMonitorFunctions().length &&
|
|
179
180
|
(!_this._monitorManagerFunction.getLastCompletedMonitorFunction() ||
|
|
@@ -181,17 +182,23 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
181
182
|
!_this._msgQueue.length &&
|
|
182
183
|
!_this._msgQueueRunning &&
|
|
183
184
|
!_this._offlineUpdates.length) {
|
|
185
|
+
console.log(new Date(), 'Safe Exit Complete, Process Exit', err);
|
|
184
186
|
clearInterval(interval);
|
|
185
187
|
process.exit(err ? 1 : 0);
|
|
186
188
|
}
|
|
187
189
|
else {
|
|
190
|
+
console.log(new Date(), 'Safe Exit In Progress', _this._monitorManagerFunction.getActiveMonitorFunctions().length, _this._monitorManagerFunction.getLastCompletedMonitorFunction() ? _this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime : '', _this._msgQueue.length, _this._msgQueueRunning, _this._offlineUpdates.length);
|
|
188
191
|
_this.getWSList().forEach(function (ws) {
|
|
189
192
|
if (!_this._msgQueue.some(function (a) { return a.ws['id_socket'] === ws['id_socket']; }) &&
|
|
190
193
|
!_this._offlineUpdates.some(function (a) { return a['id_socket'] === ws['id_socket']; }) &&
|
|
191
194
|
(!_this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket ||
|
|
192
195
|
Date.now() >= _this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket.endTime.getTime())) {
|
|
196
|
+
console.log(new Date(), 'Safe Exit Unsub WS', ws['id_user'], ws['user'], ws['id_ws']);
|
|
193
197
|
_this.unsubscribeWS(ws);
|
|
194
198
|
}
|
|
199
|
+
else {
|
|
200
|
+
console.log(new Date(), 'Safe Exit NOT Unsub WS', ws['id_user'], ws['user'], ws['id_ws'], _this._msgQueue.some(function (a) { return a.ws['id_socket'] === ws['id_socket']; }), _this._offlineUpdates.some(function (a) { return a['id_socket'] === ws['id_socket']; }), _this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket ? _this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket.endTime : '');
|
|
201
|
+
}
|
|
195
202
|
});
|
|
196
203
|
}
|
|
197
204
|
}, 100);
|
|
@@ -206,7 +213,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
206
213
|
this._app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit: 1000000 }));
|
|
207
214
|
this._app.use(xmlParser());
|
|
208
215
|
// Set port
|
|
209
|
-
this.
|
|
216
|
+
this._portHTTP = process.env.PORT_HTTP || serverConfig['PORT_HTTP'] || 8080;
|
|
217
|
+
this._portWSS = process.env.PORT_WSS || serverConfig['PORT_WSS'] || 8081;
|
|
210
218
|
if (this.LOGGER === 'DEBUG') {
|
|
211
219
|
console.log('Setup ports');
|
|
212
220
|
}
|
|
@@ -245,24 +253,24 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
245
253
|
}
|
|
246
254
|
}
|
|
247
255
|
ResolveIOMainServer.prototype.getWS = function (id_ws) {
|
|
248
|
-
return Array.from(this.
|
|
256
|
+
return Array.from(this._serverWSS.clients).filter(function (a) { return a['id_socket'] === id_ws; })[0];
|
|
249
257
|
};
|
|
250
258
|
ResolveIOMainServer.prototype.getWSList = function () {
|
|
251
259
|
var res = [];
|
|
252
|
-
this.
|
|
260
|
+
this._serverWSS.clients.forEach(function (ws) {
|
|
253
261
|
res.push(ws['id_socket']);
|
|
254
262
|
});
|
|
255
263
|
return res;
|
|
256
264
|
};
|
|
257
265
|
ResolveIOMainServer.prototype.getWSUserList = function () {
|
|
258
266
|
var res = [];
|
|
259
|
-
this.
|
|
267
|
+
this._serverWSS.clients.forEach(function (ws) {
|
|
260
268
|
res.push(ws['id_user']);
|
|
261
269
|
});
|
|
262
270
|
return res;
|
|
263
271
|
};
|
|
264
272
|
ResolveIOMainServer.prototype.getHTTPServer = function () {
|
|
265
|
-
return this.
|
|
273
|
+
return this._serverHTTP;
|
|
266
274
|
};
|
|
267
275
|
ResolveIOMainServer.prototype.getCronManager = function () {
|
|
268
276
|
return this._cronManager;
|
|
@@ -276,16 +284,19 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
276
284
|
ResolveIOMainServer.prototype.getMonitorManager = function () {
|
|
277
285
|
return this._monitorManager;
|
|
278
286
|
};
|
|
287
|
+
ResolveIOMainServer.prototype.getRebootFlag = function () {
|
|
288
|
+
return this._rebootFlag;
|
|
289
|
+
};
|
|
279
290
|
ResolveIOMainServer.prototype.createServer = function () {
|
|
280
291
|
var _this = this;
|
|
281
292
|
// Start express server
|
|
282
|
-
this.
|
|
283
|
-
this.
|
|
284
|
-
this.
|
|
293
|
+
this._serverHTTP = http_1.createServer(this._app);
|
|
294
|
+
this._serverHTTP.keepAliveTimeout = 65000;
|
|
295
|
+
this._serverHTTP.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`
|
|
285
296
|
// Start websocket server
|
|
286
297
|
// Verify client with token before opening socket
|
|
287
|
-
this.
|
|
288
|
-
|
|
298
|
+
this._serverWSS = new WebSocket.Server({
|
|
299
|
+
port: this._portWSS,
|
|
289
300
|
verifyClient: function (info, cb) { return __awaiter(_this, void 0, void 0, function () {
|
|
290
301
|
var infoData, token;
|
|
291
302
|
var _this = this;
|
|
@@ -356,7 +367,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
356
367
|
console.log('Start Managers');
|
|
357
368
|
}
|
|
358
369
|
// Start Managers
|
|
359
|
-
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this.
|
|
370
|
+
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._serverWSS, this._serverConfig, this._monitorManagerFunction);
|
|
360
371
|
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);
|
|
361
372
|
this._cronManager = new cron_manager_1.CronManager(this);
|
|
362
373
|
if (this.LOGGER === 'DEBUG') {
|
|
@@ -367,11 +378,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
367
378
|
// Listen to port for websocket
|
|
368
379
|
ResolveIOMainServer.prototype.listen = function () {
|
|
369
380
|
var _this = this;
|
|
370
|
-
this.
|
|
371
|
-
console.log('Running server on port %s', _this.
|
|
381
|
+
this._serverHTTP.listen(this._portHTTP, function () {
|
|
382
|
+
console.log('Running server on port %s', _this._portHTTP);
|
|
383
|
+
});
|
|
384
|
+
this._serverWSS.on('listening', function () {
|
|
385
|
+
console.log('Running server on port %s', _this._portWSS);
|
|
372
386
|
});
|
|
373
387
|
// On websocket connection (already verified)
|
|
374
|
-
this.
|
|
388
|
+
this._serverWSS.on('connection', function (ws, req) {
|
|
375
389
|
// Get user from token
|
|
376
390
|
ws['id_user'] = req['id_user'];
|
|
377
391
|
ws['user'] = req['user'];
|
|
@@ -386,7 +400,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
386
400
|
});
|
|
387
401
|
}
|
|
388
402
|
var idSocket = '';
|
|
389
|
-
while (!idSocket || Array.from(_this.
|
|
403
|
+
while (!idSocket || Array.from(_this._serverWSS.clients).some(function (a) { return a['id_socket'] === idSocket; })) {
|
|
390
404
|
idSocket = uuid_1.v4();
|
|
391
405
|
}
|
|
392
406
|
ws['id_socket'] = idSocket;
|
|
@@ -583,7 +597,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
583
597
|
});
|
|
584
598
|
// Keep alive timer to ping/pong
|
|
585
599
|
setInterval(function () {
|
|
586
|
-
_this.
|
|
600
|
+
_this._serverWSS.clients.forEach(function (ws) {
|
|
587
601
|
if (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {
|
|
588
602
|
if (ws['isAlive'] === false) {
|
|
589
603
|
ws['retryCnt']++;
|
package/server-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;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server } from 'http';\nimport * as express from 'express';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport { v4 as uuidv4 } from 'uuid';\n// import * as SegfaultHandler from 'segfault-handler';\nimport * as moment from 'moment';\n\nimport { dateReviver, getBinarySize, deepCopy } from './util/common';\n\nimport { objectIdHexString } from './managers/mongo.manager';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { MonitorManager, MonitorManagerFunction } from './managers/monitor.manager';\n\nimport { ServerResponseModel } from './models/server-response.model';\n\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { Users } from './collections/user.collection';\n\nimport { setupHomeRoutes } from './http/home';\nimport { setupAuthRoutes } from './http/auth';\nimport { setupHealthRoutes } from './http/health';\nimport { ResolveIOServer } from './index';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _server: Server;\n\tprivate _port: string | number;\n\tprivate _wss: WebSocket.Server;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _offlineUpdates = [];\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\tprivate standardProgram = false;\n\tprivate _rebootFlag = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\n\tprivate _monitorManager: MonitorManager;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _clientRoutes: string[] = [];\n\n\tprivate _serverStartTime: Date;\n\tprivate _lastErrorMsg: Date = null;\n\n\tprivate _debugMsgRecv = 0;\n\tprivate _debugMsgQueue = 0;\n\n\tconstructor(mainServer, serverConfig, clientRoutes, clientDir, sesMail, standardProgram) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientRoutes = clientRoutes;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\t\tthis.standardProgram = standardProgram;\n\n\t\tthis._serverStartTime = new Date();\n\t\tthis._lastErrorMsg = null;\n\t\tthis._monitorManager = new MonitorManager(mainServer, serverConfig);\n\t\tthis._monitorManagerFunction = new MonitorManagerFunction();\n\n\t\tsetInterval(() => {\n\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Length', this._msgQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Recv Hits', this._debugMsgRecv);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Hits', this._debugMsgQueue);\n\t\t\t}\n\n\t\t\tthis._debugMsgQueue = 0;\n\t\t\tthis._debugMsgRecv = 0;\n\t\t}, 60000);\n\n\t\tprocess.on('unhandledRejection', async (error, rej) => {\n\t\t\tconsole.error(new Date(), 'Unhandled Rejection at Promise', [error, rej]);\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (error && error['name'] === 'MongoError' && error['message'] === 'not master') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error) {\n\t\t\t\tif (error['name'] !== 'StatusError' && error['message'] !== '') {\n\t\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t\t}, 60000);\n\n\t\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tprocess.on('uncaughtException', async error => {\n\t\t\tconsole.error(error, 'Uncaught Exception thrown');\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t}, 60000);\n\t\t\t\t\n\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t}\n\t\t});\n\n\t\t//PM2 wants to reboot/restart\n\t\tprocess.on('SIGINT', err => {\n\t\t\tthis._rebootFlag = true;\n\t\t\t\n\t\t\tlet interval = setInterval(() => {\n\t\t\t\tif (\n\t\t\t\t\t!this._monitorManagerFunction.getActiveMonitorFunctions().length && \n\t\t\t\t\t(!this._monitorManagerFunction.getLastCompletedMonitorFunction() ||\n\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 2500) &&\n\t\t\t\t\t!this._msgQueue.length &&\n\t\t\t\t\t!this._msgQueueRunning &&\n\t\t\t\t\t!this._offlineUpdates.length\n\t\t\t\t) {\n\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\tprocess.exit(err ? 1 : 0);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.getWSList().forEach(ws => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!this._msgQueue.some(a => a.ws['id_socket'] === ws['id_socket']) &&\n\t\t\t\t\t\t\t!this._offlineUpdates.some(a => a['id_socket'] === ws['id_socket']) &&\n\t\t\t\t\t\t\t(!this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket ||\n\t\t\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket.endTime.getTime())\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb', reviver: dateReviver}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._port = process.env.PORT || serverConfig['PORT'];\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\treturn Array.from(this._wss.clients).filter(a => a['id_socket'] === id_ws)[0];\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._server;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getMonitorManager() {\n\t\treturn this._monitorManager;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._server = createServer(this._app);\n\t\tthis._server.keepAliveTimeout = 65000;\n\t\tthis._server.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._wss = new WebSocket.Server({ \n\t\t\tserver: this._server,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this._rebootFlag) {\n\t\t\t\t\tcb(false, 409, 'Unable To Process');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\t\tif (!token) {\n\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']);\n\t\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['doc_user'] = user;\n\t\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start MongoDB Connection\n\t\tthis.setUpMongo();\n\t}\n\n\tprivate setUpMongo() {\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig, this._monitorManagerFunction);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);\n\t\tthis._cronManager = new CronManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\t}\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._server.listen(this._port, () => {\n\t\t\tconsole.log('Running server on port %s', this._port);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._wss.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req['id_user'];\n\t\t\tws['user'] = req['user'];\n\t\t\tws['user_readonly'] = req['user_readonly'];\n\t\t\tws['doc_user'] = req['doc_user'];\n\n\t\t\tif (ws['user'] !== 'Admin' && this._serverConfig['CLIENT_NAME'] !== 'ResolveIO') {\n\t\t\t\tthis.getMethodManager().callMethodInternal.call(this.getMethodManager(), 'supportCreateBillingUser', {\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tclient: ResolveIOServer.getClientName()\n\t\t\t\t});\n\t\t\t}\n\t\t\t\n\t\t\tlet idSocket = '';\n\n\t\t\twhile (!idSocket || Array.from(this._wss.clients).some(a => a['id_socket'] === idSocket)) {\n\t\t\t\tidSocket = uuidv4();\n\t\t\t}\n\n\t\t\tws['id_socket'] = idSocket;\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tthis._subscriptionManager.createLoggedInUser(idSocket).then(() => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}, 5000);\n\t\t\t});\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req['user']);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tthis._debugMsgRecv += 1;\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = [];\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tif (socketData[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Pong');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = socketData[0];\n\n\t\t\t\t\tif (this._clientRoutes.some(a => messageRoute.includes(a)) && !ws['doc_user'].roles.groups.some(a => a.views.some(b => messageRoute.includes(b))) && !ws['doc_user'].roles.super_admin) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageDate = socketData[1];\n\t\t\t\t\tlet messageId = socketData[2]\n\t\t\t\t\tlet type = socketData[3]\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = socketData[4];\n\t\t\t\t\t\tlet pub = socketData[5];\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'offline') {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Main');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.push(ws);\n\t\t\t\t\t\tlet offlineUpdates = socketData[4];\n\n\t\t\t\t\t\tfor (let i = 0; i < offlineUpdates.length; i++) {\n\t\t\t\t\t\t\tlet update = offlineUpdates[i];\n\t\t\t\t\t\t\tlet data = update.data;\n\n\t\t\t\t\t\t\tlet serverResMethod: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: update.data[2],\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(serverResMethod), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Each');\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet updateRoute = data.shift();\n\t\t\t\t\t\t\tlet updateDate = data.shift();\n\t\t\t\t\t\t\tlet updateMessageId = data.shift();\n\t\t\t\t\t\t\tlet updateType = data.shift();\n\t\t\t\t\t\t\tlet method = data.shift();\n\t\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait this._methodManager.callMethodInternal.call(Object.assign({}, this._methodManager, {id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket']}), method, ...data);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Offline Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('Offline - Could not find method: ' + method);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.splice(this._offlineUpdates.map(a => a['id_socket']).indexOf(ws['id_socket']), 1);\n\t\t\t\t\t}\n\t\t\t\t\telse { //methods\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Server App', 'WS Close');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'WS Error');\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {\n\t\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\t\tif (ws['retryCnt'] >= 3) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'Ping Retry', ws['retryCnt'], ws['pingTime'], ws['pongTime']);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}, 20000);\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._msgQueueRunning) {\t\t\t\t\n\t\t\t\tif (this._msgQueue.length) {\n\t\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\tthis._debugMsgQueue += 1;\n\n\t\t\t\t\tlet msg = this._msgQueue[this._msgQueue.length - 1];\n\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\tlet ws = msg.ws;\n\t\t\n\t\t\t\t\tlet messageRoute: string = data.shift();\n\t\t\t\t\tlet messageDate: Date = data.shift();\n\t\t\t\t\tlet messageId: number = data.shift();\n\t\t\t\t\tlet type: string = data.shift();\n\t\t\n\t\t\t\t\t// Method call\n\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\tlet method = data.shift();\n\n\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatencyId, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t]}).then(res => {\n\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, err => {});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthis._msgQueue.splice(this._msgQueue.length - 1, 1);\n\t\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 25);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\tconsole.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);\n\t\t}\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n\n\tpublic getServerConfig() {\n\t\treturn this._serverConfig;\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA4C;AAC5C,iCAAmC;AACnC,wCAA0C;AAC1C,kDAAoD;AACpD,8BAAgC;AAChC,kCAAoC;AACpC,6BAAoC;AACpC,uDAAuD;AACvD,+BAAiC;AAEjC,wCAAqE;AAErE,0DAA6D;AAC7D,wDAAsD;AACtD,4DAA0D;AAC1D,wEAAsE;AACtE,8DAAoF;AAIpF,uFAA2E;AAC3E,+DAAoD;AACpD,6FAAiF;AACjF,iEAAsD;AAEtD,oCAA8C;AAC9C,oCAA8C;AAC9C,wCAAkD;AAClD,iCAA0C;AAE1C;IA8BC,6BAAY,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe;QAAvF,iBAoMC;QA1NO,oBAAe,GAAG,EAAE,CAAC;QACrB,cAAS,GAAG,EAAE,CAAC;QACf,qBAAgB,GAAG,KAAK,CAAC;QAC1B,YAAO,GAA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oCACpC,IAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,UAAC,KAAK;wCAC3C,IAAI,KAAK,EAAE;4CACV,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;4CACpC,KAAI,CAAC,aAAa,CAAC,IAAE,CAAC,CAAC;yCACvB;oCACF,CAAC,CAAC,CAAC;iCACH;6BACD;wBACF,CAAC,EAAE,UAAA,GAAG,IAAK,CAAC,CAAC,CAAC;qBACd;oBAED,KAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;oBACpD,KAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;iBAC9B;aACD;QACF,CAAC,EAAE,EAAE,CAAC,CAAC;IACR,CAAC;IAEM,2CAAa,GAApB,UAAqB,EAAa;QACjC,IAAI,IAAI,CAAC,oBAAoB,CAAC,cAAc,EAAE,EAAE;YAC/C,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SAC/E;QACD,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,oCAAM,GAAb;QACC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,6CAAe,GAAtB;QACC,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IACF,0BAAC;AAAD,CA7tBA,AA6tBC,IAAA","file":"server-app.js","sourcesContent":["import { createServer, Server } from 'http';\nimport * as express from 'express';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport { v4 as uuidv4 } from 'uuid';\n// import * as SegfaultHandler from 'segfault-handler';\nimport * as moment from 'moment';\n\nimport { dateReviver, getBinarySize, deepCopy } from './util/common';\n\nimport { objectIdHexString } from './managers/mongo.manager';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { MonitorManager, MonitorManagerFunction } from './managers/monitor.manager';\n\nimport { ServerResponseModel } from './models/server-response.model';\n\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { Users } from './collections/user.collection';\n\nimport { setupHomeRoutes } from './http/home';\nimport { setupAuthRoutes } from './http/auth';\nimport { setupHealthRoutes } from './http/health';\nimport { ResolveIOServer } from './index';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _serverHTTP: Server;\n\tprivate _portHTTP: string | number;\n\tprivate _serverWSS: WebSocket.Server;\n\tprivate _portWSS: number;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _offlineUpdates = [];\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\tprivate standardProgram = false;\n\tprivate _rebootFlag = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\n\tprivate _monitorManager: MonitorManager;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _clientRoutes: string[] = [];\n\n\tprivate _serverStartTime: Date;\n\tprivate _lastErrorMsg: Date = null;\n\n\tprivate _debugMsgRecv = 0;\n\tprivate _debugMsgQueue = 0;\n\n\tconstructor(mainServer, serverConfig, clientRoutes, clientDir, sesMail, standardProgram) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientRoutes = clientRoutes;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\t\tthis.standardProgram = standardProgram;\n\n\t\tthis._serverStartTime = new Date();\n\t\tthis._lastErrorMsg = null;\n\t\tthis._monitorManager = new MonitorManager(mainServer, serverConfig);\n\t\tthis._monitorManagerFunction = new MonitorManagerFunction();\n\n\t\tsetInterval(() => {\n\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Length', this._msgQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Recv Hits', this._debugMsgRecv);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Hits', this._debugMsgQueue);\n\t\t\t}\n\n\t\t\tthis._debugMsgQueue = 0;\n\t\t\tthis._debugMsgRecv = 0;\n\t\t}, 60000);\n\n\t\tprocess.on('unhandledRejection', async (error, rej) => {\n\t\t\tconsole.error(new Date(), 'Unhandled Rejection at Promise', [error, rej]);\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (error && error['name'] === 'MongoError' && error['message'] === 'not master') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error) {\n\t\t\t\tif (error['name'] !== 'StatusError' && error['message'] !== '') {\n\t\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t\t}, 60000);\n\n\t\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tprocess.on('uncaughtException', async error => {\n\t\t\tconsole.error(error, 'Uncaught Exception thrown');\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t}, 60000);\n\t\t\t\t\n\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t}\n\t\t});\n\n\t\t//PM2 wants to reboot/restart\n\t\tprocess.on('SIGINT', err => {\n\t\t\tthis._rebootFlag = true;\n\n\t\t\tthis._serverHTTP.close();\n\t\t\t\n\t\t\tlet interval = setInterval(() => {\n\t\t\t\tif (\n\t\t\t\t\t!this._monitorManagerFunction.getActiveMonitorFunctions().length && \n\t\t\t\t\t(!this._monitorManagerFunction.getLastCompletedMonitorFunction() ||\n\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 2500) &&\n\t\t\t\t\t!this._msgQueue.length &&\n\t\t\t\t\t!this._msgQueueRunning &&\n\t\t\t\t\t!this._offlineUpdates.length\n\t\t\t\t) {\n\t\t\t\t\tconsole.log(new Date(), 'Safe Exit Complete, Process Exit', err);\n\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\tprocess.exit(err ? 1 : 0);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tconsole.log(new Date(), \n\t\t\t\t\t\t'Safe Exit In Progress', \n\t\t\t\t\t\tthis._monitorManagerFunction.getActiveMonitorFunctions().length, \n\t\t\t\t\t\tthis._monitorManagerFunction.getLastCompletedMonitorFunction() ? this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime : '',\n\t\t\t\t\t\tthis._msgQueue.length, \n\t\t\t\t\t\tthis._msgQueueRunning,\n\t\t\t\t\t\tthis._offlineUpdates.length\n\t\t\t\t\t);\n\n\t\t\t\t\tthis.getWSList().forEach(ws => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!this._msgQueue.some(a => a.ws['id_socket'] === ws['id_socket']) &&\n\t\t\t\t\t\t\t!this._offlineUpdates.some(a => a['id_socket'] === ws['id_socket']) &&\n\t\t\t\t\t\t\t(!this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket ||\n\t\t\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket.endTime.getTime())\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Safe Exit Unsub WS', ws['id_user'], ws['user'], ws['id_ws']);\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Safe Exit NOT Unsub WS', ws['id_user'], ws['user'], ws['id_ws'], this._msgQueue.some(a => a.ws['id_socket'] === ws['id_socket']), this._offlineUpdates.some(a => a['id_socket'] === ws['id_socket']), this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket ? this._monitorManagerFunction.getLastCompletedMonitorFunctionWS().id_socket.endTime : '');\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb', reviver: dateReviver}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._portHTTP = process.env.PORT_HTTP || serverConfig['PORT_HTTP'] || 8080;\n\t\tthis._portWSS = process.env.PORT_WSS || serverConfig['PORT_WSS'] || 8081;\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\treturn Array.from(this._serverWSS.clients).filter(a => a['id_socket'] === id_ws)[0];\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._serverWSS.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._serverWSS.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._serverHTTP;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getMonitorManager() {\n\t\treturn this._monitorManager;\n\t}\n\n\tpublic getRebootFlag() {\n\t\treturn this._rebootFlag;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._serverHTTP = createServer(this._app);\n\t\tthis._serverHTTP.keepAliveTimeout = 65000;\n\t\tthis._serverHTTP.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._serverWSS = new WebSocket.Server({ \n\t\t\tport: this._portWSS,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this._rebootFlag) {\n\t\t\t\t\tcb(false, 409, 'Unable To Process');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\t\tif (!token) {\n\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']);\n\t\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['doc_user'] = user;\n\t\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start MongoDB Connection\n\t\tthis.setUpMongo();\n\t}\n\n\tprivate setUpMongo() {\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._serverWSS, this._serverConfig, this._monitorManagerFunction);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);\n\t\tthis._cronManager = new CronManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\t}\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._serverHTTP.listen(this._portHTTP, () => {\n\t\t\tconsole.log('Running server on port %s', this._portHTTP);\n\t\t});\n\n\t\tthis._serverWSS.on('listening', () => {\n\t\t\tconsole.log('Running server on port %s', this._portWSS);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._serverWSS.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req['id_user'];\n\t\t\tws['user'] = req['user'];\n\t\t\tws['user_readonly'] = req['user_readonly'];\n\t\t\tws['doc_user'] = req['doc_user'];\n\n\t\t\tif (ws['user'] !== 'Admin' && this._serverConfig['CLIENT_NAME'] !== 'ResolveIO') {\n\t\t\t\tthis.getMethodManager().callMethodInternal.call(this.getMethodManager(), 'supportCreateBillingUser', {\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tclient: ResolveIOServer.getClientName()\n\t\t\t\t});\n\t\t\t}\n\t\t\t\n\t\t\tlet idSocket = '';\n\n\t\t\twhile (!idSocket || Array.from(this._serverWSS.clients).some(a => a['id_socket'] === idSocket)) {\n\t\t\t\tidSocket = uuidv4();\n\t\t\t}\n\n\t\t\tws['id_socket'] = idSocket;\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tthis._subscriptionManager.createLoggedInUser(idSocket).then(() => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}, 5000);\n\t\t\t});\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req['user']);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tthis._debugMsgRecv += 1;\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = [];\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tif (socketData[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Pong');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = socketData[0];\n\n\t\t\t\t\tif (this._clientRoutes.some(a => messageRoute.includes(a)) && !ws['doc_user'].roles.groups.some(a => a.views.some(b => messageRoute.includes(b))) && !ws['doc_user'].roles.super_admin) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageDate = socketData[1];\n\t\t\t\t\tlet messageId = socketData[2]\n\t\t\t\t\tlet type = socketData[3]\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = socketData[4];\n\t\t\t\t\t\tlet pub = socketData[5];\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'offline') {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Main');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.push(ws);\n\t\t\t\t\t\tlet offlineUpdates = socketData[4];\n\n\t\t\t\t\t\tfor (let i = 0; i < offlineUpdates.length; i++) {\n\t\t\t\t\t\t\tlet update = offlineUpdates[i];\n\t\t\t\t\t\t\tlet data = update.data;\n\n\t\t\t\t\t\t\tlet serverResMethod: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: update.data[2],\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(serverResMethod), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Each');\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet updateRoute = data.shift();\n\t\t\t\t\t\t\tlet updateDate = data.shift();\n\t\t\t\t\t\t\tlet updateMessageId = data.shift();\n\t\t\t\t\t\t\tlet updateType = data.shift();\n\t\t\t\t\t\t\tlet method = data.shift();\n\t\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait this._methodManager.callMethodInternal.call(Object.assign({}, this._methodManager, {id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket']}), method, ...data);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Offline Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('Offline - Could not find method: ' + method);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.splice(this._offlineUpdates.map(a => a['id_socket']).indexOf(ws['id_socket']), 1);\n\t\t\t\t\t}\n\t\t\t\t\telse { //methods\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Server App', 'WS Close');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'WS Error');\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._serverWSS.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {\n\t\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\t\tif (ws['retryCnt'] >= 3) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'Ping Retry', ws['retryCnt'], ws['pingTime'], ws['pongTime']);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}, 20000);\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._msgQueueRunning) {\t\t\t\t\n\t\t\t\tif (this._msgQueue.length) {\n\t\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\tthis._debugMsgQueue += 1;\n\n\t\t\t\t\tlet msg = this._msgQueue[this._msgQueue.length - 1];\n\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\tlet ws = msg.ws;\n\t\t\n\t\t\t\t\tlet messageRoute: string = data.shift();\n\t\t\t\t\tlet messageDate: Date = data.shift();\n\t\t\t\t\tlet messageId: number = data.shift();\n\t\t\t\t\tlet type: string = data.shift();\n\t\t\n\t\t\t\t\t// Method call\n\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\tlet method = data.shift();\n\n\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatencyId, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t]}).then(res => {\n\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, err => {});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthis._msgQueue.splice(this._msgQueue.length - 1, 1);\n\t\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 25);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\tconsole.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);\n\t\t}\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n\n\tpublic getServerConfig() {\n\t\treturn this._serverConfig;\n\t}\n}"]}
|