37
37
/* Starts the console server, if it isn't already.
38
38
* This can be called any number of times - it only starts the one server.
39
* Note that this is asynchronous. It will return after signalling to start
40
* the server, but there is no guarantee that it has been started yet.
39
41
* This is a separate step from console_init, as the server is only to be
40
42
* started once the first command is entered.
41
43
* Does not return a value. Writes to global variables
42
44
* server_host, and server_port.
46
* \param callback Function which will be called after the server has been
47
* started. No parameters are passed. May be null.
44
function start_server()
49
function start_server(callback)
46
if (server_started) return;
47
var xhr = ajax_call("consoleservice", "start", {}, "POST");
48
var json_text = xhr.responseText;
49
server_key = JSON.parse(json_text);
50
server_started = true;
56
var callback1 = function(xhr)
58
var json_text = xhr.responseText;
59
server_key = JSON.parse(json_text);
60
server_started = true;
64
ajax_call(callback1, "consoleservice", "start", {}, "POST");
53
67
/** Initialises the console. All apps which import console are required to
204
218
function console_enter_line(inputline, which)
206
/* Start the server if it hasn't already been started */
208
220
var args = {"key": server_key, "text":inputline};
209
var xmlhttp = ajax_call("consoleservice", which, args, "POST");
221
var callback = function(xhr)
223
console_response(inputline, xhr.responseText);
225
ajax_call(callback, "consoleservice", which, args, "POST");
211
var res = JSON.parse(xmlhttp.responseText);
228
function console_response(inputline, responseText)
230
var res = JSON.parse(responseText);
212
231
var output = document.getElementById("console_output");
214
233
var pre = document.createElement("pre");
306
325
case 13: /* Enter key */
307
/* Send the line of text to the server */
308
console_enter_line(inp.value, "chat");
309
hist.submit(inp.value);
310
inp.value = hist.curr();
326
var callback = function()
328
/* Send the line of text to the server */
329
console_enter_line(inp.value, "chat");
330
hist.submit(inp.value);
331
inp.value = hist.curr();
333
/* Start the server if it hasn't already been started */
334
start_server(callback);
312
336
case 38: /* Up arrow */
313
337
hist.up(inp.value);