class Adhearsion::OutboundCall
Attributes
Public Class Methods
Create a new outbound call
By default, the call will enter the router when it is answered, similar to incoming calls. Alternatively, a controller may be specified.
@param [String] to the URI of the party to dial @param [Hash] opts modifier options @option opts [Class] :controller the controller to execute when the call is answered @option opts [Hash] :controller_metadata key-value pairs of metadata to set on the controller @yield Call
controller routine in block form
@return [OutboundCall] the ringing call
@see dial
for more possible options
# File lib/adhearsion/outbound_call.rb, line 27 def originate(to, opts = {}, &controller_block) new.tap do |call| call.execute_controller_or_router_on_answer opts.delete(:controller), opts.delete(:controller_metadata), &controller_block call.dial to, opts end end
Public Instance Methods
# File lib/adhearsion/outbound_call.rb, line 55 def accept(*args) end
# File lib/adhearsion/outbound_call.rb, line 58 def answer(*args) end
# File lib/adhearsion/outbound_call.rb, line 51 def client PunchblockPlugin::Initializer.client end
Dial out an existing outbound call
@param [String] to the URI of the party to dial @param [Hash] options modifier options @option options [String, Optional] :from what to set the Caller ID to @option options [Integer, Optional] :timeout in seconds @option options [Hash, Optional] :headers SIP headers to attach to
the new call.
# File lib/adhearsion/outbound_call.rb, line 74 def dial(to, options = {}) options = options.dup options[:to] = to if options[:timeout] wait_timeout = options[:timeout] options[:timeout] = options[:timeout] * 1000 else wait_timeout = 60 end uri = client.new_call_uri options[:uri] = uri @dial_command = Punchblock::Command::Dial.new(options) ref = Punchblock::Ref.new uri: uri @transport = ref.scheme @id = ref.call_id @domain = ref.domain Adhearsion.active_calls << current_actor write_and_await_response(@dial_command, wait_timeout, true).tap do |dial_command| if @dial_command.uri != self.uri logger.warn "Requested call URI (#{uri}) was not respected. Tracking by new URI #{self.uri}. This might cause a race in event handling, please upgrade your Rayo server." Adhearsion.active_calls << current_actor Adhearsion.active_calls.delete(@id) end Adhearsion::Events.trigger_immediately :call_dialed, current_actor end rescue clear_from_active_calls raise end
# File lib/adhearsion/outbound_call.rb, line 43 def domain if dial_command dial_command.domain || @domain else @domain end end
# File lib/adhearsion/outbound_call.rb, line 131 def execute_controller_or_router_on_answer(controller, metadata = {}, &controller_block) if controller || controller_block route = Router::Route.new 'inbound', controller, &controller_block route.controller_metadata = metadata on_answer { route.dispatch current_actor } else run_router_on_answer end end
# File lib/adhearsion/outbound_call.rb, line 35 def id if dial_command dial_command.target_call_id || @id else @id end end
# File lib/adhearsion/outbound_call.rb, line 127 def on_answer(&block) register_event_handler Punchblock::Event::Answered, &block end
@private
Adhearsion::Call#register_initial_handlers
# File lib/adhearsion/outbound_call.rb, line 110 def register_initial_handlers super on_answer { |event| @start_time = event.timestamp.to_time } end
# File lib/adhearsion/outbound_call.rb, line 61 def reject(*args) end
# File lib/adhearsion/outbound_call.rb, line 115 def run_router catching_standard_errors do Adhearsion.router.handle current_actor end end
# File lib/adhearsion/outbound_call.rb, line 121 def run_router_on_answer register_event_handler Punchblock::Event::Answered do |event| run_router end end
Private Instance Methods
# File lib/adhearsion/outbound_call.rb, line 143 def transport if dial_command dial_command.transport || @transport else @transport end end