I’m building a Node.js listener for the CXone Notification API. The standard ws library works fine for the initial connection, but the reconnection logic is messy. When the server sends a close frame (code 1001), my script immediately tries to reconnect. This triggers a 429 Too Many Requests error from the gateway because the backoff isn’t aggressive enough.
Here’s the relevant :
ws.on('close', (code, reason) => {
console.log(`Connection closed: ${code}`);
if (code !== 1000) {
// Immediate retry fails
connect();
}
});
I need a reliable way to handle the exponential backoff without losing messages during the gap. The @genesys/cloud-pure-client-javascript SDK doesn’t seem to expose the raw WebSocket event stream directly, so I’m stuck using the raw /api/v2/platform/notification/websocket endpoint. Is there a recommended pattern for managing the reconnect delay in or via a simple script? I can’t find a clear example in the docs for handling the close codes properly.