问题
If socket is disconnected from the server, Will all the subscription of that socket will be removed from the chat-room by default(by sails) or we have to remove it manually(by code)
回答1:
Base of socket.io source code this.leaveAll()
will run before fire disconnect event. So no need to leave from rooms manually
Socket.prototype.onclose = function(reason){
if (!this.connected) return this;
debug('closing socket - reason %s', reason);
this.emit('disconnecting', reason);
this.leaveAll(); // leave from all rooms
this.nsp.remove(this);
this.client.remove(this);
this.connected = false;
this.disconnected = true;
delete this.nsp.connected[this.id];
this.emit('disconnect', reason); // disconnect event fire here
};
来源:https://stackoverflow.com/questions/53118902/how-to-unsubscribe-a-socket-from-a-room-when-socket-disconnected-from-the-server