50 lines
1.3 KiB
HTML
50 lines
1.3 KiB
HTML
![]() |
<!DOCTYPE html>
|
||
|
<html lang="en-US">
|
||
|
<head>
|
||
|
<meta charset="utf-8" />
|
||
|
<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>
|
||
|
</body>
|
||
|
</html>
|
||
|
|