node.js - Rooms are not removed after everyone leaves -


as far read doc rooms left automatically upon disconnection , automatically removed when leaves. not case of actual code:

io.on('connection', function(socket) {     socket.join(mainroom);   io.sockets.adapter.rooms[socket.id].owner = socket.username;     //send list of available rooms on connection     socket.to(mainroom).emit('updatelist',io.sockets.adapter.rooms);      socket.on('getupdatelist',function()  {         io.to(mainroom).emit('updatelist',io.sockets.adapter.rooms);     });      socket.on('msg', function(msg) {         io.to(mainroom).emit('msgfront',msg);       });        socket.on('disconnect', function() {         console.log('leaving '+socket.id);         io.to(mainroom).emit('updatelist',io.sockets.adapter.rooms);         });  }); 

notice i'm using mainroom client forced join make sure can talk each other.

by default each socket in socket.io identified random, unguessable, unique identifier socket#id. convenience, each socket automatically joins room identified id.

my problem after closing/refreshing browser tab, joined rooms still there, , number of rooms incremented(on connection socket join new rooms automatically..)

anyone can explain behavior ?

solved:

the problem extended rooms object bu adding owner attribute :

  io.sockets.adapter.rooms[socket.id].owner = socket.username; 

so extended room can't removed. solution found store owner attribute outside within associative array, that's it.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -