@resolveio/server-lib 12.4.2 → 12.4.3

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