From 5f61c24dc632c82764431139eca6db1d129e93fc Mon Sep 17 00:00:00 2001 From: Alexander Kastius Date: Thu, 1 Sep 2016 11:18:28 +0200 Subject: [PATCH] Fixed socket calls. --- app/assets/javascripts/editor/evaluation.js.erb | 6 +++--- app/assets/javascripts/editor/websocket.js.erb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/editor/evaluation.js.erb b/app/assets/javascripts/editor/evaluation.js.erb index 0f944239..373ed197 100644 --- a/app/assets/javascripts/editor/evaluation.js.erb +++ b/app/assets/javascripts/editor/evaluation.js.erb @@ -137,13 +137,13 @@ CodeOceanEditorEvaluation = { }, killWebsocketAndContainer: function () { - if (this.websocket.readyState != WebSocket.OPEN) { + if (this.websocket.getReadyState() != WebSocket.OPEN) { return; } this.websocket.send(JSON.stringify({cmd: 'exit'})); - this.websocket.flush(); - this.websocket.close(); + this.websocket.killWebSocket(); + this.hideSpinner(); this.running = false; this.toggleButtonStates(); diff --git a/app/assets/javascripts/editor/websocket.js.erb b/app/assets/javascripts/editor/websocket.js.erb index 4c3f9787..e4c45e24 100644 --- a/app/assets/javascripts/editor/websocket.js.erb +++ b/app/assets/javascripts/editor/websocket.js.erb @@ -88,3 +88,18 @@ CommandSocket.prototype.executeCommand = function(cmd) { CommandSocket.prototype.send = function(data) { this.websocket.send(data); }; + +/** + * Returns the ready state of the socket. + */ +CommandSocket.prototype.getReadyState = function() { + return this.websocket.readyState; +}; + +/** + * Closes the websocket. + */ +CommandSocket.prototype.killWebSocket = function() { + this.websocket.flush(); + this.websocket.close(); +}; \ No newline at end of file