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