Node.js WebSocket consumer dropping events for Analytics Notifications

We’re building a pipeline to stream Genesys Cloud Analytics Notification events into a Kafka topic for downstream processing in New Relic. The goal is to capture real-time queue state changes and wrap them in custom events.

I’m using the standard WebSocket endpoint wss://api-us-east-1.aws.genesiscloud.com/v2/analytics/notifications/streams with a valid Bearer token. The connection establishes successfully, and I receive the initial connected message. However, the stream seems to drop events after about 15-20 minutes of inactivity or high load.

Here’s the core consumer logic:

const WebSocket = require('ws');

const ws = new WebSocket(WSS_URL, {
 headers: { 'Authorization': `Bearer ${token}` }
});

ws.on('message', (data) => {
 const event = JSON.parse(data);
 if (event.type === 'connected') {
 console.log('Stream active');
 } else if (event.type === 'data') {
 // Push to Kafka producer
 kafkaProducer.send({ topic: 'gc-analytics', messages: [event] });
 }
});

ws.on('close', (code, reason) => {
 console.log(`Connection closed: ${code} ${reason}`);
 // Attempt reconnect logic here
});

The issue is that ws.on('close') triggers with code 1006 (Abnormal Closure) without any prior warning or error message. The reconnect logic kicks in, but we lose those few seconds of analytics data.

I’ve checked the Genesys Cloud docs for specific ping/pong requirements or heartbeat intervals for the Analytics stream, but the standard WebSocket RFC behavior should handle this. Is there a specific header or message I need to send to keep the Analytics notification stream alive? Or is this a known limitation of the v2/analytics/notifications/streams endpoint under heavy load?

I’ve tried adding a manual ping every 30 seconds, but it doesn’t seem to prevent the 1006 closure. The token is refreshed via the standard OAuth2 flow, so auth expiration isn’t the culprit here.

Any insights on keeping this stream stable?