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
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)
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!
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
|