Skip to content

Commit

Permalink
sockets work well enough
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowCat567 committed Apr 25, 2024
1 parent 545a4e4 commit d227322
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions back-end/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ io.use((socket, next) => {
io.on('connection', (socket) => {
console.log(`a user has connected, user id = ${socket.id}`);

socket.on('chat_message', (msg, otherUser) => {
io.to(otherUser).emit('chat_message', msg); //I think this will work...
socket.on('chat_message', (msg) => {
io.emit('chat_message', msg);
});

socket.on('disconnect', () => {
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/ChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function ChatPage() {

//sends the message to the backend
function sendToSocket(msg) {
socket.emit('chat_message', msg, otherperson_username);
socket.emit('chat_message', msg);
}

const getUser = async () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ function ChatPage() {
if (message.sender === user) {
return <ChatBoxSender key={index} message={message.messagetext} user={message.sender} time={formattedTimestamp} />
}else {
return <ChatBoxReceiver key={index} message={message.messagetext} user={message.recipient} time={formattedTimestamp} />
return <ChatBoxReceiver key={index} message={message.messagetext} user={message.sender} time={formattedTimestamp} />
}
})}
<ChatExchange />
Expand Down

0 comments on commit d227322

Please sign in to comment.