Prechádzať zdrojové kódy

Исправления багов

Book Pauk 5 rokov pred
rodič
commit
fbd50bad1d
1 zmenil súbory, kde vykonal 5 pridanie a 25 odobranie
  1. 5 25
      client/api/WebSocketConnection.js

+ 5 - 25
client/api/WebSocketConnection.js

@@ -98,22 +98,7 @@ class WebSocketConnection {
     }
     }
 
 
     //timeout в минутах (cleanPeriod)
     //timeout в минутах (cleanPeriod)
-    message(timeout = 2) {
-        return new Promise((resolve, reject) => {
-            this.addListener({
-                timeout,
-                onMessage: (mes) => {
-                    resolve(mes);
-                },
-                onError: (e) => {
-                    reject(e);
-                }
-            });
-        });
-    }
-
-    //timeout в минутах (cleanPeriod)
-    messageId(requestId, timeout = 2) {
+    message(requestId, timeout = 2) {
         return new Promise((resolve, reject) => {
         return new Promise((resolve, reject) => {
             this.addListener({
             this.addListener({
                 requestId,
                 requestId,
@@ -129,17 +114,9 @@ class WebSocketConnection {
     }
     }
 
 
     send(req) {
     send(req) {
-        if (this.ws && this.ws.readyState == WebSocket.OPEN) {
-            this.ws.send(JSON.stringify(req));
-        } else {
-            throw new Error('WebSocket connection is not ready');
-        }
-    }
-
-    sendId(req) {
         if (this.ws && this.ws.readyState == WebSocket.OPEN) {
         if (this.ws && this.ws.readyState == WebSocket.OPEN) {
             const requestId = ++this.requestId;
             const requestId = ++this.requestId;
-            this.ws.send(Object.assign({requestId}, JSON.stringify(req)));
+            this.ws.send(JSON.stringify(Object.assign({requestId}, req)));
             return requestId;
             return requestId;
         } else {
         } else {
             throw new Error('WebSocket connection is not ready');
             throw new Error('WebSocket connection is not ready');
@@ -162,6 +139,9 @@ class WebSocketConnection {
             for (const listener of this.listeners) {
             for (const listener of this.listeners) {
                 if (now - listener.regTime < listener.timeout*cleanPeriod - 50) {
                 if (now - listener.regTime < listener.timeout*cleanPeriod - 50) {
                     newListeners.push(listener);
                     newListeners.push(listener);
+                } else {
+                    if (listener.onError)
+                        listener.onError('Время ожидания ответа истекло');
                 }
                 }
             }
             }
             this.listeners = newListeners;
             this.listeners = newListeners;