From 1a20c70c41a5f4a7c1e2612f538ea48070bdbfb2 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 29 Oct 2020 12:45:40 +0100 Subject: [PATCH] Send WebSocket messages only if connected --- app/assets/javascripts/editor/websocket.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/editor/websocket.js b/app/assets/javascripts/editor/websocket.js index 1bc26648..09d64975 100644 --- a/app/assets/javascripts/editor/websocket.js +++ b/app/assets/javascripts/editor/websocket.js @@ -86,7 +86,11 @@ CommandSocket.prototype.executeCommand = function(cmd) { * @param data */ CommandSocket.prototype.send = function(data) { - this.websocket.send(data); + // Only send message if WebSocket is open and ready. + // Ignore all other messages (they might hit a wrong container anyway) + if (this.getReadyState() === this.websocket.OPEN) { + this.websocket.send(data); + } }; /**