chiark / gitweb /
seems to try loading
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 23:47:48 +0000 (00:47 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jun 2020 23:47:48 +0000 (00:47 +0100)
templates/loading.tera
templates/script.js

index 869ce5765690eb5e6875c7a397e877914f73c330..7cb658f11ee2a91b0cf90b478bbf79aacc111ef4 100644 (file)
@@ -1,3 +1,4 @@
-<body>
-<h1>Loading!</h1>
-<script src="/_/loading.js"></script>
+<body id="loading_body">
+<h1 id="loading_token" data-token="{{ token }}">Loading!</h1>
+<div id="error"></div>
+<script src="/_/script.js"></script>
index ef32da5eec6aa63937f6b157f12e5285a11b2323..16bdaccbbef52634aed1ffd0a524392d9ce59b40 100644 (file)
@@ -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();