Доработки WebSocketConnection
This commit is contained in:
@@ -5,11 +5,12 @@ const { VueLoaderPlugin } = require('vue-loader');
|
||||
const clientDir = path.resolve(__dirname, '../client');
|
||||
|
||||
module.exports = {
|
||||
/*resolve: {
|
||||
resolve: {
|
||||
alias: {
|
||||
vue: '@vue/compat'
|
||||
ws: false,
|
||||
//vue: '@vue/compat'
|
||||
}
|
||||
},*/
|
||||
},
|
||||
entry: [`${clientDir}/main.js`],
|
||||
output: {
|
||||
publicPath: '/app/',
|
||||
|
||||
@@ -219,7 +219,7 @@ class Reader {
|
||||
const state = response.state;
|
||||
if (!state)
|
||||
throw new Error('Неверный ответ api');
|
||||
if (response.state == 'error') {
|
||||
if (state == 'error') {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,7 @@ class WebSocketController {
|
||||
ws.lastActivity = Date.now();
|
||||
|
||||
//pong for WebSocketConnection
|
||||
if (req._rpo === 1)
|
||||
this.send({_rok: 1}, req, ws);
|
||||
this.send({_rok: 1}, req, ws);
|
||||
|
||||
switch (req.action) {
|
||||
case 'test':
|
||||
|
||||
@@ -9,8 +9,7 @@ const cleanPeriod = 5*1000;//5 секунд
|
||||
class WebSocketConnection {
|
||||
//messageLifeTime в секундах (проверка каждый cleanPeriod интервал)
|
||||
constructor(url, openTimeoutSecs = 10, messageLifeTimeSecs = 30) {
|
||||
//const ws = 'ws';//for nodejs
|
||||
this.WebSocket = (isBrowser ? WebSocket : null/*for nodejs require(ws)*/);
|
||||
this.WebSocket = (isBrowser ? WebSocket : require('ws'));
|
||||
this.url = url;
|
||||
this.ws = null;
|
||||
this.listeners = [];
|
||||
@@ -166,7 +165,7 @@ class WebSocketConnection {
|
||||
this.requestId = (this.requestId < 1000000 ? this.requestId + 1 : 1);
|
||||
const requestId = this.requestId;//реентерабельность!!!
|
||||
|
||||
this.ws.send(JSON.stringify(Object.assign({requestId, _rpo: 1}, req)));//_rpo: 1 - ждем в ответ _rok: 1
|
||||
this.ws.send(JSON.stringify(Object.assign({requestId}, req)));
|
||||
|
||||
let resp = {};
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user