commit 3ac40fb3d7467df6c0f66b0d156202cbfbf80f09
parent 9c9ca70d05fb2894d4e8113acc3a99a7b582ec78
Author: RobinLinus <robinlinus@users.noreply.github.com>
Date: Fri, 21 Sep 2018 21:04:48 +0200
Don’t reconnect if already connecting
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/client/scripts/network.js b/client/scripts/network.js
@@ -9,7 +9,7 @@ class ServerConnection {
}
_connect() {
- if (this._isConnected()) return;
+ if (this._isConnected() || this._isConnecting()) return;
const ws = new WebSocket(this._endpoint());
ws.binaryType = 'arraybuffer';
ws.onopen = e => console.log('WS: server connected');
@@ -24,6 +24,10 @@ class ServerConnection {
return this._socket && this._socket.readyState === this._socket.OPEN;
}
+ _isConnecting() {
+ return this._socket && this._socket.readyState === this._socket.CONNECTING;
+ }
+
_onMessage(msg) {
msg = JSON.parse(msg);
console.log('WS:', msg);