-
-
Save toanalien/1336561103d185652974 to your computer and use it in GitHub Desktop.
joinRoom
This file contains hidden or 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
function joinRoom(socket, room) { | |
socket.join(room); | |
currentRoom[socket.id] = room; | |
socket.emit('joinResult', {room: room}); | |
socket.broadcast.to(room).emit('message', {text: nickNames[socket.id] + 'has joined ' + room + '.'}); | |
var usersInRoom = io.sockets.clients(room); | |
if (usersInRoom.length > 1) { | |
var usersInRoomSummary = 'Users currently in ' + room + ': '; | |
for (var index in usersInRoom) { | |
var userSocketId = usersInRoom[index].id; | |
if (userSocketId != socket.id) { | |
if (index > 0) { | |
usersInRoomSummary += ', '; | |
} | |
usersInRoomSummary += nickNames[userSocketId]; | |
} | |
} | |
usersInRoomSummary += '.'; | |
socket.emit('message', {text: usersInRoomSummary}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment