From: Ian Jackson Date: Sun, 21 Jun 2020 23:47:48 +0000 (+0100) Subject: seems to try loading X-Git-Tag: otter-0.2.0~1570 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e461b52e648fe778533c6bcd442e410339e31697;p=otter.git seems to try loading --- diff --git a/templates/loading.tera b/templates/loading.tera index 869ce576..7cb658f1 100644 --- a/templates/loading.tera +++ b/templates/loading.tera @@ -1,3 +1,4 @@ - -

Loading!

- + +

Loading!

+
+ diff --git a/templates/script.js b/templates/script.js index ef32da5e..16bdaccb 100644 --- a/templates/script.js +++ b/templates/script.js @@ -2,25 +2,31 @@ // xxx deployment note: need a whole bunch of domains for SSE conn limit +general_timeout = 10000; messages = Object(); - var our_dnd_type = "text/puvnex-game-server-dummy"; -dragthresh = 5; -space = document.getElementById('space'); - -function new_xhr_then(good,bad) { - // xxx not yet finished?? +function xhr_post_then(url,data,good) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if (xhr.readyState != XMLHttpRequest.DONE) { return; } - if (xhr.status != 200) { bad(xhr); } - good(xhr); + if (xhr.status != 200) { xhr_report_error(xhr); } + else { good(xhr); } }; - return xhr; + xhr.timeout = general_timeout; + xhr.open('POST',url); + xhr.setRequestHeader('Content-Type','application/json'); + xhr.send(data); } - console.log('foo1'); +function xhr_report_error(xhr) { + let error_message = JSON.stringify({ + statusText : xhr.statusText, + responseText : xhr.responseText, + }); + let errornode = document.getElementById('error'); + errornode.textContent = 'Error (reloading may help?):' + error_message; +} function drag_mousedown(e) { drag_cancel(); @@ -82,6 +88,8 @@ messages.TestCounter = function(data) { function startup() { status_node = document.getElementById('status'); status_node.innerHTML = 'js-done' + dragthresh = 5; + space = document.getElementById('space'); es = new EventSource("/_/updates"); es.onmessage = function(event) { @@ -91,4 +99,19 @@ function startup() { } } -startup(); +function doload(){ + console.log('DOLOAD'); + var elem = document.getElementById('loading_token'); + token = elem.dataset.token; + xhr_post_then('/session', + JSON.stringify({ token : token }), + loaded); +} + +function loaded(xhr){ + console.log('LOADED'); + var body = document.getElementById('loading_body'); + body.outerHTML = xhr.response; +} + +doload();