Does anyone know why my Node.js client fails to re-establish the WebSocket connection immediately after a network interruption, even though I am following the reconnection guidelines?
Context:
I am building a real-time dashboard for supervisor views in our Tokyo office. The system relies heavily on the Notification API to push queue statistics via WebSockets. I have implemented a robust reconnection mechanism using the ws library in Node.js. The initial connection works perfectly, and I receive events as expected. However, when I simulate a network drop, the client attempts to reconnect but gets stuck in a loop where the handshake never completes successfully, eventually timing out.
The documentation for the Notification API states: “Clients should implement exponential backoff for reconnection attempts to avoid overwhelming the server during outages.” I am adhering to this strictly. My logic waits for the close event, calculates the delay, and then initiates a new WebSocket connection to wss://api.mypurecloud.com/api/v2/notification/events.
Here is the core of my reconnection handler:
ws.on('close', (code, reason) => {
console.log('WebSocket closed:', code, reason);
let delay = Math.min(1000 * Math.pow(2, retryCount), 30000);
setTimeout(() => {
retryCount++;
connect();
}, delay);
});
function connect() {
const headers = {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
};
ws = new WebSocket(url, { headers });
// ... event listeners
}
The issue is that the new connection attempt does not trigger the open event immediately. Instead, it seems to hang until the timeout. I have verified that the OAuth token is valid and refreshed before each attempt. The server returns no explicit error code during the handshake phase, it just silently drops the connection after a few seconds.
Question:
Is there a specific header or parameter required in the WebSocket upgrade request during reconnection that is documented elsewhere? Or is there a known issue with how the Genesys Cloud Notification API handles rapid reconnection attempts from the same IP address? I need to ensure my dashboard remains stable during intermittent network issues.