Skip to content

Commit

Permalink
Chat feature now working
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhar-5 committed Jul 11, 2021
1 parent 12babc1 commit a111893
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions public/Styles/RoomStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,13 @@ input {
line-height: 15px;
color: black;
}

li {
background-color: rgb(241, 243, 244);
font-family: "Roboto", sans-serif;
list-style: none;
padding: 10px;
border: 1px solid black;
border-radius: 10px;
margin: 10px 10px 10px 10px;
}
40 changes: 39 additions & 1 deletion public/scripts/Roomscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ navigator.mediaDevices
//we need video so this is true
video: true,
//we also need the audio then so audio is true
audio: true,
audio: false,
})
.then((stream) => {
VideoStream: stream;
Expand Down Expand Up @@ -91,3 +91,41 @@ if (Room_id) {

const pageTitle = document.getElementById("title-id");
pageTitle.innerHTML = `Meeting-${Room_id}`;

//bringing input-field and the paper rocket button
const inputText = document.getElementById("chat-message");
const send = document.getElementById("send");

inputText.addEventListener("input", changeTheColorOfSend);

function changeTheColorOfSend(event) {
if (inputText.value) {
send.style.color = `rgb(55,118,224)`;
} else {
send.style.color = `grey`;
}
}

//adding event listener to the send button
send.addEventListener("click", sendMessage);

function sendMessage(event) {
var messageText = inputText.value;
if (messageText) {
//emit the message text
socket.emit("chat message", messageText);
//and clear the chat
inputText.value = "";
send.style.color = `grey`;
}
}

const chatWindowTexts = document.getElementById("UserTexts");
//recieving the message and adding that as a list
socket.on("chat message", (message) => {
var messageElement = document.createElement("li");
console.log(message);
messageElement.textContent = message;
chatWindowTexts.appendChild(messageElement);
window.scrollTo(0, document.body.scrollHeight);
});
6 changes: 6 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ io.on("connection", (socket) => {
console.log("request reached server");
socket.broadcast.emit("user-connected", id);
});

socket.on("chat message", (message) => {
//if we do this we will not recieve our own messages but here we wnt our texts too
//socket.broadcast.emit("chat message", message);
io.emit("chat message", message);
});
});

port = process.env.PORT || 3000;
Expand Down
2 changes: 1 addition & 1 deletion views/room.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
call ends.
</div>
</div>
<ul class="messages">
<ul id="UserTexts" class="messages-list">
<!-- Here lies the in meeting chat messages-->
</ul>
</div>
Expand Down

0 comments on commit a111893

Please sign in to comment.