Skip to content

Instantly share code, notes, and snippets.

@ramainen
Created September 6, 2014 16:22
Show Gist options
  • Save ramainen/7a2f014f00a7864d2768 to your computer and use it in GitHub Desktop.
Save ramainen/7a2f014f00a7864d2768 to your computer and use it in GitHub Desktop.
//Sample I use
socket.on('disconnect', function() {
	if(typeof(socket._room) != 'undefined'){
		for(key in socket._room){
			if(Object.keys(io.sockets.adapter.rooms[socket._room[key]]).length == 0){
				delete io.sockets.adapter.rooms[socket._room[key]];
			}
		}
	}
	delete io.sockets.adapter.rooms[socket.id];
});

//Another just-quick-fix sample
socket.on('disconnect', function() {
   delete io.sockets.adapter.rooms[socket.id];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment