似乎reconnect_failed事件在 socket.io-client 中被触发了两次。我尝试为reconnectionAttempts设置不同的值,但即使它是 1、2 或 3,它总是会触发两次事件。
要重现场景,请在客户端运行
var opts = { reconnection: true, reconnectionAttempts: 3, reconnectionDelay: 500}
var socket = io.connect(opts)
socket.on('reconnect_failed', function() {
console.log("Reconnect failed")
})
在运行 kill node server (CTRL+C) 时,您将在开发者工具控制台中获得以下输出:
Reconnect failed
Reconnect failed
我正在使用 socket.io 1.0.5