我有一个脚本聊天,它工作正常,但如果成员通过 Android 进入并离开聊天并打开任何其他程序,服务器将删除它 这是我的服务器 js commond
//DisconnectUser
io.use((socket, next) => { next(); }).on('connection', socket => { console.log('(default) client connected'); });
socket.on("disconnect", function () {
var userData = UserInfo[socket.id];
if (typeof userData !== "undefined") {
if (UserInfo[socket.id].powers["stealth"] == 1000 && UserInfo[socket.id].stealth == true) {
} else {
io.to(userData.idroom).emit("msg", {
cmd: "msg",
data: {
bg: "none",
class: "hmsg",
topic: userData.username,
msg: "( هذا المستخدم غادر الدردشة)",
roomid: userData.idroom,
pic: userData.pic,
},
});
}
if (UserInfo[socket.id].uid) {
var UpdateUser = {
$set: {
lastssen: new Date().getTime(),
token: stringGen(177),
},
};
user_list.updateOne({ id: UserInfo[socket.id].uid }, UpdateUser, function (err, uruser) {
if (err) throw err;
if (uruser) {
}
});
}
io.emit("msg", { cmd: "ur", data: [userData.id, null] });
socket.leave(userData.idroom);
}
delete UserInfo[socket.id];
const indexw = online.findIndex((x) => x.id == socket.id);
if (indexw != -1) {
online.splice(
online.findIndex((v) => v.id == socket.id),
1
);
io.emit("msg", { cmd: "u-", data: socket.id });
}
var index = UserEntre.findIndex((x) => x == socket.id);
if (index != -1) {
UserEntre.splice(UserEntre.indexOf(socket.id), 1);
}
lastssen: new Date().getTime();
});
**我该怎么做才能让用户在聊天中保持最长时间?**