Class: Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer

Inherits:
GServer
  • Object
show all
Defined in:
lib/adhearsion/voip/asterisk/agi_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(port, host) ⇒ RubyServer

Returns a new instance of RubyServer.



10
11
12
# File 'lib/adhearsion/voip/asterisk/agi_server.rb', line 10

def initialize(port, host)
  super(port, host, (1.0/0.0)) # (1.0/0.0) == Infinity
end

Instance Method Details

#disconnecting(port) ⇒ Object



14
15
16
17
# File 'lib/adhearsion/voip/asterisk/agi_server.rb', line 14

def disconnecting(port)
  @call.deliver_message :cancel if !@call.nil?
  super(port)
end

#serve(io) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/adhearsion/voip/asterisk/agi_server.rb', line 19

def serve(io)
  begin
    call = Adhearsion.receive_call_from(io)
  rescue EOFError
    # We didn't get the initial headers we were expecting
    return
  end

  Events.trigger_immediately([:asterisk, :before_call], call)
 ahn_log.agi.debug "Handling call with variables #{call.variables.inspect}"

 return DialPlan::ConfirmationManager.handle(call) if DialPlan::ConfirmationManager.confirmation_call?(call)

 # This is what happens 99.9% of the time.

 DialPlan::Manager.handle call
    	      rescue Hangup
 ahn_log.agi "HANGUP event for call with uniqueid #{call.variables[:uniqueid].inspect} and channel #{call.variables[:channel].inspect}"
  Events.trigger_immediately([:asterisk, :after_call], call)
 call.hangup!
rescue DialPlan::Manager::NoContextError => e
  ahn_log.agi e.message
  call.hangup!
rescue FailedExtensionCallException => failed_call
  begin
    ahn_log.agi "Received \"failed\" meta-call with :failed_reason => #{failed_call.call.failed_reason.inspect}. Executing Executing /asterisk/failed_call event callbacks."
    Events.trigger [:asterisk, :failed_call], failed_call.call
    call.hangup!
  rescue => e
    ahn_log.agi.error e
  end
rescue HungupExtensionCallException => hungup_call
  begin
    ahn_log.agi "Received \"h\" meta-call. Executing /asterisk/hungup_call event callbacks."
    Events.trigger [:asterisk, :hungup_call], hungup_call.call
    call.hangup!
  rescue => e
    ahn_log.agi.error e
  end
rescue UselessCallException
  ahn_log.agi "Ignoring meta-AGI request"
  call.hangup!
        	  # TBD: (may have more hooks than what Jay has defined in hooks.rb)
rescue => e
  ahn_log.agi.error "#{e.class}: #{e.message}"
  ahn_log.agi.error e.backtrace.join("\n\t")
ensure
  Adhearsion.remove_inactive_call call rescue nil
end