Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 25, 2022 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save percybolmer/97ee86a62aceddad8e1696843b656e80 to your computer and use it in GitHub Desktop.
Save percybolmer/97ee86a62aceddad8e1696843b656e80 to your computer and use it in GitHub Desktop.
/**
* ChangeChatRoomEvent is used to switch chatroom
* */
class ChangeChatRoomEvent {
constructor(name) {
this.name = name;
}
}
/**
* changeChatRoom will update the value of selectedchat
* and also notify the server that it changes chatroom
* */
function changeChatRoom() {
// Change Header to reflect the Changed chatroom
var newchat = document.getElementById("chatroom");
if (newchat != null && newchat.value != selectedchat) {
selectedchat = newchat.value;
header = document.getElementById("chat-header").innerHTML = "Currently in chat: " + selectedchat;
let changeEvent = new ChangeChatRoomEvent(selectedchat);
sendEvent("change_room", changeEvent);
textarea = document.getElementById("chatmessages");
textarea.innerHTML = `You changed room into: ${selectedchat}`;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment