diff --git a/server/server.js b/server/server.js index 10a2077..f199c8a 100644 --- a/server/server.js +++ b/server/server.js @@ -7,7 +7,7 @@ const cors = require('cors'); const io = require('socket.io')(server); const users = { - general : [ + general: [ ], sports: [ @@ -31,7 +31,7 @@ app.use((req, res, next) => { io.on('connection', (socket) => { // Listening for joining a room - socket.on('joinRoom', ({username, room}) => { + socket.on('joinRoom', ({ username, room }) => { console.log(`user ${username} wants to join the room ${room}`); // Join the room @@ -55,7 +55,8 @@ io.on('connection', (socket) => { }); }) - socket.on('leaveRoom', ({room, username}) => { + // Leave room + socket.on('leaveRoom', ({ room, username }) => { console.log(`user ${username} wants to leave the room ${room}`); socket.leave(room, () => { @@ -63,7 +64,7 @@ io.on('connection', (socket) => { let usersRoom = users[room] // delete user from the suitable array - usersRoom = usersRoom.filter( (user) => (user.username !== username)) + usersRoom = usersRoom.filter((user) => (user.username !== username)) // Notify all the users in the same room io.sockets.in(room).emit('newUser', usersRoom); @@ -71,24 +72,45 @@ io.on('connection', (socket) => { }) // Listening for private chats - socket.on('joinPrivateRoom', ({username, room, to}) => { + socket.on('joinPrivateRoom', ({ username, room, to }) => { console.log(`user ${username} wants to have a private chat with ${to}`); // Join the room socket.join(to, () => { - - // Notify the user to talk with - io.sockets.in(room).emit('privateChat', { - username, - to - }); + + if (room !== null) { + // Notify the user to talk with (in the same main room) + io.sockets.in(room).emit('privateChat', { + username, + to + }); + } }); + }); - // io.to(to).emit('privateChat', { - // username, - // }) + // Leave private chat + socket.on('leavePrivateRoom', ({ room, from, to }) => { + console.log(`user ${from} wants to leave the private chat with ${room}`); - }); + io.to(room).emit('leavePrivateRoom', { + to, + privateMessage: `${from} has closed the chat`, + from, + room + }) + + socket.leave(room, () => { + console.log(`user ${from} left the private chat with ${room}`); + }) + }) + + // Private message listener + socket.on('privateMessage', ({ privateMessage, to, from, room }) => { + console.log(`User ${from} wants sends a message to ${to}`); + + // Private message to the user + io.to(room).emit('privateMessage', { to, privateMessage, from, room }) + }) }) server.listen(PORT, () => console.log(`Server Listening on port ${PORT}`)); \ No newline at end of file diff --git a/src/components/ChatArea.vue b/src/components/ChatArea.vue index 6e080e9..0a7fb5f 100644 --- a/src/components/ChatArea.vue +++ b/src/components/ChatArea.vue @@ -1,7 +1,7 @@ diff --git a/src/components/ChatDialog.vue b/src/components/ChatDialog.vue index 8069a9f..52b0227 100644 --- a/src/components/ChatDialog.vue +++ b/src/components/ChatDialog.vue @@ -5,33 +5,50 @@ :md-fullscreen="false" :md-click-outside-to-close="false" > +
+ hahsdfhashfd +
+
- + video_call close
- Private chat with {{showDialog.user}} + +

Private chat with {{showDialog.user}}

+ +
+ +
+