Put lox test script into its own file
This commit is contained in:
parent
9de53da203
commit
21a29a09eb
|
@ -5,45 +5,7 @@
|
|||
<title>Lox binding test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
init().then(() => {
|
||||
set_panic_hook();
|
||||
request_open_invite().then((token) => {
|
||||
open_invite(token);
|
||||
});
|
||||
});
|
||||
|
||||
function request_open_invite() {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status !== 200) {
|
||||
console.log("Error. Status code: "+xhr.status);
|
||||
console.log(xhr);
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log("Got invitation token: "+response.invite);
|
||||
fulfill(response.invite);
|
||||
return;
|
||||
};
|
||||
try {
|
||||
xhr.open('GET', "http://localhost:8001");
|
||||
} catch (err) {
|
||||
console.log("Error connecting to lox bridge db");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="module" src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
||||
init().then(() => {
|
||||
set_panic_hook();
|
||||
request_open_invite().then((token) => {
|
||||
open_invite(token);
|
||||
});
|
||||
});
|
||||
|
||||
function request_open_invite() {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.DONE !== xhr.readyState) {
|
||||
return;
|
||||
}
|
||||
if (xhr.status !== 200) {
|
||||
console.log("Error. Status code: "+xhr.status);
|
||||
console.log(xhr);
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log("Got invitation token: "+response.invite);
|
||||
fulfill(response.invite);
|
||||
return;
|
||||
};
|
||||
try {
|
||||
xhr.open('GET', "http://localhost:8001");
|
||||
} catch (err) {
|
||||
console.log("Error connecting to lox bridge db");
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue