如果套接字与服务器断开连接,该套接字的所有订阅将默认从聊天室中删除(通过 sails)还是我们必须手动删除(通过代码)
最佳答案
socket.io source code的基础this.leaveAll()
将在触发断开连接事件之前运行。因此无需手动离开房间
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
};
关于node.js - 当套接字与服务器断开连接时,如何从房间取消订阅套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53118902/