它是否需要在Nodejs中断开连接的socket.leave()

Par*_*ars 6 node.js socket.io

socket.io,socket.leave()断开连接时我是否需要手动呼叫?
或者NodeJs Socket.io自己处理它?

socket.on("disconnect" function() {
   this.leave("room"); // is this necessary?
});
Run Code Online (Sandbox Code Playgroud)

Sha*_*yar 14

,所有房间在发布此活动之前已经离开.

代码来自socket.io:

Socket.prototype.onclose = function(reason){
  if (!this.connected) return this;
  debug('closing socket - reason %s', reason);
  this.emit('disconnecting', reason);
  this.leaveAll();   //leaving 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);   //emitting event
};
Run Code Online (Sandbox Code Playgroud)