You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
在连接成功后先执行了类似await这样的异步等待操作,可能会导致socket.on('disconnect')未执行的问题
io.on('connection', async socket => {
let res = await sockets.find({id: socket.id)})
await sockets.remove({id: socket.id})
socket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg)
socket.on('disconnect', reason => {
// console.log('下线:' + reason)
delete wsUsers[query.id]
socket.emit('onlineCount', io.eio.cliensCount)
...
调整一下它们的执行顺序,可以解决
io.on('connection', async socket => {
socket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg)
socket.on('disconnect', reason => {
// console.log('下线:' + reason)
delete wsUsers[query.id]
socket.emit('onlineCount', io.eio.cliensCount)
let res = await sockets.find({id: socket.id)})
await sockets.remove({id: socket.id})
...