class Signalwire::Relay::Calling::Instance

Public Class Methods

new(client) click to toggle source
# File lib/signalwire/relay/calling.rb, line 15
def initialize(client)
  @client = client
  listen_for_created_calls
end

Public Instance Methods

calls() click to toggle source
# File lib/signalwire/relay/calling.rb, line 20
def calls
  @calls ||= Concurrent::Array.new
end
contexts() click to toggle source
# File lib/signalwire/relay/calling.rb, line 24
def contexts
  @client.contexts
end
dial(from:, to:, device_type: 'phone', timeout: 30) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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