Skip to content
Snippets Groups Projects
Commit afb23460 authored by maka's avatar maka
Browse files

Handling room and connections deletions

parent 39acb0e7
Branches main
No related tags found
1 merge request!4Merging into Master
......@@ -121,18 +121,21 @@ function handleEnd(pScore, oScore) {
close.onclick = function() {
modal.style.display = "none";
socket.emit("done playing", sessionStorage.getItem("gameId"));
sessionStorage.clear();
window.location.replace("/");
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
socket.emit("done playing", sessionStorage.getItem("gameId"));
sessionStorage.clear();
window.location.replace("/");
}
}
noButton.onclick = function() {
modal.style.display = "none";
socket.emit("done playing", sessionStorage.getItem("gameId"));
sessionStorage.clear();
window.location.replace("/");
}
yesButton.onclick = function() {
......@@ -468,4 +471,5 @@ socket.on("play again cancelled", () => {
let yesButton = document.getElementById("yes-button");
scoreBody.innerHTML += '<br><div>THE OTHER PLAYER WON\'T PLAY AGAIN</div><br>';
yesButton.disabled = true;
sessionStorage.clear();
});
......@@ -190,6 +190,13 @@ io.on("connection", socket => {
});
socket.on("done playing", (gameId) => {
socket.to(gameId).emit("play again cancelled");
rooms.delete(gameId);
delete games[`${gameId}`];
// io.in(gameId).clients.forEach(function(s){
// s.leave(someRoom);
// });
io.in(gameId).socketsLeave(gameId);
socket.leave(gameId);
});
});
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment