浏览代码

Don’t reconnect if already connecting

RobinLinus 6 年之前
父节点
当前提交
3ac40fb3d7
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      client/scripts/network.js

+ 5 - 1
client/scripts/network.js

@@ -9,7 +9,7 @@ class ServerConnection {
     }
     }
 
 
     _connect() {
     _connect() {
-        if (this._isConnected()) return;
+        if (this._isConnected() || this._isConnecting()) return;
         const ws = new WebSocket(this._endpoint());
         const ws = new WebSocket(this._endpoint());
         ws.binaryType = 'arraybuffer';
         ws.binaryType = 'arraybuffer';
         ws.onopen = e => console.log('WS: server connected');
         ws.onopen = e => console.log('WS: server connected');
@@ -24,6 +24,10 @@ class ServerConnection {
         return this._socket && this._socket.readyState === this._socket.OPEN;
         return this._socket && this._socket.readyState === this._socket.OPEN;
     }
     }
 
 
+    _isConnecting() {
+        return this._socket && this._socket.readyState === this._socket.CONNECTING;
+    }
+
     _onMessage(msg) {
     _onMessage(msg) {
         msg = JSON.parse(msg);
         msg = JSON.parse(msg);
         console.log('WS:', msg);
         console.log('WS:', msg);