Class: Adhearsion::OutboundCall

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

Constant Summary

Constant Summary

Constants inherited from Call

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

Instance Attribute Summary (collapse)

Attributes inherited from Call

#commands, #controllers, #end_reason, #variables

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Call

#active?, #deliver_message, #execute_controller, #hangup, #initialize, #join, #mute, new, #on_end, #on_joined, #on_unjoined, #peers, #register_event_handler, #remove_tag, #tag, #tagged_with?, #tags, #unjoin, #unmute, #wait_for_joined, #wait_for_unjoined

Methods included from Celluloid

logger

Constructor Details

This class inherits a constructor from Adhearsion::Call

Instance Attribute Details

- (Object) dial_command (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

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

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

- (Object) accept(*args)



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

def accept(*args)
end

- (Object) answer(*args)



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

def answer(*args)
end

- (Object) client



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

def client
  PunchblockPlugin::Initializer.client
end

- (Object) dial(to, options = {})

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.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/adhearsion/outbound_call.rb', line 62

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).tap do |dial_command|
    @dial_command = dial_command
    Adhearsion.active_calls << current_actor
    Adhearsion::Events.trigger_immediately :call_dialed, current_actor
  end
end

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



99
100
101
102
103
104
105
106
107
# File 'lib/adhearsion/outbound_call.rb', line 99

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

- (Object) id



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

def id
  dial_command.target_call_id if dial_command
end

- (Object) on_answer(&block)



92
93
94
95
96
97
# File 'lib/adhearsion/outbound_call.rb', line 92

def on_answer(&block)
  register_event_handler Punchblock::Event::Answered do |event|
    block.call event
    throw :pass
  end
end

- (Object) reject(*args)



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

def reject(*args)
end

- (Object) run_router



79
80
81
82
83
# File 'lib/adhearsion/outbound_call.rb', line 79

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

- (Object) run_router_on_answer



85
86
87
88
89
90
# File 'lib/adhearsion/outbound_call.rb', line 85

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