Class: Signalwire::Relay::Calling::Instance
- Inherits:
-
Object
- Object
- Signalwire::Relay::Calling::Instance
- Extended by:
- Forwardable
- Defined in:
- lib/signalwire/relay/calling.rb
Instance Method Summary collapse
- #calls ⇒ Object
- #contexts ⇒ Object
- #dial(from:, to:, device_type: 'phone', timeout: 30) ⇒ Object
- #end_call(call_id) ⇒ Object
- #find_call_by_id(call_id) ⇒ Object
- #find_call_by_tag(tag) ⇒ Object
-
#initialize(client) ⇒ Instance
constructor
A new instance of Instance.
- #listen_for_created_calls ⇒ Object
- #new_call(from:, to:, device_type: 'phone', timeout: 30) ⇒ Object
- #receive(context:, &block) ⇒ Object
Methods included from Logger
Constructor Details
#initialize(client) ⇒ Instance
Returns a new instance of Instance.
15 16 17 18 |
# File 'lib/signalwire/relay/calling.rb', line 15 def initialize(client) @client = client listen_for_created_calls end |
Instance Method Details
#calls ⇒ Object
20 21 22 |
# File 'lib/signalwire/relay/calling.rb', line 20 def calls @calls ||= Concurrent::Array.new end |
#contexts ⇒ Object
24 25 26 |
# File 'lib/signalwire/relay/calling.rb', line 24 def contexts @client.contexts end |
#dial(from:, to:, device_type: 'phone', timeout: 30) ⇒ Object
76 77 78 79 |
# File 'lib/signalwire/relay/calling.rb', line 76 def dial(from:, to:, device_type: 'phone', timeout: 30) handle = new_call(from: from, to: to, device_type: device_type, timeout: timeout) handle.dial end |
#end_call(call_id) ⇒ Object
56 57 58 |
# File 'lib/signalwire/relay/calling.rb', line 56 def end_call(call_id) calls.delete find_call_by_id(call_id) end |
#find_call_by_id(call_id) ⇒ Object
48 49 50 |
# File 'lib/signalwire/relay/calling.rb', line 48 def find_call_by_id(call_id) calls.find { |call| call.id == call_id } end |
#find_call_by_tag(tag) ⇒ Object
52 53 54 |
# File 'lib/signalwire/relay/calling.rb', line 52 def find_call_by_tag(tag) calls.find { |call| call.tag == tag } end |
#listen_for_created_calls ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/signalwire/relay/calling.rb', line 28 def listen_for_created_calls @client.on :event, event_type: 'calling.call.state' do |event| if !find_call_by_id(event.call_id) created_call = Call.from_event(@client, event) calls << created_call end end end |
#new_call(from:, to:, device_type: 'phone', timeout: 30) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/signalwire/relay/calling.rb', line 60 def new_call(from:, to:, device_type: 'phone', timeout: 30) params = { device: { type: device_type, params: { from_number: from, to_number: to, timeout: timeout } } } call = Call.new(@client, params) calls << call call end |
#receive(context:, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/signalwire/relay/calling.rb', line 37 def receive(context:, &block) @client.on :event, event_type: 'calling.call.receive' do |event| logger.debug "Receiving call: #{event.call_params}" call_obj = Signalwire::Relay::Calling::Call.from_event(@client, event) calls << call_obj block.call(call_obj) if block_given? end @client.setup_context(context) end |