We are implementing a Node.js service to consume real-time analytics notification events from Genesys Cloud and push them to a Kafka topic. The setup uses the ws library to connect to the /api/v2/analytics/realtime/events endpoint. Authentication is handled via a bearer token that we refresh automatically.
The connection establishes successfully, and we receive the initial batch of events. However, after approximately 15 minutes of inactivity on the stream, the connection drops with a 1006 Abnormal Closure. We have implemented a ping/pong keep-alive mechanism in the client, but it seems the server side is not responding to our pings, or perhaps the interval is incorrect.
Here is the relevant snippet:
const ws = new WebSocket(url, {
headers: { Authorization: `Bearer ${token}` }
});
ws.on('open', () => {
console.log('Connected to analytics stream');
// Send ping every 15 seconds
setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
}
}, 15000);
});
ws.on('close', (code, reason) => {
console.log(`Connection closed: ${code} ${reason}`);
reconnect();
});
The logs show the closure code 1006, which typically indicates a network issue or timeout. We are in the Europe/Berlin timezone, so latency to the US-East endpoint might be a factor, but 15 minutes seems too long for a simple timeout. Is there a specific keep-alive requirement for the analytics notification stream that we are missing? Or is this a known issue with the WebSocket implementation in the Node.js environment? We need a reliable stream for our Kafka pipeline.