|
@@ -1,6 +1,8 @@
|
|
const WebSocket = require ('ws');
|
|
const WebSocket = require ('ws');
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
+const WorkerState = require('../core/WorkerState');//singleton
|
|
|
|
+const WebWorker = require('../core/WebWorker');//singleton
|
|
const log = new (require('../core/AppLogger'))().log;//singleton
|
|
const log = new (require('../core/AppLogger'))().log;//singleton
|
|
//const utils = require('../core/utils');
|
|
//const utils = require('../core/utils');
|
|
|
|
|
|
@@ -12,6 +14,9 @@ class WebSocketController {
|
|
this.config = config;
|
|
this.config = config;
|
|
this.isDevelopment = (config.branch == 'development');
|
|
this.isDevelopment = (config.branch == 'development');
|
|
|
|
|
|
|
|
+ this.workerState = new WorkerState();
|
|
|
|
+ this.webWorker = new WebWorker(config);
|
|
|
|
+
|
|
this.wss = wss;
|
|
this.wss = wss;
|
|
|
|
|
|
wss.on('connection', (ws) => {
|
|
wss.on('connection', (ws) => {
|
|
@@ -59,6 +64,8 @@ class WebSocketController {
|
|
await this.test(req, ws); break;
|
|
await this.test(req, ws); break;
|
|
case 'get-config':
|
|
case 'get-config':
|
|
await this.getConfig(req, ws); break;
|
|
await this.getConfig(req, ws); break;
|
|
|
|
+ case 'get-worker-state':
|
|
|
|
+ await this.getWorkerState(req, ws); break;
|
|
|
|
|
|
default:
|
|
default:
|
|
throw new Error(`Action not found: ${req.action}`);
|
|
throw new Error(`Action not found: ${req.action}`);
|
|
@@ -100,6 +107,14 @@ class WebSocketController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async getWorkerState(req, ws) {
|
|
|
|
+ if (!req.workerId)
|
|
|
|
+ throw new Error(`key 'workerId' is empty`);
|
|
|
|
+
|
|
|
|
+ const state = this.workerState.getState(req.workerId);
|
|
|
|
+ this.send((state ? state : {}), req, ws);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = WebSocketController;
|
|
module.exports = WebSocketController;
|