openai / openai-realtime-api-beta

Node.js + JavaScript reference client for the Realtime API (beta)
MIT License
535 stars 107 forks source link

Message object sometimes is null #6

Open jaytoday opened 2 weeks ago

jaytoday commented 2 weeks ago

I sometimes get this error seemingly at random:

[RealtimeRelay] Received message type: response.create
node:internal/event_target:1095
  process.nextTick(() => { throw err; });
                           ^

TypeError: Cannot read properties of null (reading 'type')
    at WebSocket.<anonymous> (/...node_modules/@openai/realtime-api-beta/lib/api.js:83:30)
// Relevant API code:
          ws.addEventListener('message', (event) => {
        const message = JSON.parse(event.data);
        this.receive(message.type, message);
      });
khorwood-openai commented 2 weeks ago

Can you create a reliable repro and add it to the tests by any chance?

jaytoday commented 2 weeks ago

@khorwood-openai not sure I'll be able to because I don't understand what triggers it. It's usually when a connection has been open for a little while. For now I applied a band aid that seems to work fine, although doesn't address whatever the root cause is:

      ws.addEventListener('message', (event) => {
        const message = JSON.parse(event.data);
        if (!message){
          console.error('message is null');
          return;
        }
        this.receive(message.type, message);
      });

This is just using the realtime console demo per the instructions. I'd suspect the problem may be on the demo side as there are a few other bugs I've found in it.