delete callback

This commit is contained in:
creeper123123321 2021-03-07 18:52:33 -03:00 committed by GitHub
parent ab67c699b8
commit 0c8280b0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
// SW
navigator.serviceWorker.register("sw.js")
new BroadcastChannel('viaaas-notification').addEventListener("message", e => handleSWMsg(e));
// Minecraft.id
let urlParams = new URLSearchParams();
@ -283,18 +282,13 @@ function resetHtml() {
renderActions();
}
// Websocket
function listen(token) {
socket.send(JSON.stringify({"action": "listen_login_requests", "token": token}));
}
function confirmJoin(hash) {
socket.send(JSON.stringify({action: "session_hash_response", session_hash: hash}));
}
// Notification
var notificationCallbacks = {};
function handleSWMsg(event) {
console.log("sw msg: " + event);
let data = event.data;
let callback = notificationCallbacks[data.tag];
delete notificationCallbacks[data.tag];
if (callback == null) return;
callback(data.action);
}
@ -322,8 +316,18 @@ function authNotification(msg, yes, no) {
return;
}
};
setTimeout(() => { delete notificationCallbacks[tag] }, 30_000);
});
}
new BroadcastChannel("viaaas-notification").addEventListener("message", handleSWMsg);
// Websocket
function listen(token) {
socket.send(JSON.stringify({"action": "listen_login_requests", "token": token}));
}
function confirmJoin(hash) {
socket.send(JSON.stringify({action: "session_hash_response", session_hash: hash}));
}
function handleJoinRequest(parsed) {
authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => {
let account = findAccountByMcName(parsed.user);