当套接字与服务器断开连接时,如何从房间退订套接字

时间:2018-11-02 12:48:11

标签: node.js socket.io sails.js

如果套接字已从服务器断开连接,则该套接字的所有订阅将默认(通过帆)从聊天室中删除,还是我们必须手动(通过代码)将其删除

1 个答案:

答案 0 :(得分:1)

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
};