diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index 0d48133..abf80e2 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -7,6 +7,19 @@ init().then(() => { }); function request_open_invite() { + return new Promise((fulfill, reject) => { + loxServerRequest("").then((response) => { + console.log("Got invitation token: " + response.invite); + fulfill(response.invite); + return; + }).catch(() => { + console.log("Error requesting open invite from Lox server"); + reject(); + }); + }); +} + +function loxServerRequest(data) { return new Promise((fulfill, reject) => { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { @@ -20,8 +33,7 @@ function request_open_invite() { return; } const response = JSON.parse(xhr.responseText); - console.log("Got invitation token: "+response.invite); - fulfill(response.invite); + fulfill(response); return; }; try {