Module: Adhearsion::CallController::Dial
- Included in:
- Adhearsion::CallController
- Defined in:
- lib/adhearsion/call_controller/dial.rb
Defined Under Namespace
Classes: DialStatus
Instance Method Summary (collapse)
-
- (DialStatus) dial(to, options = {}, latch = nil)
Dial one or more third parties and join one to this call.
Instance Method Details
- (DialStatus) dial(to[String], options = {}) - (DialStatus) dial(to[Array], options = {}) - (DialStatus) dial(to[Hash], options = {})
Dial one or more third parties and join one to this call
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/adhearsion/call_controller/dial.rb', line 45 def dial(to, = {}, latch = nil) targets = to.respond_to?(:has_key?) ? to : Array(to) status = DialStatus.new latch ||= CountDownLatch.new targets.size call.on_end { |_| latch.countdown! until latch.count == 0 } _for = .delete :for [:timeout] ||= _for if _for [:from] ||= call.from calls = targets.map do |target, | new_call = OutboundCall.new new_call.on_answer do |event| calls.each do |call_to_hangup, _| begin next if call_to_hangup.id == new_call.id logger.debug "#dial hanging up call #{call_to_hangup.id} because this call has been answered by another channel" call_to_hangup.hangup rescue Celluloid::DeadActorError # This actor may previously have been shut down due to the call ending end end new_call.register_event_handler Punchblock::Event::Unjoined, :call_id => call.id do |unjoined| new_call["dial_countdown_#{call.id}"] = true latch.countdown! throw :pass end logger.debug "#dial joining call #{new_call.id} to #{call.id}" new_call.join call status.answer! end new_call.on_end do |event| latch.countdown! unless new_call["dial_countdown_#{call.id}"] case event.reason when :error status.error! end end [new_call, target, ] end calls.map! do |call, target, | = .dup.deep_merge if call.dial target, ( || ) call end status.calls = calls no_timeout = latch.wait [:timeout] status.timeout! unless no_timeout logger.debug "#dial finished. Hanging up #{calls.size} outbound calls: #{calls.map(&:id).join ", "}." calls.each do |outbound_call| begin outbound_call.hangup rescue Celluloid::DeadActorError # This actor may previously have been shut down due to the call ending end end status end |