Skip to content

Commit 1052c1f

Browse files
achim-kViktor Kunovski
authored andcommitted
Prevent multiple web socket connections being opened. (#304)
1 parent 0e62589 commit 1052c1f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/core/Ros.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ Ros.prototype.connect = function(url) {
6969
this.socket.on('error', this.socket.onerror);
7070
} else if (this.transportLibrary.constructor.name === 'RTCPeerConnection') {
7171
this.socket = assign(this.transportLibrary.createDataChannel(url, this.transportOptions), socketAdapter(this));
72-
}else {
73-
this.socket = assign(new WebSocket(url), socketAdapter(this));
72+
} else {
73+
if (!this.socket || this.socket.readyState === WebSocket.CLOSED) {
74+
this.socket = assign(new WebSocket(url), socketAdapter(this));
75+
}
7476
}
7577

7678
};

0 commit comments

Comments
 (0)