Instructions and a simple test of the bindings

This commit is contained in:
Cecylia Bocovich 2022-11-15 22:03:30 -05:00
parent ebae7fb600
commit 9de53da203
2 changed files with 72 additions and 0 deletions

View File

@ -1,3 +1,26 @@
# lox-wasm
wasm bindings for the lox crate: https://git-crysp.uwaterloo.ca/iang/lox
# Dependencies
```
cargo install wasm-pack
```
# Build
```
wasm-pack build --target web
```
# Testing
The provided `index.html` file can be used for testing the lox bindings. First, follow the instructions to [run a lox server](https://gitlab.torproject.org/cohosh/lox-server).
Then, spin up a simple local webserver in the current directory:
```
python3 -m http.server 8000
```
Next, open the dev console in your browser and navigate to `http://localhost:8000`.

View File

@ -0,0 +1,49 @@
<!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>