【发布时间】:2019-04-06 17:13:28
【问题描述】:
如果套接字与服务器断开连接,该套接字的所有订阅是否会默认从聊天室中删除(通过sails)或者我们必须手动删除它(通过代码)
【问题讨论】:
标签: node.js socket.io sails.js
如果套接字与服务器断开连接,该套接字的所有订阅是否会默认从聊天室中删除(通过sails)或者我们必须手动删除它(通过代码)
【问题讨论】:
标签: node.js socket.io sails.js
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
};
【讨论】: