Building a reconnection handler for the Notification API in Node.js. The initial handshake works fine, but when I kill the connection and retry, the server sends a 200 OK then immediately closes the socket without sending any events.
Here’s the reconnect logic:
ws.on('close', (code, reason) => {
setTimeout(() => {
const newWs = new WebSocket(`wss://${orgHost}/api/v2/notifications`);
newWs.on('open', () => {
newWs.send(JSON.stringify({
action: 'subscribe',
topic: 'routing.agents'
}));
});
}, 5000);
});
- Node 18 LTS
- Using native
wspackage - Token is valid and refreshed via OAuth
Tried adding a random query param to force a new session, didn’t help. Any idea why the subscription isn’t sticking after reconnect?