-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete implementation of chat system
- Loading branch information
1 parent
13f2d63
commit 20ac507
Showing
3 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var username = prompt("Enter your username: "); | ||
var textBox = document.getElementById("inputTextBox"); | ||
var messageList = document.getElementById("messages"); | ||
|
||
function appendMessage(message, backgroundColor) { | ||
var listItem = document.createElement("li"); | ||
var listItemText = document.createTextNode(message); | ||
listItem.appendChild(listItemText); | ||
if (arguments.length == 2) | ||
listItem.style.background = backgroundColor; | ||
|
||
messages.appendChild(listItem); | ||
} | ||
|
||
function sendMessage() { | ||
var message = username + ": " + document.getElementById("inputTextBox").value; | ||
textBox.value = ""; // clear textbox | ||
appendMessage(message, "white"); | ||
socket.emit("chat_message", message); | ||
console.log("message"); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters