WebSocket: добавлен метод get-config

This commit is contained in:
Book Pauk
2020-01-23 15:54:46 +07:00
parent 8df80ce738
commit 00cc63b7cd
4 changed files with 29 additions and 8 deletions

View File

@@ -1,4 +1,6 @@
const WebSocket = require ('ws');
const _ = require('lodash');
const WorkerState = require('../core/WorkerState');//singleton
const utils = require('../core/utils');
@@ -42,6 +44,8 @@ class WebSocketController {
switch (req.action) {
case 'test':
this.test(req, ws); break;
case 'get-config':
this.getConfig(req, ws); break;
case 'worker-get-state':
this.workerGetState(req, ws); break;
case 'worker-get-state-finish':
@@ -70,6 +74,14 @@ class WebSocketController {
this.send({message: 'Liberama project is awesome'}, req, ws);
}
async getConfig(req, ws) {
if (Array.isArray(req.params)) {
this.send(_.pick(this.config, req.params), req, ws);
} else {
throw new Error('params is not an array');
}
}
async workerGetState(req, ws) {
if (!req.workerId)
throw new Error(`key 'workerId' is wrong`);