mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: reset ping timeout on any frame recv
Credit to @HUGEIT for suggesting this
This commit is contained in:
@@ -259,6 +259,9 @@ export const makeSocket = ({
|
|||||||
|
|
||||||
const onMessageRecieved = (data: Buffer) => {
|
const onMessageRecieved = (data: Buffer) => {
|
||||||
noise.decodeFrame(data, frame => {
|
noise.decodeFrame(data, frame => {
|
||||||
|
// reset ping timeout
|
||||||
|
lastDateRecv = new Date()
|
||||||
|
|
||||||
ws.emit('frame', frame)
|
ws.emit('frame', frame)
|
||||||
// if it's a binary node
|
// if it's a binary node
|
||||||
if(!(frame instanceof Uint8Array)) {
|
if(!(frame instanceof Uint8Array)) {
|
||||||
@@ -359,7 +362,7 @@ export const makeSocket = ({
|
|||||||
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
||||||
} else if(ws.readyState === ws.OPEN) {
|
} else if(ws.readyState === ws.OPEN) {
|
||||||
// if its all good, send a keep alive request
|
// if its all good, send a keep alive request
|
||||||
query(
|
sendNode(
|
||||||
{
|
{
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -369,14 +372,11 @@ export const makeSocket = ({
|
|||||||
xmlns: 'w:p',
|
xmlns: 'w:p',
|
||||||
},
|
},
|
||||||
content: [{ tag: 'ping', attrs: { } }]
|
content: [{ tag: 'ping', attrs: { } }]
|
||||||
},
|
}
|
||||||
keepAliveIntervalMs
|
|
||||||
)
|
)
|
||||||
.then(() => {
|
.catch(err => {
|
||||||
lastDateRecv = new Date()
|
logger.error({ trace: err.stack }, 'error in sending keep alive')
|
||||||
logger.trace('recv keep alive')
|
|
||||||
})
|
})
|
||||||
.catch(err => end(err))
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn('keep alive called when WS not open')
|
logger.warn('keep alive called when WS not open')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user