Skip to content

Commit 84e492e

Browse files
committed
Fix handling of DBGet via AMI [#82 state:fixcommitted]
1 parent 680179d commit 84e492e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/adhearsion/voip/asterisk/manager_interface.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module Manager
2929
#
3030
class ManagerInterface
3131

32-
CAUSAL_EVENT_NAMES = ["queuestatus", "sippeers", "parkedcalls", "status", "dahdishowchannels", "coreshowchannels"] unless defined? CAUSAL_EVENT_NAMES
32+
CAUSAL_EVENT_NAMES = %w[queuestatus sippeers parkedcalls status
33+
dahdishowchannels coreshowchannels dbget] unless defined? CAUSAL_EVENT_NAMES
3334

3435
class << self
3536

@@ -70,10 +71,12 @@ def causal_event_terminator_name_for(action_name)
7071
return nil unless has_causal_events?(action_name)
7172
action_name = action_name.to_s.downcase
7273
case action_name
73-
when "queuestatus", "parkedcalls", "status", "coreshowchannels"
74+
when "sippeers"
75+
"peerlistcomplete"
76+
when "dbget"
77+
"dbgetresponse"
78+
else
7479
action_name + "complete"
75-
when "sippeers"
76-
"peerlistcomplete"
7780
end
7881
end
7982

@@ -132,21 +135,29 @@ def action_message_received(message)
132135

133136
if corresponding_action
134137

138+
# The "DBGet" command is causal, meaning it has an separate
139+
# event that contains the data for command's response. However,
140+
# unlike other causal commands, AMI does not send a
141+
# "DBGetComplete" action indicating the causal event is
142+
# finished. This is fixed starting in Asterisk 1.8.
143+
if message.name.downcase == "dbgetresponse"
144+
event_collection << message
145+
end
146+
135147
# If this is the meta-event which signals no more events will follow and the response is complete.
136148
if message.name.downcase == corresponding_action.causal_event_terminator_name
137-
138-
# Result found! Wake up any Threads waiting
149+
# Wake up the waiting Thread
139150
corresponding_action.future_resource.resource = event_collection.freeze
140151

152+
# Clear the stored action and event collection
141153
@current_action_with_causal_events = nil
142154
@event_collection_for_current_action = nil
143-
144155
else
145156
event_collection << message
146157
# We have more causal events coming.
147158
end
148159
else
149-
ahn_log.ami.error "Got an unexpected event on actions socket! This may be a bug! #{message.inspect}"
160+
ahn_log.ami.error "Got an unexpected event on actions socket! This AMI command may have a multi-message response. Try making Adhearsion treat it as CAUSAL_EVENT #{message.inspect}"
150161
end
151162

152163
elsif message["ActionID"].nil?
@@ -505,7 +516,7 @@ def clear_actions_connection_resources
505516
#
506517
def establish_actions_connection
507518
@actions_connection = EventSocket.connect(@host, @port) do |handler|
508-
handler.receive_data { |data| @actions_lexer << data }
519+
handler.receive_data { |data| @actions_lexer << data }
509520
handler.connected { actions_connection_established }
510521
handler.disconnected { actions_connection_disconnected }
511522
end
@@ -530,7 +541,7 @@ def establish_events_connection
530541

531542
# Note: the @events_connection instance variable is set in login()
532543
@events_connection = EventSocket.connect(@host, @port) do |handler|
533-
handler.receive_data { |data| @events_lexer << data }
544+
handler.receive_data { |data| @events_lexer << data }
534545
handler.connected { events_connection_established }
535546
handler.disconnected { events_connection_disconnected }
536547
end

0 commit comments

Comments
 (0)