Class: OpenAI::Realtime::Transports::AsyncWebSocket::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/helpers/realtime/transports/async_websocket.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, url:) ⇒ Socket

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 Socket.



144
145
146
147
148
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 144

def initialize(connection, url:)
  @connection = connection
  @url = url
  @aborted = false
end

Instance Method Details

#abortObject

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.



170
171
172
173
174
175
176
177
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 170

def abort
  framer = @connection.framer
  framer.extend(AbortableFramer)
  framer.abort
  @aborted = true
rescue StandardError => e
  raise OpenAI::Errors::RealtimeConnectionError.new(url: @url, cause: e)
end

#aborted?Boolean

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:



180
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 180

def aborted? = @aborted

#close(code: 1000, reason: "") ⇒ Object



163
164
165
166
167
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 163

def close(code: 1000, reason: "")
  @connection.close(code, reason)
rescue StandardError => e
  raise OpenAI::Errors::RealtimeConnectionError.new(url: @url, cause: e)
end

#closed?Boolean

Returns:



182
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 182

def closed? = @aborted || @connection.closed?

#readObject



150
151
152
153
154
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 150

def read
  @connection.read
rescue StandardError => e
  raise OpenAI::Errors::RealtimeConnectionError.new(url: @url, cause: e)
end

#write(message) ⇒ Object



156
157
158
159
160
161
# File 'lib/openai/helpers/realtime/transports/async_websocket.rb', line 156

def write(message)
  @connection.write(message)
  @connection.flush
rescue StandardError => e
  raise OpenAI::Errors::RealtimeConnectionError.new(url: @url, cause: e)
end