node.js - Can I use rooms in namespaces in socket.io -
i'd know whether can use multiple rooms withing namespace in socket.io.
as far know can use either namespaces or rooms.
my purpose have multiple unique instances of application talking other ones unique application through websockets 1 node.js-socket.io-server.
withing application there requirements talk each other. either within room or global. there no need talk namespace.
thanks in advance,
daniel
i have had no problem doing this. have few multiplayer games built (see here), , run on same socket.io instance. namespacing keeps different games separated, , rooms keep individual game rooms within single game separated.
full code example here: https://github.com/azurelogic/cakerush/blob/master/controllers/cakerush.js
the highlights fact use namespacing on connection:
io.of('/sockets/cakerush').on('connection', function (socket) { //... then later, allow users join room through 'join room' event:
socket.on('joinroom', function (data) { // find room being requested var room = _.find(rooms, {id: data.roomid}); /* skip logic here... */ // register player room room.playerids.push(socket.id); socket.join(room.id); // send verification room joined player room id socket.emit('roomjoined', {roomid: room.id, shouldgeneratefirstcake: shouldgeneratefirstcake}); });
Comments
Post a Comment