@resolveio/server-lib 1.0.0-rc22 → 1.0.0-rc24

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/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export declare class ResolveIOServer {
5
5
  private static _supportDB;
6
6
  private static _mainServer;
7
7
  private static _client;
8
+ private static _clientDir;
8
9
  constructor(serverConfig: any, client: string);
9
10
  static connectAndRun(): Promise<{}>;
10
11
  static getClientName(): string;
package/index.js CHANGED
@@ -58,7 +58,7 @@ var ResolveIOServer = /** @class */ (function () {
58
58
  return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
59
59
  case 1:
60
60
  serverApp = (_a.sent()).default;
61
- ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
61
+ ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig, this._clientDir);
62
62
  resolve();
63
63
  return [2 /*return*/];
64
64
  }
@@ -85,7 +85,7 @@ var ResolveIOServer = /** @class */ (function () {
85
85
  return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
86
86
  case 1:
87
87
  serverApp = (_a.sent()).default;
88
- ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
88
+ ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig, this._clientDir);
89
89
  resolve();
90
90
  return [2 /*return*/];
91
91
  }
@@ -114,6 +114,7 @@ var ResolveIOServer = /** @class */ (function () {
114
114
  ResolveIOServer._supportDB = null;
115
115
  ResolveIOServer._mainServer = null;
116
116
  ResolveIOServer._client = '';
117
+ ResolveIOServer._clientDir = '';
117
118
  return ResolveIOServer;
118
119
  }());
119
120
  exports.ResolveIOServer = ResolveIOServer;
@@ -9,9 +9,10 @@ export declare class MethodManager {
9
9
  private _imap;
10
10
  private _aws;
11
11
  private serverConfig;
12
+ private clientDir;
12
13
  private _sendQueue;
13
14
  private _runningQueue;
14
- constructor(mainServer: any, serverConfig: any);
15
+ constructor(mainServer: any, serverConfig: any, clientDir: any);
15
16
  getMainServer(): ResolveIOMainServer;
16
17
  methods(method: MethodModel): void;
17
18
  callMethodCron(method: string, ...methodData: any[]): void;
@@ -20,13 +20,14 @@ var mongoose_1 = require("mongoose");
20
20
  var common_1 = require("../util/common");
21
21
  var log_collection_1 = require("../collections/log.collection");
22
22
  var MethodManager = /** @class */ (function () {
23
- function MethodManager(mainServer, serverConfig) {
23
+ function MethodManager(mainServer, serverConfig, clientDir) {
24
24
  var _this = this;
25
25
  this._methods = {};
26
26
  this._sendQueue = [];
27
27
  this._runningQueue = false;
28
28
  this._mainServer = mainServer;
29
29
  this.serverConfig = serverConfig;
30
+ this.clientDir = clientDir;
30
31
  // Fixtures
31
32
  init_1.loadServerInit();
32
33
  cron_jobs_1.loadServerCronJobs();
@@ -262,7 +263,7 @@ var MethodManager = /** @class */ (function () {
262
263
  }
263
264
  }
264
265
  }
265
- (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, { id_user: '', user: '', id_ws: '' })].concat(methodData));
266
+ (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })].concat(methodData));
266
267
  };
267
268
  MethodManager.prototype.callMethodQueue = function (update) {
268
269
  // console.log('Call Method Queue', update);
@@ -330,7 +331,7 @@ var MethodManager = /** @class */ (function () {
330
331
  }
331
332
  }
332
333
  // console.log('Run Method', update.method);
333
- (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
334
+ (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
334
335
  var serverRes = {
335
336
  messageId: update.messageId,
336
337
  hasError: false,
@@ -414,7 +415,7 @@ var MethodManager = /** @class */ (function () {
414
415
  }
415
416
  }
416
417
  }
417
- (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
418
+ (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
418
419
  var serverRes = {
419
420
  messageId: messageId,
420
421
  hasError: false,
@@ -452,7 +453,7 @@ var MethodManager = /** @class */ (function () {
452
453
  return;
453
454
  }
454
455
  }
455
- var promise = (_a = that._methods[method].function).call.apply(_a, [that].concat(methodData));
456
+ var promise = (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype)].concat(methodData));
456
457
  if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
457
458
  promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
458
459
  }
@@ -485,27 +486,57 @@ var MethodManager = /** @class */ (function () {
485
486
  return this._aws;
486
487
  };
487
488
  MethodManager.prototype.readFile = function (fileName) {
489
+ var _this = this;
488
490
  return new Promise(function (resolve, reject) {
489
- fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
490
- if (err) {
491
- reject(err);
492
- }
493
- else {
494
- resolve(res);
491
+ if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
492
+ fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
493
+ if (err) {
494
+ reject(err);
495
+ }
496
+ else {
497
+ resolve(res);
498
+ }
499
+ });
500
+ }
501
+ else {
502
+ if (fs.existsSync(path.join(_this.clientDir, ('../private/' + fileName)))) {
503
+ fs.readFile(path.join(_this.clientDir, ('../private/' + fileName)), 'utf-8', function (err, res) {
504
+ if (err) {
505
+ reject(err);
506
+ }
507
+ else {
508
+ resolve(res);
509
+ }
510
+ });
495
511
  }
496
- });
512
+ }
497
513
  });
498
514
  };
499
515
  MethodManager.prototype.readImage = function (fileName) {
516
+ var _this = this;
500
517
  return new Promise(function (resolve, reject) {
501
- fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
502
- if (err) {
503
- reject(err);
504
- }
505
- else {
506
- resolve(res);
518
+ if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
519
+ fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
520
+ if (err) {
521
+ reject(err);
522
+ }
523
+ else {
524
+ resolve(res);
525
+ }
526
+ });
527
+ }
528
+ else {
529
+ if (fs.existsSync(path.join(_this.clientDir, ('../private/' + fileName)))) {
530
+ fs.readFile(path.join(_this.clientDir, ('../private/' + fileName)), 'base64', function (err, res) {
531
+ if (err) {
532
+ reject(err);
533
+ }
534
+ else {
535
+ resolve(res);
536
+ }
537
+ });
507
538
  }
508
- });
539
+ }
509
540
  });
510
541
  };
511
542
  return MethodManager;
@@ -614,7 +614,7 @@ var SubscriptionManager = /** @class */ (function () {
614
614
  return __generator(this, function (_c) {
615
615
  that = this;
616
616
  if (!that._publications[subscription.publication].ws_specific) { // Same pub for all users
617
- (_a = that._publications[subscription.publication].function).call.apply(_a, [that].concat(subscription.subscriptionData)).then(function (res) {
617
+ (_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
618
618
  var serverRes = {
619
619
  messageId: messageId,
620
620
  hasError: false,
@@ -631,7 +631,7 @@ var SubscriptionManager = /** @class */ (function () {
631
631
  });
632
632
  }
633
633
  else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
634
- (_b = that._publications[subscription.publication].function).call.apply(_b, [that, ws['id_user']].concat(subscription.subscriptionData)).then(function (res) {
634
+ (_b = that._publications[subscription.publication].function).call.apply(_b, [Object.assign({}, that, SubscriptionManager.prototype), ws['id_user']].concat(subscription.subscriptionData)).then(function (res) {
635
635
  var serverRes = {
636
636
  messageId: messageId,
637
637
  hasError: false,
@@ -658,7 +658,7 @@ var SubscriptionManager = /** @class */ (function () {
658
658
  var _this = this;
659
659
  return __generator(this, function (_b) {
660
660
  that = this;
661
- (_a = that._publications[subscription.publication].function).call.apply(_a, [that].concat(subscription.subscriptionData)).then(function (res) {
661
+ (_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
662
662
  subscription.clients.forEach(function (client) {
663
663
  that._wss.clients.forEach(function (ws) {
664
664
  if (ws['id_socket'] === client.id_socket) {
@@ -164,7 +164,7 @@ var SupportManager = /** @class */ (function () {
164
164
  }
165
165
  }
166
166
  }
167
- (_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
167
+ (_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, SupportManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
168
168
  var serverRes = {
169
169
  messageId: messageId,
170
170
  hasError: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "1.0.0-rc22",
3
+ "version": "1.0.0-rc24",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.d.ts CHANGED
@@ -10,13 +10,14 @@ export default class ResolveIOMainServer {
10
10
  private _port;
11
11
  private _wss;
12
12
  private _serverConfig;
13
+ private _clientDir;
13
14
  private _resolveioServer;
14
15
  private _subscriptionManager;
15
16
  private _methodManager;
16
17
  private _queueManager;
17
18
  private _cronManager;
18
19
  private _supportManager;
19
- constructor(mainServer: any, serverConfig: any);
20
+ constructor(mainServer: any, serverConfig: any, clientDir: any);
20
21
  getWS(id_ws: string): any;
21
22
  getWSList(): any[];
22
23
  getCronManager(): CronManager;
package/server-app.js CHANGED
@@ -59,9 +59,10 @@ var subscription_manager_1 = require("./managers/subscription.manager");
59
59
  var support_manager_1 = require("./managers/support.manager");
60
60
  var queue_method_manager_1 = require("./managers/queue-method.manager");
61
61
  var ResolveIOMainServer = /** @class */ (function () {
62
- function ResolveIOMainServer(mainServer, serverConfig) {
62
+ function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
63
63
  this._resolveioServer = mainServer;
64
64
  this._serverConfig = serverConfig;
65
+ this._clientDir = clientDir;
65
66
  // process.on('unhandledException').
66
67
  // Start express app
67
68
  this._app = express();
@@ -204,7 +205,7 @@ var ResolveIOMainServer = /** @class */ (function () {
204
205
  };
205
206
  // Start Managers
206
207
  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._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
208
209
  this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig);
209
210
  this._cronManager = new cron_manager_1.CronManager(this);
210
211
  this._queueManager = new queue_method_manager_1.QueueMethodManager(this);