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

socket.io ,当断开火警时,是否需要手动调用socket.leave()
NodeJs Socket.io本身处理它?

 socket.on("disconnect" function() { this.leave("room"); // is this necessary? }); 

       

网上收集的解决方案 "是否需要socket.leave()在Nodejs断开连接的房间"

,所有的房间都已经离开之前,这个事件。

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

不,当断开事件触发时,不需要手动调用socket.leave()。 有关更多详细信息,请参阅http://socket.io/docs/rooms-and-namespaces/