Just noticed that my Node.js consumer is intermittently failing to parse the binary frames from the CXone Streaming Analytics WebSocket endpoint.
I have successfully authenticated using client_credentials and established the connection to wss://api-us.nice-incontact.com/api/v2/analytics/streaming. The connection opens with a 101 Switching Protocols response, and I receive the initial metadata frame correctly. However, when data events start flowing, specifically around high-volume intervals, the ws.on('message') callback receives Buffer objects that do not decode cleanly to JSON. I am using the standard ws library in Node.js v18. Here is the relevant consumer logic:
ws.on('message', (data) => {
try {
const payload = JSON.parse(data.toString('utf8'));
console.log('Event:', payload.eventType);
} catch (err) {
console.error('Parse error:', err.message);
// Attempting to log raw buffer
console.log('Raw:', data);
}
});
The error logged is typically SyntaxError: Unexpected token '�' in JSON at position 0. I suspect the streaming API might be using a specific compression or framing format that requires explicit decompression before parsing, or perhaps the WebSocket handshake headers need a specific Accept-Encoding parameter. Has anyone successfully consumed these binary frames in Node.js? Is there a specific CXone header required during the WebSocket upgrade to ensure UTF-8 text frames instead of binary?