Class: OpenAI::Realtime::ConnectionManager Private

Inherits:
WebSocket::ConnectionManager show all
Defined in:
lib/openai/helpers/realtime/connection_manager.rb

Overview

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

Internal block-scoped lifecycle manager for Realtime WebSocket connections.

Constant Summary

Constants inherited from WebSocket::ConnectionManager

WebSocket::ConnectionManager::RESERVED_TRANSPORT_OPTIONS

Instance Method Summary collapse

Methods inherited from WebSocket::ConnectionManager

#open

Constructor Details

#initialize(client:, query:, websocket_base_url:, transport:, request_options:, transport_options:, connection_class: OpenAI::Realtime::Connection) ⇒ ConnectionManager

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openai/helpers/realtime/connection_manager.rb', line 10

def initialize(
  client:,
  query:,
  websocket_base_url:,
  transport:,
  request_options:,
  transport_options:,
  connection_class: OpenAI::Realtime::Connection
)
  query = query
    .to_h
    .to_h do |key, value|
      [key.to_s.dup.freeze, value.to_s.dup.freeze]
    end
    .freeze
  base_url = websocket_base_url&.to_s&.dup&.freeze
  request = lambda do |&request_block|
    client.with_realtime_connection_request(
      path: "realtime",
      query: query,
      websocket_base_url: base_url,
      options: request_options,
      &request_block
    )
  end

  super(
    transport: transport,
    transport_options: transport_options,
    default_transport: -> { OpenAI::Realtime::Transports::AsyncWebSocket.new },
    connection_class: connection_class,
    request: request,
    block_error_message: "A block is required to open a Realtime WebSocket.",
    abort_after_block: -> (_connection, pending_error) { !pending_error.nil? },
    transport_error_message: "`transport` must respond to `open`",
    reserved_options_error_message: lambda do |reserved|
      "`transport_options` cannot include #{reserved.map(&:inspect).join(", ")}"
    end
  )
end