diff --git a/crates/lox-wasm/index.html b/crates/lox-wasm/index.html index abbc18d..4c7c7e2 100644 --- a/crates/lox-wasm/index.html +++ b/crates/lox-wasm/index.html @@ -5,45 +5,7 @@ Lox binding test - + diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js new file mode 100644 index 0000000..0d48133 --- /dev/null +++ b/crates/lox-wasm/index.js @@ -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(); + }); +}