@resolveio/server-lib 1.0.0-rc19 → 1.0.0-rc2

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.
Files changed (157) hide show
  1. package/collections/active-subscription.collection.js +1 -68
  2. package/collections/app-status.collection.js +1 -43
  3. package/collections/app-version.collection.js +1 -56
  4. package/collections/counter.collection.js +1 -73
  5. package/collections/cron-job-history.collection.js +1 -86
  6. package/collections/cron-job.collection.js +1 -89
  7. package/collections/file.collection.js +1 -73
  8. package/collections/flag.collection.js +1 -47
  9. package/collections/log.collection.js +1 -64
  10. package/collections/logged-in-users.collection.js +1 -70
  11. package/collections/method-call.collection.js +1 -44
  12. package/collections/method-response.collection.js +1 -48
  13. package/collections/queue-flag.collection.js +1 -41
  14. package/collections/queue-method.collection.js +1 -116
  15. package/collections/queue-response.collection.js +1 -78
  16. package/collections/support-ticket.collection.js +1 -146
  17. package/collections/user.collection.js +1 -108
  18. package/cron/cron.js +1 -160
  19. package/fixtures/cron-jobs.js +1 -72
  20. package/fixtures/init.js +1 -73
  21. package/http/auth.js +1 -472
  22. package/http/health.js +1 -8
  23. package/index.js +1 -123
  24. package/managers/cron.manager.js +1 -193
  25. package/managers/method.manager.js +1 -513
  26. package/managers/queue-method.manager.js +1 -239
  27. package/managers/subscription.manager.js +1 -700
  28. package/managers/support.manager.js +1 -208
  29. package/methods/accounts.js +1 -253
  30. package/methods/aws.js +1 -323
  31. package/methods/cloudconvert.js +1 -37
  32. package/methods/collections.js +1 -738
  33. package/methods/counters.js +1 -404
  34. package/methods/cron-jobs.js +1 -63
  35. package/methods/flags.js +1 -6
  36. package/methods/logs.js +1 -29
  37. package/methods/pdf.js +1 -303
  38. package/models/active-subscription.model.js +1 -2
  39. package/models/app-status.model.js +1 -2
  40. package/models/app-version.model.js +1 -2
  41. package/models/collection-document.model.js +1 -2
  42. package/models/counter.model.js +1 -2
  43. package/models/cron-job-history.model.js +1 -2
  44. package/models/cron-job.model.js +1 -2
  45. package/models/dialog.model.js +1 -2
  46. package/models/file.model.js +1 -2
  47. package/models/flag.model.js +1 -2
  48. package/models/log.model.js +1 -2
  49. package/models/logged-in-users.model.js +1 -2
  50. package/models/method-call.model.js +1 -2
  51. package/models/method-response.model.js +1 -2
  52. package/models/method.model.js +1 -2
  53. package/models/pagination.model.js +1 -20
  54. package/models/permission.model.js +1 -2
  55. package/models/queue-method.model.js +1 -2
  56. package/models/queue-response.model.js +1 -2
  57. package/models/select-data-label.model.js +1 -2
  58. package/models/server-response.model.js +1 -2
  59. package/models/subscription.model.js +1 -2
  60. package/models/support-method.model.js +1 -2
  61. package/models/support-ticket.model.js +1 -2
  62. package/models/user.model.js +1 -2
  63. package/package.json +2 -5
  64. package/publications/app-status.js +1 -14
  65. package/publications/app-version.js +1 -14
  66. package/publications/cron-jobs.js +1 -14
  67. package/publications/files.js +1 -71
  68. package/publications/flags.js +1 -23
  69. package/publications/logs.js +1 -26
  70. package/publications/method-calls.js +1 -14
  71. package/publications/method-responses.js +1 -14
  72. package/publications/super-admin.js +1 -21
  73. package/publications/support-tickets.js +1 -118
  74. package/server-app.js +1 -640
  75. package/support-methods/aws.js +1 -276
  76. package/support-methods/collections.js +1 -471
  77. package/support-methods/counters.js +1 -189
  78. package/support-methods/support.js +1 -19
  79. package/util/common.js +1 -334
  80. package/collections/active-subscription.collection.d.ts +0 -8
  81. package/collections/app-status.collection.d.ts +0 -8
  82. package/collections/app-version.collection.d.ts +0 -8
  83. package/collections/counter.collection.d.ts +0 -10
  84. package/collections/cron-job-history.collection.d.ts +0 -8
  85. package/collections/cron-job.collection.d.ts +0 -8
  86. package/collections/file.collection.d.ts +0 -10
  87. package/collections/flag.collection.d.ts +0 -8
  88. package/collections/log.collection.d.ts +0 -8
  89. package/collections/logged-in-users.collection.d.ts +0 -8
  90. package/collections/method-call.collection.d.ts +0 -7
  91. package/collections/method-response.collection.d.ts +0 -7
  92. package/collections/queue-flag.collection.d.ts +0 -8
  93. package/collections/queue-method.collection.d.ts +0 -8
  94. package/collections/queue-response.collection.d.ts +0 -8
  95. package/collections/support-ticket.collection.d.ts +0 -8
  96. package/collections/user.collection.d.ts +0 -9
  97. package/cron/cron.d.ts +0 -6
  98. package/fixtures/cron-jobs.d.ts +0 -2
  99. package/fixtures/init.d.ts +0 -2
  100. package/http/auth.d.ts +0 -3
  101. package/http/health.d.ts +0 -2
  102. package/index.d.ts +0 -15
  103. package/managers/cron.manager.d.ts +0 -17
  104. package/managers/method.manager.d.ts +0 -27
  105. package/managers/queue-method.manager.d.ts +0 -14
  106. package/managers/subscription.manager.d.ts +0 -27
  107. package/managers/support.manager.d.ts +0 -18
  108. package/methods/accounts.d.ts +0 -3
  109. package/methods/aws.d.ts +0 -3
  110. package/methods/cloudconvert.d.ts +0 -3
  111. package/methods/collections.d.ts +0 -3
  112. package/methods/counters.d.ts +0 -3
  113. package/methods/cron-jobs.d.ts +0 -3
  114. package/methods/flags.d.ts +0 -3
  115. package/methods/logs.d.ts +0 -3
  116. package/methods/pdf.d.ts +0 -3
  117. package/models/active-subscription.model.d.ts +0 -14
  118. package/models/app-status.model.d.ts +0 -5
  119. package/models/app-version.model.d.ts +0 -5
  120. package/models/collection-document.model.d.ts +0 -7
  121. package/models/counter.model.d.ts +0 -6
  122. package/models/cron-job-history.model.d.ts +0 -13
  123. package/models/cron-job.model.d.ts +0 -14
  124. package/models/dialog.model.d.ts +0 -24
  125. package/models/file.model.d.ts +0 -10
  126. package/models/flag.model.d.ts +0 -6
  127. package/models/log.model.d.ts +0 -12
  128. package/models/logged-in-users.model.d.ts +0 -10
  129. package/models/method-call.model.d.ts +0 -8
  130. package/models/method-response.model.d.ts +0 -9
  131. package/models/method.model.d.ts +0 -11
  132. package/models/pagination.model.d.ts +0 -12
  133. package/models/permission.model.d.ts +0 -13
  134. package/models/queue-method.model.d.ts +0 -10
  135. package/models/queue-response.model.d.ts +0 -11
  136. package/models/select-data-label.model.d.ts +0 -10
  137. package/models/server-response.model.d.ts +0 -6
  138. package/models/subscription.model.d.ts +0 -31
  139. package/models/support-method.model.d.ts +0 -10
  140. package/models/support-ticket.model.d.ts +0 -40
  141. package/models/user.model.d.ts +0 -15
  142. package/publications/app-status.d.ts +0 -3
  143. package/publications/app-version.d.ts +0 -3
  144. package/publications/cron-jobs.d.ts +0 -3
  145. package/publications/files.d.ts +0 -3
  146. package/publications/flags.d.ts +0 -3
  147. package/publications/logs.d.ts +0 -3
  148. package/publications/method-calls.d.ts +0 -3
  149. package/publications/method-responses.d.ts +0 -3
  150. package/publications/super-admin.d.ts +0 -3
  151. package/publications/support-tickets.d.ts +0 -2
  152. package/server-app.d.ts +0 -33
  153. package/support-methods/aws.d.ts +0 -3
  154. package/support-methods/collections.d.ts +0 -3
  155. package/support-methods/counters.d.ts +0 -3
  156. package/support-methods/support.d.ts +0 -3
  157. package/util/common.d.ts +0 -15
package/server-app.js CHANGED
@@ -1,640 +1 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var http_1 = require("http");
39
- var express = require("express");
40
- var mongoose = require("mongoose");
41
- var bodyParser = require("body-parser");
42
- var passport = require("passport");
43
- var passportlocal = require("passport-local");
44
- var WebSocket = require("ws");
45
- var jwt = require("jsonwebtoken");
46
- var uuid = require("uuid/v4");
47
- var auth_1 = require("./http/auth");
48
- var common_1 = require("./util/common");
49
- var health_1 = require("./http/health");
50
- var method_call_collection_1 = require("./collections/method-call.collection");
51
- var mongoose_1 = require("mongoose");
52
- var method_response_collection_1 = require("./collections/method-response.collection");
53
- var log_collection_1 = require("./collections/log.collection");
54
- var moment = require("moment");
55
- var user_collection_1 = require("./collections/user.collection");
56
- var cron_manager_1 = require("./managers/cron.manager");
57
- var method_manager_1 = require("./managers/method.manager");
58
- var subscription_manager_1 = require("./managers/subscription.manager");
59
- var support_manager_1 = require("./managers/support.manager");
60
- var queue_method_manager_1 = require("./managers/queue-method.manager");
61
- var ResolveIOMainServer = /** @class */ (function () {
62
- function ResolveIOMainServer(mainServer, serverConfig) {
63
- this._resolveioServer = mainServer;
64
- this._serverConfig = serverConfig;
65
- // process.on('unhandledException').
66
- // Start express app
67
- this._app = express();
68
- // Use body parser for http call (login)
69
- this._app.use(bodyParser.json({ limit: '5mb' }));
70
- this._app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));
71
- // Set port
72
- this._port = process.env.PORT || serverConfig['PORT'];
73
- // Create http server and websock server
74
- this.createServer();
75
- // Set CORS
76
- this._app.use(function (req, res, next) {
77
- // Website you wish to allow to connect
78
- // res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);
79
- res.setHeader('Access-Control-Allow-Origin', '*');
80
- // Request methods you wish to allow
81
- // res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
82
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
83
- // Request headers you wish to allow
84
- res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
85
- // Set to true if you need the website to include cookies in the requests sent
86
- // to the API (e.g. in case you use sessions)
87
- res.setHeader('Access-Control-Allow-Credentials', 'false');
88
- // Pass to next layer of middleware
89
- next();
90
- });
91
- // Set up http login route
92
- auth_1.setupAuthRoutes(this, this._app, serverConfig);
93
- health_1.setupHealthRoutes(this._app, serverConfig);
94
- }
95
- ResolveIOMainServer.prototype.getWS = function (id_ws) {
96
- var res = null;
97
- this._wss.clients.forEach(function (ws) {
98
- if (ws['id_socket'] === id_ws) {
99
- res = ws;
100
- }
101
- });
102
- return res;
103
- };
104
- ResolveIOMainServer.prototype.getWSList = function () {
105
- var res = [];
106
- this._wss.clients.forEach(function (ws) {
107
- res.push(ws['id_socket']);
108
- });
109
- return res;
110
- };
111
- ResolveIOMainServer.prototype.getCronManager = function () {
112
- return this._cronManager;
113
- };
114
- ResolveIOMainServer.prototype.getMethodManager = function () {
115
- return this._methodManager;
116
- };
117
- ResolveIOMainServer.prototype.getSubscriptionManager = function () {
118
- return this._subscriptionManager;
119
- };
120
- ResolveIOMainServer.prototype.getQueueManager = function () {
121
- return this._queueManager;
122
- };
123
- ResolveIOMainServer.prototype.getSupportManager = function () {
124
- return this._supportManager;
125
- };
126
- ResolveIOMainServer.prototype.createServer = function () {
127
- var _this = this;
128
- // Start express server
129
- this._server = http_1.createServer(this._app);
130
- // Start websocket server
131
- // Verify client with token before opening socket
132
- this._wss = new WebSocket.Server({
133
- server: this._server,
134
- verifyClient: function (info, cb) { return __awaiter(_this, void 0, void 0, function () {
135
- var infoData, token;
136
- var _this = this;
137
- return __generator(this, function (_a) {
138
- infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
139
- if (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']) {
140
- cb(false, 401, 'Unauthorized');
141
- }
142
- else {
143
- if (infoData[1]) { //app version
144
- token = infoData[0];
145
- if (!token) {
146
- cb(false, 401, 'Unauthorized');
147
- }
148
- else {
149
- jwt.verify(token, this._serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
150
- var user, err_1;
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0:
154
- if (!err) return [3 /*break*/, 1];
155
- cb(false, 401, 'Unauthorized');
156
- return [3 /*break*/, 5];
157
- case 1:
158
- info.req['id_user'] = decoded['id_user'];
159
- _a.label = 2;
160
- case 2:
161
- _a.trys.push([2, 4, , 5]);
162
- return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user']).exec()];
163
- case 3:
164
- user = _a.sent();
165
- if (user) {
166
- info.req['user'] = user.fullname;
167
- cb(true);
168
- }
169
- else {
170
- cb(false);
171
- }
172
- return [3 /*break*/, 5];
173
- case 4:
174
- err_1 = _a.sent();
175
- cb(false);
176
- return [3 /*break*/, 5];
177
- case 5: return [2 /*return*/];
178
- }
179
- });
180
- }); });
181
- }
182
- }
183
- else {
184
- cb(false, 401, 'Invalid Version');
185
- }
186
- }
187
- return [2 /*return*/];
188
- });
189
- }); }
190
- });
191
- // Start Mongoose (MongoDB Connection)
192
- this.setUpMongoose();
193
- };
194
- ResolveIOMainServer.prototype.setUpMongoose = function () {
195
- this.setUpPassport();
196
- // Enable lean by default
197
- var __setOptions = mongoose_1.Query.prototype.setOptions;
198
- mongoose_1.Query.prototype.setOptions = function (options) {
199
- if (this._mongooseOptions.lean == null && this.mongooseCollection.collectionName !== 'users') {
200
- this._mongooseOptions.lean = true;
201
- }
202
- __setOptions.apply(this, arguments);
203
- return this;
204
- };
205
- // Start Managers
206
- this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
207
- this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig);
208
- this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig);
209
- this._cronManager = new cron_manager_1.CronManager(this);
210
- this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
211
- this.listen();
212
- mongoose.set('useFindAndModify', false);
213
- // mongoose.set('useCreateIndexes', true);
214
- };
215
- ResolveIOMainServer.prototype.setUpPassport = function () {
216
- // Set up login passort
217
- this._app.use(passport.initialize());
218
- // Start user authentication
219
- passport.use(new passportlocal.Strategy(user_collection_1.Users.authenticate()));
220
- passport.serializeUser(user_collection_1.Users.serializeUser());
221
- passport.deserializeUser(user_collection_1.Users.deserializeUser());
222
- };
223
- // Listen to port for http/websocket
224
- ResolveIOMainServer.prototype.listen = function () {
225
- var _this = this;
226
- this._server.listen(this._port, function () {
227
- console.log('Running server on port %s', _this._port);
228
- });
229
- // On websocket connection (already verified)
230
- this._wss.on('connection', function (ws, req) {
231
- // Get user from token
232
- ws['id_user'] = req.id_user;
233
- ws['user'] = req.user;
234
- ws['id_socket'] = uuid();
235
- ws['retryCnt'] = 0;
236
- // Use for keeping connection alive (ping/pong)
237
- ws['isAlive'] = true;
238
- ws.on('pong', function () {
239
- ws['isAlive'] = true;
240
- ws['pongTime'] = new Date();
241
- ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
242
- _this._subscriptionManager.loggedInLatency(ws);
243
- });
244
- ws['versionTimer'] = setTimeout(function () {
245
- _this.unsubscribeWS(ws);
246
- ws.terminate();
247
- }, 10000);
248
- // On data received (message)
249
- ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
250
- var _a, _b, _c, _d, _e, data, messageId, type, method, serverRes, methodCall, subType, pub, supportMethod, serverRes;
251
- var _this = this;
252
- return __generator(this, function (_f) {
253
- switch (_f.label) {
254
- case 0:
255
- data = JSON.parse(message, common_1.dateReviver);
256
- // console.log(data);
257
- if (data[0] === 'ping') {
258
- if (ws && ws.readyState === ws.OPEN) {
259
- ws.send('pong', function (error) {
260
- if (error) {
261
- console.log('Error on WS: ', error);
262
- _this.unsubscribeWS(ws);
263
- }
264
- });
265
- }
266
- return [2 /*return*/];
267
- }
268
- messageId = data.shift();
269
- type = data.shift();
270
- method = '';
271
- if (!(type === 'method')) return [3 /*break*/, 8];
272
- method = data.shift();
273
- if (method === 'setWSAppVersion') {
274
- clearTimeout(ws['versionTimer']);
275
- }
276
- if (method === 'disconnectWSCommand') {
277
- setTimeout(function () {
278
- _this.unsubscribeWS(ws);
279
- ws.terminate();
280
- }, 5000);
281
- }
282
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
283
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
284
- log_collection_1.Logs.create({
285
- _id: mongoose_1.Types.ObjectId().toHexString(),
286
- date: new Date(),
287
- type: 'client-request',
288
- title: 'Client Request - Method',
289
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
290
- payload: data,
291
- method: method,
292
- user: ws['user'],
293
- messageId: messageId
294
- });
295
- }
296
- else {
297
- log_collection_1.Logs.create({
298
- _id: mongoose_1.Types.ObjectId().toHexString(),
299
- date: new Date(),
300
- type: 'client-request',
301
- title: 'Client Request - Method',
302
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
303
- payload: 'Too Big',
304
- method: method,
305
- user: ws['user'],
306
- messageId: messageId
307
- });
308
- }
309
- }
310
- serverRes = {
311
- messageId: messageId,
312
- hasError: false,
313
- data: 'ACK'
314
- };
315
- if (ws && ws.readyState === ws.OPEN) {
316
- ws.send(JSON.stringify(serverRes), function (error) {
317
- if (error) {
318
- console.log('Error on WS: ', error);
319
- _this.unsubscribeWS(ws);
320
- }
321
- });
322
- }
323
- if (!this._methodManager._methods[method]) return [3 /*break*/, 6];
324
- if (!this._methodManager._methods[method].skipQueue) return [3 /*break*/, 1];
325
- (_a = this._methodManager).callMethod.apply(_a, [ws, messageId, method].concat(data));
326
- return [3 /*break*/, 5];
327
- case 1: return [4 /*yield*/, method_call_collection_1.MethodCalls.findOne({ $and: [
328
- { id_user: ws['id_user'] },
329
- { message_id: messageId },
330
- { method: method },
331
- { data: JSON.stringify(data) }
332
- ] }).exec()];
333
- case 2:
334
- methodCall = _f.sent();
335
- if (!!methodCall) return [3 /*break*/, 4];
336
- return [4 /*yield*/, method_call_collection_1.MethodCalls.create({
337
- _id: mongoose_1.Types.ObjectId().toHexString(),
338
- __v: 0,
339
- id_user: ws['id_user'],
340
- message_id: messageId,
341
- method: method,
342
- data: JSON.stringify(data)
343
- })];
344
- case 3:
345
- _f.sent();
346
- if (this._methodManager._methods[method]) {
347
- if (this._methodManager._methods[method].skipQueue) {
348
- (_b = this._methodManager).callMethod.apply(_b, [ws, messageId, method].concat(data));
349
- }
350
- else {
351
- this._queueManager.addMethodToQueue(ws['id_socket'], ws['id_user'], ws['user'], messageId, method, data);
352
- }
353
- }
354
- else {
355
- console.log('Could not find method: ' + method);
356
- }
357
- return [3 /*break*/, 5];
358
- case 4:
359
- method_response_collection_1.MethodResponses.findOne({ $and: [
360
- { id_user: ws['id_user'] },
361
- { message_id: messageId },
362
- { method: method },
363
- { data: JSON.stringify(data) }
364
- ] }).exec(function (err, res) {
365
- if (res) {
366
- if (ws && ws.readyState === ws.OPEN) {
367
- ws.send(JSON.stringify(res.response), function (error) {
368
- if (error) {
369
- console.log('Error on WS: ', error);
370
- _this.unsubscribeWS(ws);
371
- }
372
- });
373
- }
374
- }
375
- });
376
- _f.label = 5;
377
- case 5: return [3 /*break*/, 7];
378
- case 6:
379
- console.log('Could not find method: ' + method);
380
- _f.label = 7;
381
- case 7: return [3 /*break*/, 9];
382
- case 8:
383
- if (type === 'methodRetry') {
384
- method = data.shift();
385
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
386
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
387
- log_collection_1.Logs.create({
388
- _id: mongoose_1.Types.ObjectId().toHexString(),
389
- date: new Date(),
390
- type: 'client-request',
391
- title: 'Client Request - Method Retry',
392
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
393
- payload: data,
394
- method: method,
395
- user: ws['user'],
396
- messageId: messageId
397
- });
398
- }
399
- else {
400
- log_collection_1.Logs.create({
401
- _id: mongoose_1.Types.ObjectId().toHexString(),
402
- date: new Date(),
403
- type: 'client-request',
404
- title: 'Client Request - Method Retry',
405
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
406
- payload: 'Too Big',
407
- method: method,
408
- user: ws['user'],
409
- messageId: messageId
410
- });
411
- }
412
- }
413
- method_call_collection_1.MethodCalls.findOne({ $and: [
414
- { id_user: ws['id_user'] },
415
- { message_id: messageId },
416
- { method: method },
417
- { data: JSON.stringify(data) }
418
- ] }).exec(function (err, res) {
419
- if (res) {
420
- var serverRes = {
421
- messageId: messageId,
422
- hasError: false,
423
- data: 'ACK'
424
- };
425
- if (ws && ws.readyState === ws.OPEN) {
426
- ws.send(JSON.stringify(serverRes), function (error) {
427
- if (error) {
428
- console.log('Error on WS: ', error);
429
- _this.unsubscribeWS(ws);
430
- }
431
- });
432
- }
433
- }
434
- else {
435
- var serverRes = {
436
- messageId: messageId,
437
- hasError: false,
438
- data: 'NACK'
439
- };
440
- if (ws && ws.readyState === ws.OPEN) {
441
- ws.send(JSON.stringify(serverRes), function (error) {
442
- if (error) {
443
- console.log('Error on WS: ', error);
444
- _this.unsubscribeWS(ws);
445
- }
446
- });
447
- }
448
- }
449
- });
450
- }
451
- else if (type === 'methodResponse') {
452
- method = data.shift();
453
- if (method !== 'countQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'setWSAppVersion') {
454
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
455
- log_collection_1.Logs.create({
456
- _id: mongoose_1.Types.ObjectId().toHexString(),
457
- date: new Date(),
458
- type: 'client-request',
459
- title: 'Client Request - Method Response',
460
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
461
- payload: data,
462
- method: method,
463
- user: ws['user'],
464
- messageId: messageId
465
- });
466
- }
467
- else {
468
- log_collection_1.Logs.create({
469
- _id: mongoose_1.Types.ObjectId().toHexString(),
470
- date: new Date(),
471
- type: 'client-request',
472
- title: 'Client Request - Method Response',
473
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Method: ' + method,
474
- payload: 'Too Big',
475
- method: method,
476
- user: ws['user'],
477
- messageId: messageId
478
- });
479
- }
480
- }
481
- method_response_collection_1.MethodResponses.findOne({ $and: [
482
- { id_user: ws['id_user'] },
483
- { message_id: messageId },
484
- { method: method },
485
- { data: JSON.stringify(data) }
486
- ] }).exec(function (err, res) {
487
- if (res) {
488
- if (ws && ws.readyState === ws.OPEN) {
489
- ws.send(JSON.stringify(res.response), function (error) {
490
- if (error) {
491
- console.log('Error on WS: ', error);
492
- _this.unsubscribeWS(ws);
493
- }
494
- });
495
- }
496
- }
497
- });
498
- }
499
- // Subscription call
500
- else if (type === 'subscription') {
501
- subType = data.shift();
502
- pub = data.shift();
503
- // Subscribe
504
- if (subType === 'sub') {
505
- (_c = this._subscriptionManager).subscribe.apply(_c, [ws, messageId, pub].concat(data));
506
- }
507
- // Unsubscribe
508
- else {
509
- (_d = this._subscriptionManager).unsubscribe.apply(_d, [ws, messageId, pub].concat(data));
510
- }
511
- }
512
- else if (type === 'support') {
513
- supportMethod = data.shift();
514
- // if (supportMethod !== 'countQuery' && supportMethod !== 'countCollectionWithQuery' && supportMethod !== 'find' && supportMethod !== 'findOne' && supportMethod !== 'findWithOptions' && method !== 'setWSAppVersion' && method !== 'uploadFileAndSave') {
515
- if (common_1.getBinarySize(JSON.stringify(data)) < 200000) {
516
- log_collection_1.Logs.create({
517
- _id: mongoose_1.Types.ObjectId().toHexString(),
518
- date: new Date(),
519
- type: 'client-request',
520
- title: 'Client Request - Support',
521
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod,
522
- payload: data,
523
- method: supportMethod,
524
- user: ws['user'],
525
- messageId: messageId
526
- });
527
- }
528
- else {
529
- log_collection_1.Logs.create({
530
- _id: mongoose_1.Types.ObjectId().toHexString(),
531
- date: new Date(),
532
- type: 'client-request',
533
- title: 'Client Request - Support',
534
- message: 'User: ' + ws['user'] + ', Type: ' + type + ', MessageId: ' + messageId + ', Support Method: ' + supportMethod,
535
- payload: 'Too Big',
536
- method: supportMethod,
537
- user: ws['user'],
538
- messageId: messageId
539
- });
540
- }
541
- serverRes = {
542
- messageId: messageId,
543
- hasError: false,
544
- data: 'ACK'
545
- };
546
- if (ws && ws.readyState === ws.OPEN) {
547
- ws.send(JSON.stringify(serverRes), function (error) {
548
- if (error) {
549
- console.log('Error on WS: ', error);
550
- _this.unsubscribeWS(ws);
551
- }
552
- });
553
- }
554
- if (this._supportManager._supportMethods[supportMethod]) {
555
- (_e = this._supportManager).callSupportMethod.apply(_e, [ws, messageId, supportMethod].concat(data));
556
- }
557
- else {
558
- console.log('Could not find support method: ' + supportMethod);
559
- }
560
- }
561
- _f.label = 9;
562
- case 9: return [2 /*return*/];
563
- }
564
- });
565
- }); });
566
- ws.on('close', function () {
567
- _this.unsubscribeWS(ws);
568
- });
569
- });
570
- // Keep alive timer to ping/pong
571
- setInterval(function () {
572
- _this._wss.clients.forEach(function (ws) {
573
- if (ws['isAlive'] === false) {
574
- ws['retryCnt']++;
575
- if (ws['retryCnt'] >= 12) {
576
- _this.unsubscribeWS(ws);
577
- ws.terminate();
578
- }
579
- else {
580
- ws['pingTime'] = new Date();
581
- ws.ping(function () { });
582
- }
583
- }
584
- else {
585
- ws['retryCnt'] = 0;
586
- ws['isAlive'] = false;
587
- ws['pingTime'] = new Date();
588
- ws.ping(function () { });
589
- }
590
- });
591
- }, 5000);
592
- };
593
- ResolveIOMainServer.prototype.unsubscribeWS = function (ws) {
594
- this._subscriptionManager.unsubscribeAll(ws);
595
- };
596
- return ResolveIOMainServer;
597
- }());
598
- exports.default = ResolveIOMainServer;
599
- // export * from './collections/active-subscription.collection';
600
- // export * from './collections/app-status.collection';
601
- // export * from './collections/app-version.collection';
602
- // export * from './collections/counter.collection';
603
- // export * from './collections/cron-job-history.collection';
604
- // export * from './collections/cron-job.collection';
605
- // export * from './collections/file.collection';
606
- // export * from './collections/flag.collection';
607
- // export * from './collections/log.collection';
608
- // export * from './collections/logged-in-users.collection';
609
- // export * from './collections/method-call.collection';
610
- // export * from './collections/method-response.collection';
611
- // export * from './collections/queue-flag.collection';
612
- // export * from './collections/queue-method.collection';
613
- // export * from './collections/queue-response.collection';
614
- // export * from './collections/support-ticket.collection';
615
- // export * from './collections/user.collection';
616
- // export * from './managers/cron.manager';
617
- // export * from './managers/method.manager';
618
- // export * from './managers/queue-method.manager';
619
- // export * from './managers/subscription.manager';
620
- // export * from './managers/support.manager';
621
- // export * from './models/active-subscription.model';
622
- // export * from './models/app-status.model';
623
- // export * from './models/app-version.model';
624
- // export * from './models/collection-document.model';
625
- // export * from './models/counter.model';
626
- // // export * from './models/cron-job-history.model';
627
- // export * from './models/cron-job.model';
628
- // export * from './models/dialog.model';
629
- // export * from './models/file.model';
630
- // export * from './models/flag.model';
631
- // export * from './models/log.model';
632
- // export * from './models/method.model';
633
- // export * from './models/pagination.model';
634
- // export * from './models/permission.model';
635
- // export * from './models/select-data-label.model';
636
- // export * from './models/server-response.model';
637
- // export * from './models/support-method.model';
638
- // export * from './models/support-ticket.model';
639
- // export * from './models/user.model';
640
- // export * from './util/common';
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(n,i,a,u){return new(a||(a=Promise))(function(e,t){function o(e){try{r(u.next(e))}catch(e){t(e)}}function s(e){try{r(u.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new a(function(e){e(t.value)}).then(o,s)}r((u=u.apply(n,i||[])).next())})},__generator=this&&this.__generator||function(o,s){var r,n,i,e,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&t[0]?n.return:t[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,t[1])).done)return i;switch(n=0,i&&(t=[2&t[0],i.value]),t[0]){case 0:case 1:i=t;break;case 4:return a.label++,{value:t[1],done:!1};case 5:a.label++,n=t[1],t=[0];continue;case 7:t=a.ops.pop(),a.trys.pop();continue;default:if(!(i=0<(i=a.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){a=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3])){a.label=t[1];break}if(6===t[0]&&a.label<i[1]){a.label=i[1],i=t;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(t);break}i[2]&&a.ops.pop(),a.trys.pop();continue}t=s.call(o,a)}catch(e){t=[6,e],n=0}finally{r=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};Object.defineProperty(exports,"__esModule",{value:!0});var http_1=require("http"),express=require("express"),mongoose=require("mongoose"),bodyParser=require("body-parser"),passport=require("passport"),passportlocal=require("passport-local"),WebSocket=require("ws"),jwt=require("jsonwebtoken"),uuid=require("uuid/v4"),auth_1=require("./http/auth"),common_1=require("./util/common"),health_1=require("./http/health"),method_call_collection_1=require("./collections/method-call.collection"),mongoose_1=require("mongoose"),method_response_collection_1=require("./collections/method-response.collection"),log_collection_1=require("./collections/log.collection"),moment=require("moment"),user_collection_1=require("./collections/user.collection"),cron_manager_1=require("./managers/cron.manager"),method_manager_1=require("./managers/method.manager"),subscription_manager_1=require("./managers/subscription.manager"),support_manager_1=require("./managers/support.manager"),queue_method_manager_1=require("./managers/queue-method.manager"),ResolveIOMainServer=function(){function e(e,t){this._resolveioServer=e,this._serverConfig=t,this._app=express(),this._app.use(bodyParser.json({limit:"5mb"})),this._app.use(bodyParser.urlencoded({limit:"5mb",extended:!0})),this._port=process.env.PORT||t.PORT,this.createServer(),this._app.use(function(e,t,o){t.setHeader("Access-Control-Allow-Origin","*"),t.setHeader("Access-Control-Allow-Methods","GET, POST"),t.setHeader("Access-Control-Allow-Headers","X-Requested-With,content-type"),t.setHeader("Access-Control-Allow-Credentials","false"),o()}),auth_1.setupAuthRoutes(this,this._app,t),health_1.setupHealthRoutes(this._app,t)}return e.prototype.getWS=function(t){var o=null;return this._wss.clients.forEach(function(e){e.id_socket===t&&(o=e)}),o},e.prototype.getWSList=function(){var t=[];return this._wss.clients.forEach(function(e){t.push(e.id_socket)}),t},e.prototype.getCronManager=function(){return this._cronManager},e.prototype.getMethodManager=function(){return this._methodManager},e.prototype.getSubscriptionManager=function(){return this._subscriptionManager},e.prototype.getQueueManager=function(){return this._queueManager},e.prototype.getSupportManager=function(){return this._supportManager},e.prototype.createServer=function(){var e=this;this._server=http_1.createServer(this._app),this._wss=new WebSocket.Server({server:this._server,verifyClient:function(n,i){return __awaiter(e,void 0,void 0,function(){var t,o,r=this;return __generator(this,function(e){return t=n.req.headers["sec-websocket-protocol"].split(/,/),n.origin!==this._serverConfig.ROOT_URL&&n.origin!==this._serverConfig.SEC_ROOT_URL&&n.origin!==this._serverConfig.RESOLVEIO_URL&&n.origin!==this._serverConfig.RESOLVEIO_SECONDARY_URL?i(!1,401,"Unauthorized"):t[1]?(o=t[0])?jwt.verify(o,this._serverConfig.JWT_SECRET,function(o,s){return __awaiter(r,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return o?(i(!1,401,"Unauthorized"),[3,5]):[3,1];case 1:n.req.id_user=s.id_user,e.label=2;case 2:return e.trys.push([2,4,,5]),[4,user_collection_1.Users.findById(s.id_user).exec()];case 3:return(t=e.sent())?(n.req.user=t.fullname,i(!0)):i(!1),[3,5];case 4:return e.sent(),i(!1),[3,5];case 5:return[2]}})})}):i(!1,401,"Unauthorized"):i(!1,401,"Invalid Version"),[2]})})}}),this.setUpMongoose()},e.prototype.setUpMongoose=function(){this.setUpPassport();var t=mongoose_1.Query.prototype.setOptions;mongoose_1.Query.prototype.setOptions=function(e){return null==this._mongooseOptions.lean&&"users"!==this.mongooseCollection.collectionName&&(this._mongooseOptions.lean=!0),t.apply(this,arguments),this},this._subscriptionManager=new subscription_manager_1.SubscriptionManager(this,this._wss,this._serverConfig),this._methodManager=new method_manager_1.MethodManager(this,this._serverConfig),this._supportManager=new support_manager_1.SupportManager(this,this._serverConfig),this._cronManager=new cron_manager_1.CronManager(this),this._queueManager=new queue_method_manager_1.QueueMethodManager(this),this.listen(),mongoose.set("useFindAndModify",!1)},e.prototype.setUpPassport=function(){this._app.use(passport.initialize()),passport.use(new passportlocal.Strategy(user_collection_1.Users.authenticate())),passport.serializeUser(user_collection_1.Users.serializeUser()),passport.deserializeUser(user_collection_1.Users.deserializeUser())},e.prototype.listen=function(){var t=this;this._server.listen(this._port,function(){console.log("Running server on port %s",t._port)}),this._wss.on("connection",function(m,e){m.id_user=e.id_user,m.user=e.user,m.id_socket=uuid(),m.retryCnt=0,m.isAlive=!0,m.on("pong",function(){m.isAlive=!0,m.pongTime=new Date,m.latency=moment.duration(moment(m.pongTime).diff(m.pingTime)).asMilliseconds(),t._subscriptionManager.loggedInLatency(m)}),m.versionTimer=setTimeout(function(){t.unsubscribeWS(m),m.terminate()},1e4),m.on("message",function(h){return __awaiter(t,void 0,void 0,function(){var t,o,s,r,n,i,a,u,c,l,d,p,_,g=this;return __generator(this,function(e){switch(e.label){case 0:return"ping"===(i=JSON.parse(h,common_1.dateReviver))[0]?(m&&m.readyState===m.OPEN&&m.send("pong",function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),[2]):(a=i.shift(),u=i.shift(),c="","method"!==u?[3,8]:("setWSAppVersion"===(c=i.shift())&&clearTimeout(m.versionTimer),"disconnectWSCommand"===c&&setTimeout(function(){g.unsubscribeWS(m),m.terminate()},5e3),"countQuery"!==c&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),_={messageId:a,hasError:!1,data:"ACK"},m&&m.readyState===m.OPEN&&m.send(JSON.stringify(_),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),this._methodManager._methods[c]?this._methodManager._methods[c].skipQueue?((t=this._methodManager).callMethod.apply(t,[m,a,c].concat(i)),[3,5]):[3,1]:[3,6]));case 1:return[4,method_call_collection_1.MethodCalls.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec()];case 2:return e.sent()?[3,4]:[4,method_call_collection_1.MethodCalls.create({_id:mongoose_1.Types.ObjectId().toHexString(),__v:0,id_user:m.id_user,message_id:a,method:c,data:JSON.stringify(i)})];case 3:return e.sent(),this._methodManager._methods[c]?this._methodManager._methods[c].skipQueue?(o=this._methodManager).callMethod.apply(o,[m,a,c].concat(i)):this._queueManager.addMethodToQueue(m.id_socket,m.id_user,m.user,a,c,i):console.log("Could not find method: "+c),[3,5];case 4:method_response_collection_1.MethodResponses.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){t&&m&&m.readyState===m.OPEN&&m.send(JSON.stringify(t.response),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}),e.label=5;case 5:return[3,7];case 6:console.log("Could not find method: "+c),e.label=7;case 7:return[3,9];case 8:"methodRetry"===u?("countQuery"!==(c=i.shift())&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Retry",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Retry",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),method_call_collection_1.MethodCalls.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){if(t){var o={messageId:a,hasError:!1,data:"ACK"};m&&m.readyState===m.OPEN&&m.send(JSON.stringify(o),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}else{o={messageId:a,hasError:!1,data:"NACK"};m&&m.readyState===m.OPEN&&m.send(JSON.stringify(o),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})}})):"methodResponse"===u?("countQuery"!==(c=i.shift())&&"countCollectionWithQuery"!==c&&"find"!==c&&"findOne"!==c&&"findWithOptions"!==c&&"setWSAppVersion"!==c&&(common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Response",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:i,method:c,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Method Response",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Method: "+c,payload:"Too Big",method:c,user:m.user,messageId:a})),method_response_collection_1.MethodResponses.findOne({$and:[{id_user:m.id_user},{message_id:a},{method:c},{data:JSON.stringify(i)}]}).exec(function(e,t){t&&m&&m.readyState===m.OPEN&&m.send(JSON.stringify(t.response),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))})})):"subscription"===u?(l=i.shift(),d=i.shift(),"sub"===l?(s=this._subscriptionManager).subscribe.apply(s,[m,a,d].concat(i)):(r=this._subscriptionManager).unsubscribe.apply(r,[m,a,d].concat(i))):"support"===u&&(p=i.shift(),common_1.getBinarySize(JSON.stringify(i))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Support",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Support Method: "+p,payload:i,method:p,user:m.user,messageId:a}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-request",title:"Client Request - Support",message:"User: "+m.user+", Type: "+u+", MessageId: "+a+", Support Method: "+p,payload:"Too Big",method:p,user:m.user,messageId:a}),_={messageId:a,hasError:!1,data:"ACK"},m&&m.readyState===m.OPEN&&m.send(JSON.stringify(_),function(e){e&&(console.log("Error on WS: ",e),g.unsubscribeWS(m))}),this._supportManager._supportMethods[p]?(n=this._supportManager).callSupportMethod.apply(n,[m,a,p].concat(i)):console.log("Could not find support method: "+p)),e.label=9;case 9:return[2]}})})}),m.on("close",function(){t.unsubscribeWS(m)})}),setInterval(function(){t._wss.clients.forEach(function(e){!1===e.isAlive?(e.retryCnt++,12<=e.retryCnt?(t.unsubscribeWS(e),e.terminate()):(e.pingTime=new Date,e.ping(function(){}))):(e.retryCnt=0,e.isAlive=!1,e.pingTime=new Date,e.ping(function(){}))})},5e3)},e.prototype.unsubscribeWS=function(e){this._subscriptionManager.unsubscribeAll(e)},e}();exports.ResolveIOMainServer=ResolveIOMainServer;