Use unique ids in call_server_method (#55)

This commit is contained in:
Patrick Kubiak
2022-05-10 10:13:53 -04:00
committed by GitHub
parent 28746e3962
commit 945db5de47
+8 -1
View File
@@ -8,7 +8,7 @@ window.addEventListener("message", function(evt) {
}, false);
async function call_server_method(method_name, arg_object={}) {
let id = `${new Date().getTime()}`;
let id = `${uuidv4()}`;
console.debug(JSON.stringify({
"id": id,
"method": method_name,
@@ -22,6 +22,13 @@ async function call_server_method(method_name, arg_object={}) {
});
}
// Source: https://stackoverflow.com/a/2117523 Thanks!
function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
async function fetch_nocors(url, request={}) {
let args = { method: "POST", headers: {}, body: "" };
request = {...args, ...request};