gpt4 book ai didi

node.js - 当套接字与服务器断开连接时如何从房间取消订阅套接字

转载 作者:搜寻专家 更新时间:2023-11-01 00:35:37 25 4
gpt4 key购买 nike

如果套接字与服务器断开连接,该套接字的所有订阅会默认从聊天室中删除(通过 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com