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

#serve(io) ⇒ Object



14
15
16
17
18
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
# File 'lib/adhearsion/voip/asterisk/agi_server.rb', line 14

def serve(io)
  call = Adhearsion.receive_call_from(io)
  Events.trigger_immediately([:asterisk, :before_call], call)
 ahn_log.agi "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}"
 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.inspect
  ahn_log.agi.error e.backtrace.map { |s| " " * 5 + s }.join("\n")
ensure
  Adhearsion.remove_inactive_call call rescue nil
end