有一个
socket.on('disconnect', function () { ... });。所以你可以做
socket.on('disconnect', function () { setTimeout(function () { //do something }, 10000);});
编辑1:
我明白了 因此,也许您应该执行以下 *** 作:
客户:服务器://right after connectionsocket.emit('register', localstorage.getItem('gameUniqueId'));//somewhere, when game startsvar randomlyGeneratedUID = Math.random().toString(36).substring(3,16) + +new Date;localStorage.setItem('gameUniqueId', randomlyGeneratedUID);
io.sockets.on('connection', function (socket) { var player = null; socket.on('register', function (data) { if (data !== null) { //there was something in localstorage if (game.Players.existsUID(data)) { player = game.Players.getByUID(data); player.disconnected = false; } else { //timed out, create new player } } else { //localStorage is not set, create new player } }); socket.on('disconnect', function () { player.disconnected = true; setTimeout(function () { if (player.disconnected) player.delete(); }, 10000); });});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)