node.js - One-line check if socket is in given room? -


i'm using node.js socket.io multiplayer card game, , there game rooms players can join.

for joining room, use:

io.sockets.on('connection', function (socket) {     socket.on('joinroom', function (gid) {         //gid game id - create room name based on , join room         var room = 'game'+gid;         socket.join(room);     }); }); 

my question is, quickest way check if socket connected room? know sockets in room in array , check whether target socket in array, i'm guessing there should more basic syntax this. i'm looking (in pseudo-code) be

if(socket id "z8b7dbf98i" in room "game10")     //do 

for documentation, socket.io doesn't seem have simple way that. need check if client in room array, or opposite: if room in client array.

this can done oneliner using indexof:

if(socket.rooms.indexof(room) >= 0) 

or opposite search:

if(io.sockets.manager.rooms['/' + room].indexof(socket.id) >= 0) 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -