javascript - How to listen for Room events -


so clarify, know client should send message such 'join-room' server handling, , thats fine, , know can same 'leave-room'.

what want listen events themself, because if client disconnects, need send message rooms affected, when client disconnects automatically leave rooms.

so want like;

socket.on('join' function() { // send message });  socket.on('leave' function() { // send message }); 

so if user closes window (which disconnects client, , triggers rooms left) can send message out.

i using latest socket.io, redis adaptor.

also;

what efficient way list rooms particular socket in, technically think disconnect event should contain client_id manually.

the key thing clarity , stability, although open alternate approaches (must still use socket.io).

thanks

so if understood correctly main question: want listen events of joining , leaving room in implementation such socket.join(room_id) should fire event want listen to.

the thing docs dont mention ways of listening event. in fact, the implementation itself shows no sign of firing event when joining room. guess have implement join_room/leave_room system handle that.

as sub-question, socket object contains array called rooms such socket.rooms contains rooms socket in.

this you're looking :

socket.on('disconnect', function() { for(var room in socket.rooms) { //do stuff before client close connection , leave rooms } });


Comments