diff --git a/core/client.js b/core/client.js index 21395088..1c6b6e9e 100644 --- a/core/client.js +++ b/core/client.js @@ -1,6 +1,5 @@ "use strict"; -var gHaveIndex = -1; var gSessionId; var gCredentials; var gErrorCount = 0; @@ -122,8 +121,8 @@ function receive(data) { if (line && line.action == "ping") { gSocket.send(JSON.stringify({action: "pong"})); } else if (line && line.action == "session") { - gSessionId = line.session.sessionId; - gCredentials = line.session.credentials; + gSessionId = line.sessionId; + gCredentials = line.credentials; updateLogin(); } else if (line && line[0] && line[0].action == "ready") { if (window.location.hash) { @@ -157,9 +156,6 @@ function receive(data) { print(document.getElementById(target), line); } } - if ("index" in data) { - gHaveIndex = data.index; - } } function autoNewLine(terminal) { @@ -249,6 +245,15 @@ function autoScroll(terminal) { terminal.scrollTop = terminal.scrollHeight - terminal.clientHeight; } +function setErrorMessage(message) { + var node = document.getElementById("status"); + while (node.firstChild) { + node.removeChild(node.firstChild); + } + node.appendChild(document.createTextNode(message)); + node.setAttribute("style", "display: inline; color: #dc322f"); +} + function send(command) { var value = command; if (!command) { @@ -260,12 +265,7 @@ function send(command) { try { gSocket.send(JSON.stringify({action: "command", command: value})); } catch (error) { - var node = document.getElementById("status"); - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(document.createTextNode("Send failed: " + error)); - node.setAttribute("style", "display: inline; color: #dc322f"); + setErrorMessage("Send failed: " + error.toString()); } } @@ -437,4 +437,7 @@ $(document).ready(function() { gSocket.onmessage = function(event) { receive(JSON.parse(event.data)); } + gSocket.onclose = function(event) { + setErrorMessage("Connection closed with code " + event.code); + } }); diff --git a/core/terminal.js b/core/terminal.js index 7a86c735..d5b8105b 100644 --- a/core/terminal.js +++ b/core/terminal.js @@ -174,9 +174,10 @@ function socket(request, response, client) { packageOwner = match[1]; packageName = match[2]; } - response.send(JSON.stringify({action: "hello"}), 0x1); + var sessionId = makeSessionId(); + response.send(JSON.stringify({lines: [{action: "session", sessionId: sessionId, credentials: credentials}]}), 0x1); - process = getSessionProcess(packageOwner, packageName, makeSessionId(), options); + process = getSessionProcess(packageOwner, packageName, sessionId, options); process.terminal.readOutput(function(message) { response.send(JSON.stringify(message), 0x1); });