Opens the raw socket immediately (matching the SDK connection's construct-then-connect
lifecycle). The platform-global WebSocket API has no header support, so any upstream auth
must be enforced by the endpoint or injected by an intermediary (e.g. MJAPI's realtime proxy).
The ws(s)://…/v1/realtime endpoint URL.
OptionalwebSocketCtor: NativeWebSocketCtorOptional WebSocket constructor override (tests inject a fake; production resolves the platform global).
The socket shim the driver uses to detect UNEXPECTED closure (see IOpenAIRealtimeConnection.socket).
Closes the underlying socket (pending buffered sends are dropped).
Removes a previously-registered listener.
Removes a previously-registered error listener.
Registers a listener for parsed server events ('event') or connection errors ('error').
Registers a listener for connection errors. The SDK routes BOTH transport-level failures
(socket error, unparseable frame, failed send — error.error is undefined) and provider
error server frames (error.error carries the payload) through this channel; the driver
classifies fatality from that distinction.
JSON-serializes one client frame; buffered until the socket opens, sent immediately after. A send after the socket closed is a safe no-op (the session teardown path may still emit).
Adapts a RAW platform WebSocket speaking the OpenAI Realtime wire protocol into the IOpenAIRealtimeConnection seam the shared
OpenAIRealtimedriver family consumes.This is the enabling primitive for OpenAI-protocol-compatible providers whose endpoint is NOT reachable through the
openaiSDK client — e.g. a self-hosted HuggingFace speech-to-speech server (arbitraryws://endpoint, optional/no auth) — letting them subclass the shared driver instead of re-implementing the protocol against a bare socket.Behavior mirrors the SDK's
OpenAIRealtimeWebSocketwhere the driver depends on it:'event'listeners; non-JSON frames are ignored.errorFRAMES are routed to'error'listeners with the payload attached at.error(the driver classifies those as recoverable), while TRANSPORT failures are routed with no.errorpayload (classified fatal) — the same dual-channel contract the SDK exposes.socketshim the driver feature-detects for unexpected-closure handling.