2
我正在開發一個使用套接字io的應用程序,但是我的diconnect觸發器事件不起作用,我做了一切都像文檔說的,它仍然是一樣的......它被前幾天的工作,但現在它不工作了,我也沒從那時起Node.js socket.io斷開連接事件不會觸發
var io = require('socket.io')(server);
io.on('event', function(data){});
var socketUsers = [];
io.use(sharedSession(session, {
autoSave: true
}));
io.on('connection', function(socket) {
socketUsers.push(socket);
console.log('Player connected: ' + socket.id);
console.log('Connected players: ' + socketUsers.length);
io.on('disconnect', function() {
for(var i = 0; i < socketUsers.length; i++) {
console.log(socketUsers[i].id);
if(socketUsers[i].id == socket.id) {
//delete socketUsers[i];
socketUsers.splice(i);
break;
}
}
console.log(socketUsers.length + ' players online.');
});
io.on('chat message', function(msg){
io.emit('chat message', msg);
console.log('message: ' + msg);
});
function broadcast(key, value) {
io.emit(key, value);
}
});
固定的,感謝您的幫助! :d –