Class: Pinnacle::Wrapper::Voice::Client
- Inherits:
-
Object
- Object
- Pinnacle::Wrapper::Voice::Client
- Defined in:
- lib/pinnacle/wrapper/voice/client.rb
Defined Under Namespace
Classes: DefaultSocket
Constant Summary collapse
- DEFAULT_RECONNECT =
{ enabled: true }.freeze
Instance Method Summary collapse
- #connect(call_id:, token: nil, protocols: nil, reconnect: nil, socket: nil) ⇒ Object
- #connect_stream(stream_url, protocols: nil, reconnect: nil, socket: nil) ⇒ Object
- #create_and_connect(to:, from:, record: nil, metadata: nil, token: nil, protocols: nil, reconnect: nil, socket: nil, request_options: {}) ⇒ Object
-
#initialize(client:) ⇒ Client
constructor
A new instance of Client.
Constructor Details
Instance Method Details
#connect(call_id:, token: nil, protocols: nil, reconnect: nil, socket: nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pinnacle/wrapper/voice/client.rb', line 86 def connect(call_id:, token: nil, protocols: nil, reconnect: nil, socket: nil) socket_class = socket || default_socket token_params = token || {} stream_token = @calls.create_stream_token(**token_params, id: call_id) create_socket = -> do next_token = @calls.create_stream_token(**token_params, id: call_id) new_socket(socket_class, next_token.stream_url, protocols) end VoiceSocket.new( new_socket(socket_class, stream_token.stream_url, protocols), create_socket: create_socket, reconnect: DEFAULT_RECONNECT.merge(reconnect || {}) ) end |
#connect_stream(stream_url, protocols: nil, reconnect: nil, socket: nil) ⇒ Object
102 103 104 105 106 |
# File 'lib/pinnacle/wrapper/voice/client.rb', line 102 def connect_stream(stream_url, protocols: nil, reconnect: nil, socket: nil) socket_class = socket || default_socket create_socket = -> { new_socket(socket_class, stream_url, protocols) } VoiceSocket.new(create_socket.call, create_socket: create_socket, reconnect: reconnect) end |
#create_and_connect(to:, from:, record: nil, metadata: nil, token: nil, protocols: nil, reconnect: nil, socket: nil, request_options: {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pinnacle/wrapper/voice/client.rb', line 59 def create_and_connect( to:, from:, record: nil, metadata: nil, token: nil, protocols: nil, reconnect: nil, socket: nil, request_options: {} ) call_params = { to: to, from: from } call_params[:record] = record unless record.nil? call_params[:metadata] = unless .nil? call = @calls.create(**call_params, request_options: ) connection = connect( call_id: call.id, token: token, protocols: protocols, reconnect: DEFAULT_RECONNECT.merge(reconnect || {}), socket: socket ) connection.call = call connection.call_id = call.id connection end |