fix: add missing RPC methods and WebSocket heartbeat to mock backend
- Add node-messages-received, node.messages, node.notifications stubs - Send WebSocket heartbeat every 45s to prevent client disconnect at 60s Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b62635874f
commit
95a3687f0a
@ -893,7 +893,14 @@ app.post('/rpc/v1', (req, res) => {
|
||||
return res.json({ result: { success: true } })
|
||||
}
|
||||
|
||||
case 'node-messages-received':
|
||||
case 'node.messages':
|
||||
case 'node.notifications': {
|
||||
return res.json({ result: [] })
|
||||
}
|
||||
|
||||
default: {
|
||||
console.log(`[RPC] Unknown method: ${method}`)
|
||||
return res.json({
|
||||
error: {
|
||||
code: -32601,
|
||||
@ -934,12 +941,23 @@ wss.on('connection', (ws, req) => {
|
||||
} catch (err) {
|
||||
console.error('[WebSocket] Ping error:', err)
|
||||
clearInterval(pingInterval)
|
||||
clearInterval(heartbeatInterval)
|
||||
}
|
||||
} else {
|
||||
clearInterval(pingInterval)
|
||||
clearInterval(heartbeatInterval)
|
||||
}
|
||||
}, 30000) // Ping every 30 seconds
|
||||
|
||||
// Send periodic heartbeat data so clients don't think the connection is dead
|
||||
const heartbeatInterval = setInterval(() => {
|
||||
if (ws.readyState === 1) {
|
||||
try {
|
||||
ws.send(JSON.stringify({ rev: Date.now(), patch: [] }))
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}, 45000) // Every 45s (client expects data within 60s)
|
||||
|
||||
// Send initial data immediately
|
||||
try {
|
||||
ws.send(JSON.stringify({
|
||||
@ -968,12 +986,14 @@ wss.on('connection', (ws, req) => {
|
||||
ws.on('close', (code, reason) => {
|
||||
console.log('[WebSocket] Client disconnected', { code, reason: reason.toString() })
|
||||
clearInterval(pingInterval)
|
||||
clearInterval(heartbeatInterval)
|
||||
wsClients.delete(ws)
|
||||
})
|
||||
|
||||
ws.on('error', (error) => {
|
||||
console.error('[WebSocket Error]', error)
|
||||
clearInterval(pingInterval)
|
||||
clearInterval(heartbeatInterval)
|
||||
wsClients.delete(ws)
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user