Class: OpenAI::Live::Connection

Inherits:
WebSocket::TypedConnection show all
Defined in:
lib/openai/helpers/live/websocket.rb

Overview

A transport-open primary connection. Startup is owned by the caller: send session.start and observe session.started before further commands. Only one receive call may read or decode at a time. Iteration releases the read before yielding an event to the caller.

Direct Known Subclasses

ForkConnection, SidebandConnection

Instance Attribute Summary

Attributes inherited from WebSocket::TypedConnection

#url

Attributes inherited from WebSocket::Connection

#url

Instance Method Summary collapse

Methods inherited from WebSocket::TypedConnection

#close, #closed?, #each, #parse_event, #send_event

Methods included from WebSocket::GuardedConnection

#abort, #close, #closed?

Methods inherited from WebSocket::Connection

#abort, #close, #closed?, #each, #send_raw

Constructor Details

#initialize(socket:, url:) ⇒ Connection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Connection.



51
52
53
54
55
56
# File 'lib/openai/helpers/live/websocket.rb', line 51

def initialize(socket:, url:)
  super(socket: socket, url: url, client_event: client_event_type, server_event: server_event_type)
  @poisoned = false
  @closed = false
  @read_mutex = Mutex.new
end

Instance Method Details

#receive ⇒ Object



60
61
62
# File 'lib/openai/helpers/live/websocket.rb', line 60

def receive
  with_read_lease { read_one }
end

#receive_raw ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/openai/helpers/live/websocket.rb', line 65

def receive_raw
  with_read_lease { read_raw_message }
end