ws.on('close', (code) => console.log('Connection lost', code)) keeps firing at 1006 instead of triggering the retry routine. We’re piping routing.queueEvents through the /v2/analytics/notifications WebSocket endpoint for the dashboard, and the Node.js ws client drops packets during the reconnect phase. The current loop uses setTimeout with exponential backoff, but the access_token expires right before the new socket attempts the handshake.
const reconnect = async () => {
const token = await refreshToken();
const uri = `wss://api.mypurecloud.com/v2/analytics/notifications?access_token=${token}`;
const sock = new WebSocket(uri);
sock.on('open', () => sendSubscriptionPayload());
};
The dashboard misses queue level spikes during that gap. We’ve tried adding a ping interval to keep the TCP state alive, but the server still pushes a 401 when the token refreshes mid-flight. Any pattern for handling token rotation inside the reconnection handler without losing the subscription state. The interval grouping calculations fall apart if we miss those routing events.