@resolveio/server-lib 5.2.25 → 5.2.26

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.
@@ -56,6 +56,7 @@ var DefaultSchema = new mongoose_1.Schema(schema, {
56
56
  versionKey: false,
57
57
  timestamps: true
58
58
  });
59
+ DefaultSchema.index({ id_ws: 1 });
59
60
  exports.LoggedInUsers = index_1.ResolveIOServer.getMainDB().model('logged-in-users', DefaultSchema);
60
61
  var vSchema = __assign({}, schema);
61
62
  vSchema._id = {
@@ -5,6 +5,7 @@ export declare class SubscriptionManager {
5
5
  private _publications;
6
6
  private _subscriptions;
7
7
  private _wss;
8
+ private _loggedInUsers;
8
9
  private _oplogQueue;
9
10
  private _subCache;
10
11
  private _nodeCache;
@@ -62,6 +62,7 @@ var SubscriptionManager = /** @class */ (function () {
62
62
  var _this = this;
63
63
  this._publications = {};
64
64
  this._subscriptions = [];
65
+ this._loggedInUsers = [];
65
66
  this._oplogQueue = [];
66
67
  this._subCache = [];
67
68
  this._cacheId = 0;
@@ -124,6 +125,17 @@ var SubscriptionManager = /** @class */ (function () {
124
125
  }
125
126
  }
126
127
  }, 25);
128
+ logged_in_users_collection_1.LoggedInUsers.find().then(function (loggedInUsers) {
129
+ _this._loggedInUsers = loggedInUsers;
130
+ });
131
+ setInterval(function () {
132
+ for (var i = 0; i < _this._loggedInUsers.length; i++) {
133
+ var loggedInUser = _this._loggedInUsers[i];
134
+ if (!loggedInUser.updatedAt || moment().diff(moment(loggedInUser.updatedAt), 'minutes', true) > 1) {
135
+ _this.unsubscribeAll(_this._mainServer.getWS(loggedInUser.id_ws));
136
+ }
137
+ }
138
+ }, 60000);
127
139
  }
128
140
  // Add all files to publications private object
129
141
  SubscriptionManager.prototype.publications = function (method) {
@@ -149,7 +161,7 @@ var SubscriptionManager = /** @class */ (function () {
149
161
  subscriptionData[_i - 4] = arguments[_i];
150
162
  }
151
163
  return __awaiter(this, void 0, void 0, function () {
152
- var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
164
+ var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, newLoggedInUser, begDate, endDate, billUser;
153
165
  return __generator(this, function (_c) {
154
166
  switch (_c.label) {
155
167
  case 0:
@@ -237,14 +249,16 @@ var SubscriptionManager = /** @class */ (function () {
237
249
  _c.label = 4;
238
250
  case 4:
239
251
  if (!(publication === 'appversion')) return [3 /*break*/, 6];
240
- logged_in_users_collection_1.LoggedInUsers.create({
252
+ newLoggedInUser = {
241
253
  _id: mongoose_1.Types.ObjectId().toHexString(),
242
254
  __v: 0,
243
255
  date: new Date(),
244
256
  id_user: ws['id_user'],
245
257
  user: ws['user'],
246
258
  id_ws: ws['id_socket']
247
- });
259
+ };
260
+ this._loggedInUsers.push(newLoggedInUser);
261
+ logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
248
262
  if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 6];
249
263
  begDate = moment().startOf('month');
250
264
  endDate = moment().endOf('month');
@@ -340,6 +354,9 @@ var SubscriptionManager = /** @class */ (function () {
340
354
  case 1:
341
355
  loggedInUser = _a.sent();
342
356
  if (loggedInUser) {
357
+ if (this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id) >= 0) {
358
+ this._loggedInUsers.splice(this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id), 1);
359
+ }
343
360
  logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id }).exec();
344
361
  }
345
362
  userSubs = that._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']; }); });
@@ -375,6 +392,7 @@ var SubscriptionManager = /** @class */ (function () {
375
392
  active_subscription_collection_1.ActiveSubscriptions.updateOne({ _id: sub._id }, { $set: { clients: sub.clients } }).exec();
376
393
  }
377
394
  });
395
+ ws.terminate();
378
396
  return [2 /*return*/];
379
397
  }
380
398
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "5.2.25",
3
+ "version": "5.2.26",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.js CHANGED
@@ -281,7 +281,6 @@ var ResolveIOMainServer = /** @class */ (function () {
281
281
  });
282
282
  ws['versionTimer'] = setTimeout(function () {
283
283
  _this.unsubscribeWS(ws);
284
- ws.terminate();
285
284
  }, 10000);
286
285
  // On data received (message)
287
286
  ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
@@ -345,23 +344,8 @@ var ResolveIOMainServer = /** @class */ (function () {
345
344
  ws.on('error', function (error) {
346
345
  console.log(error);
347
346
  _this.unsubscribeWS(ws);
348
- ws.terminate();
349
347
  });
350
348
  });
351
- // Seems to cause issues
352
- // process.stdout.on('error', (err) => {
353
- // if (err.code === "EPIPE") {
354
- // console.log('EPIPE error found => ignoring');
355
- // this._wss.clients.forEach((ws: WebSocket) => {
356
- // if (ws['isAlive'] === false) {
357
- // if (ws['retryCnt'] >= 60) {
358
- // this.unsubscribeWS(ws);
359
- // ws.terminate();
360
- // }
361
- // }
362
- // });
363
- // }
364
- // });
365
349
  process.on('unhandledRejection', function (reason, p) {
366
350
  console.error(reason, 'Unhandled Rejection at Promise', p);
367
351
  _this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + _this._serverConfig['CLIENT_NAME'], JSON.stringify([reason, p]));
@@ -378,7 +362,6 @@ var ResolveIOMainServer = /** @class */ (function () {
378
362
  ws['retryCnt']++;
379
363
  if (ws['retryCnt'] >= 60) {
380
364
  _this.unsubscribeWS(ws);
381
- ws.terminate();
382
365
  }
383
366
  else {
384
367
  ws['pingTime'] = new Date();
@@ -421,7 +404,6 @@ var ResolveIOMainServer = /** @class */ (function () {
421
404
  if (method === 'disconnectWSCommand') {
422
405
  setTimeout(function () {
423
406
  _this.unsubscribeWS(ws);
424
- ws.terminate();
425
407
  }, 5000);
426
408
  }
427
409
  if (ws['user_readonly']) {