chrispound / robits

MIT License
2 stars 0 forks source link

multi room support #17

Closed chrispound closed 10 years ago

chrispound commented 10 years ago

Added multiple session/ room support for games and chat using socket.io's rooms. The room id only needs to be on the server right now and we can store it as part of the client's socket.

tnunamak commented 10 years ago

This is cool. I'm not seeing the log messages come through though.

chrispound commented 10 years ago

server or client log messages?

tnunamak commented 10 years ago

The log function on the server which broadcasts to the client. It seems to be logging server side but the emit isn't working.

function log(message, socket, room) {
    (socket || io).to(room).emit('log', message);
    console.log(message);
}
chrispound commented 10 years ago

ah i wasn't sure about this one. could we change it to 'io.to(room).emit('log', message)?

tnunamak commented 10 years ago

Ah is that the problem? That it's only broadcasting to whichever socket it's reacting to? Yeah in most cases we should broadcast to the whole room so maybe where log() is getting called we should just not pass in a specific socket. It may be better to reorder the parameters for that:

function log(message, room, socket) {...}

so that you can call it either like log('hello world!', roomId) or log('hello world!', roomId, socket). We would most commonly use the first one.