我正在尝试每5秒设置一个自定义保持活动并将其附加到套接字对象,以便在出现通信问题时我可以重置计时器。我认为它更像是一个范围问题,但它对我来说是一个障碍。
client.on('connect', function handleConnection() {
this.fullDataDec = ''
this.pingInterval = null
const credentials = {}
credentials.player_id = 123
this.credentials = credentials
const initPacket = buildPacket(this)
this.write(initPacket)
this.pingInterval = setInterval(() => {
const keepAlivePacket = packetBuilder.buildKeepAlivePacket(this)
this.write(keepAlivePacket)
}, 5000)
})
我的问题:
this
引用Timeout
对象。我如何将套接字(客户端对象)传递给此函数?