Made the Chat part only visible after being connected with a room

This commit is contained in:
abrendan
2024-01-29 17:18:14 +00:00
parent 0d26f56c4b
commit db7b495194
3 changed files with 20 additions and 4 deletions

View File

@@ -24,6 +24,8 @@ function onload(){
socket.on("join", function(room){
chatRoom.innerHTML = "Current Chatroom : " + room;
// Show the chat div when successfully joined a room.
document.getElementById("Chat").style.display = "block";
})
socket.on("recieve", function(message){
@@ -45,7 +47,19 @@ function onload(){
}
function Connect(){
socket.emit("join", chatIDInput.value, usernameInput.value);
// Get the username and room from the input fields
var username = usernameInput.value.trim();
var room = chatIDInput.value.trim();
// Check if the username and room are not empty
if(username && room){
socket.emit("join", room, username);
chatRoom.innerHTML = "Chatroom : " + room;
// Hide the chat div initially when attempting to connect
document.getElementById("Chat").style.display = "none";
} else {
// Maybe show an error message to the user that they need to fill in both fields
}
}
function Send(){