Class: Adhearsion::OutboundCall

Inherits:
Call show all
Defined in:
lib/adhearsion/outbound_call.rb

Constant Summary

Constants inherited from Call

Call::CommandTimeout, Call::ExpiredError, Call::Hangup

Instance Attribute Summary collapse

Attributes inherited from Call

#auto_hangup, #controllers, #end_code, #end_reason, #end_time, #start_time, #variables

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Call

#active?, #commands, #deliver_message, #duration, #execute_controller, #from, #hangup, #initialize, #join, #mute, new, #on_end, #on_joined, #on_unjoined, #peers, #register_event_handler, #remove_tag, #send_message, #tag, #tagged_with?, #tags, #to, #unjoin, #unmute, #uri, uri, #wait_for_end, #wait_for_joined, #wait_for_unjoined

Methods included from Celluloid

logger

Constructor Details

This class inherits a constructor from Adhearsion::Call

Instance Attribute Details

#dial_commandObject (readonly)

Returns the value of attribute dial_command.



7
8
9
# File 'lib/adhearsion/outbound_call.rb', line 7

def dial_command
  @dial_command
end

Class Method Details

.originate(to, opts = {}) { ... } ⇒ OutboundCall

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.

Parameters:

  • to (String)

    the URI of the party to dial

  • opts (Hash) (defaults to: {})

    modifier options

Options Hash (opts):

  • :controller (Class)

    the controller to execute when the call is answered

  • :controller_metadata (Hash)

    key-value pairs of metadata to set on the controller

Yields:

  • Call controller routine in block form

Returns:

See Also:



27
28
29
30
31
32
# 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

Instance Method Details

#accept(*args) ⇒ Object



47
48
# File 'lib/adhearsion/outbound_call.rb', line 47

def accept(*args)
end

#answer(*args) ⇒ Object



50
51
# File 'lib/adhearsion/outbound_call.rb', line 50

def answer(*args)
end

#clientObject



43
44
45
# File 'lib/adhearsion/outbound_call.rb', line 43

def client
  PunchblockPlugin::Initializer.client
end

#dial(to, options = {}) ⇒ Object

Dial out an existing outbound call

Parameters:

  • to (String)

    the URI of the party to dial

  • options (Hash) (defaults to: {})

    modifier options

Options Hash (options):

  • :from (String, Optional)

    what to set the Caller ID to

  • :timeout (Integer, Optional)

    in seconds

  • :headers (Hash, Optional)

    SIP headers to attach to the new call.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/adhearsion/outbound_call.rb', line 66

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

  write_and_await_response(Punchblock::Command::Dial.new(options), wait_timeout, true).tap do |dial_command|
    @dial_command = dial_command
    Adhearsion.active_calls << current_actor
    Adhearsion::Events.trigger_immediately :call_dialed, current_actor
  end
end

#domainObject



39
40
41
# File 'lib/adhearsion/outbound_call.rb', line 39

def domain
  dial_command.domain if dial_command
end

#execute_controller_or_router_on_answer(controller, metadata = {}, &controller_block) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/adhearsion/outbound_call.rb', line 105

def execute_controller_or_router_on_answer(controller,  = {}, &controller_block)
  if controller || controller_block
    route = Router::Route.new 'inbound', controller, &controller_block
    route. = 
    on_answer { route.dispatch current_actor }
  else
    run_router_on_answer
  end
end

#idObject



35
36
37
# File 'lib/adhearsion/outbound_call.rb', line 35

def id
  dial_command.target_call_id if dial_command
end

#on_answer(&block) ⇒ Object



101
102
103
# File 'lib/adhearsion/outbound_call.rb', line 101

def on_answer(&block)
  register_event_handler Punchblock::Event::Answered, &block
end

#reject(*args) ⇒ Object



53
54
# File 'lib/adhearsion/outbound_call.rb', line 53

def reject(*args)
end

#run_routerObject



89
90
91
92
93
# File 'lib/adhearsion/outbound_call.rb', line 89

def run_router
  catching_standard_errors do
    Adhearsion.router.handle current_actor
  end
end

#run_router_on_answerObject



95
96
97
98
99
# File 'lib/adhearsion/outbound_call.rb', line 95

def run_router_on_answer
  register_event_handler Punchblock::Event::Answered do |event|
    run_router
  end
end