Skip to content

Instantly share code, notes, and snippets.

@powerc9000
Created May 23, 2013 18:09
Show Gist options
  • Save powerc9000/5638149 to your computer and use it in GitHub Desktop.
Save powerc9000/5638149 to your computer and use it in GitHub Desktop.
var rooms = {};
io.sockets.on("connection", function(socket){
socket.on("create room", function(roomName){
if(!rooms[roomName]){
rooms[roomName] = [];
}
rooms[roomName].push(socket);
});
socket.on("message", function(data){
rooms[data.roomName].forEach(function(s){
io.sockets.socket(s.id).emit(data.message);
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment