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 // SW
navigator.serviceWorker.register("sw.js") navigator.serviceWorker.register("sw.js")
new BroadcastChannel('viaaas-notification').addEventListener("message", e => handleSWMsg(e));
// Minecraft.id // Minecraft.id
let urlParams = new URLSearchParams(); let urlParams = new URLSearchParams();
@ -283,18 +282,13 @@ function resetHtml() {
renderActions(); renderActions();
} }
// Websocket // Notification
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}));
}
var notificationCallbacks = {}; var notificationCallbacks = {};
function handleSWMsg(event) { function handleSWMsg(event) {
console.log("sw msg: " + event); console.log("sw msg: " + event);
let data = event.data; let data = event.data;
let callback = notificationCallbacks[data.tag]; let callback = notificationCallbacks[data.tag];
delete notificationCallbacks[data.tag];
if (callback == null) return; if (callback == null) return;
callback(data.action); callback(data.action);
} }
@ -322,8 +316,18 @@ function authNotification(msg, yes, no) {
return; 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) { function handleJoinRequest(parsed) {
authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => { authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => {
let account = findAccountByMcName(parsed.user); let account = findAccountByMcName(parsed.user);