Change calls to match server
This commit is contained in:
parent
d473b53745
commit
235eb90d6e
|
@ -1,9 +1,14 @@
|
||||||
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
import init, { open_invite, set_panic_hook } from "./pkg/lox_wasm.js";
|
||||||
|
var pubkeys = request_pubkeys().then((pubkeys) => {
|
||||||
|
pubkeys
|
||||||
|
});
|
||||||
|
console.log(pubkeys)
|
||||||
init().then(() => {
|
init().then(() => {
|
||||||
set_panic_hook();
|
set_panic_hook();
|
||||||
requested = request_open_invite().then((token) => {
|
requested = request_open_invite().then((token) => {
|
||||||
open_invite(token);
|
open_invite(token);
|
||||||
});
|
});
|
||||||
|
// unsigned_open_lox_credential = handle_new_lox_credential(requested, pubkeys);
|
||||||
// lox_credential = request_new_lox_credential(request_cred[0]).then((lox_cred) => {
|
// lox_credential = request_new_lox_credential(request_cred[0]).then((lox_cred) => {
|
||||||
// handle_new_lox_credential(request_cred[1], response, pubkey);
|
// handle_new_lox_credential(request_cred[1], response, pubkey);
|
||||||
// })
|
// })
|
||||||
|
@ -11,7 +16,7 @@ requested = request_open_invite().then((token) => {
|
||||||
|
|
||||||
function request_open_invite() {
|
function request_open_invite() {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
loxServerRequest("").then((response) => {
|
loxServerRequest("/invite").then((response) => {
|
||||||
console.log("Got invitation token: " + response.invite);
|
console.log("Got invitation token: " + response.invite);
|
||||||
fulfill(response.invite);
|
fulfill(response.invite);
|
||||||
return;
|
return;
|
||||||
|
@ -22,6 +27,19 @@ function request_open_invite() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function request_pubkeys() {
|
||||||
|
return new Promise((fulfill, reject) => {
|
||||||
|
loxServerRequest("/pubkeys").then((response) => {
|
||||||
|
console.log("Got pubkeys: " + JSON.parse(response));
|
||||||
|
fulfill(JSON.parse(response));
|
||||||
|
return;
|
||||||
|
}).catch(() => {
|
||||||
|
console.log("Error requesting open invite from Lox server");
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loxServerRequest(data) {
|
function loxServerRequest(data) {
|
||||||
return new Promise((fulfill, reject) => {
|
return new Promise((fulfill, reject) => {
|
||||||
const xhr = new XMLHttpRequest(data);
|
const xhr = new XMLHttpRequest(data);
|
||||||
|
@ -40,20 +58,16 @@ function loxServerRequest(data) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
if (data != ""){
|
xhr.open('GET', "http://localhost:8001"+data);
|
||||||
xhr.open('GET', "http://localhost:8001");
|
//xhr.open("Post", "http://localhost:8001"+data)
|
||||||
}
|
//xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
else {
|
//var data = JSON.stringify({})
|
||||||
xhr.open("Post", "http://localhost:8001")
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
|
||||||
var data = JSON.stringify({})
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error connecting to lox bridge db");
|
console.log("Error connecting to lox bridge db");
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xhr.send(data);
|
xhr.send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,19 @@ fn concat_string(request: String, state: String) -> String {
|
||||||
return new_string;
|
return new_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deconcat_string(concatString: String) -> (String, String) {
|
||||||
|
|
||||||
|
("hello".to_owned(), "world".to_owned())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn handle_new_lox_credential(state: String, response: String, lox_pub: String) -> Result<String, JsValue> {
|
pub fn handle_new_lox_credential(open_lox_result: String, lox_pub: String) -> Result<String, JsValue> {
|
||||||
unsafe {
|
unsafe {
|
||||||
log(&format!("Using server response: {:?}", response));
|
log(&format!("Using server response: {:?}", open_lox_result));
|
||||||
}
|
}
|
||||||
|
let (state, response) = deconcat_string(open_lox_result);
|
||||||
let deserialized_state = serde_json::from_str(&state).unwrap();
|
let deserialized_state = serde_json::from_str(&state).unwrap();
|
||||||
let deserialized_response = serde_json::from_str(&response).unwrap();
|
let deserialized_response = serde_json::from_str(&response).unwrap();
|
||||||
let deserialized_pubkey = serde_json::from_str(&lox_pub).unwrap();
|
let deserialized_pubkey = serde_json::from_str(&lox_pub).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue