Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/librevox/listener/inbound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ def run_session

send_message "auth #{@auth}"

events = self.class.subscribe_events || ['ALL']

send_message "event plain #{events.join(' ')}"

# Filters first: FreeSWITCH sends every subscribed event while a
# connection has no filters, so subscribing first would let the whole
# node's events through until the filters land.
filters = self.class.subscribe_filters || {}
filters.each do |header, values|
[*values].each do |value|
send_message "filter #{header} #{value}"
end
end

events = self.class.subscribe_events || ['ALL']

send_message "event plain #{events.join(' ')}"

connection_completed
end

Expand Down
9 changes: 5 additions & 4 deletions test/functional/librevox/listener/inbound_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def setup
@session_task = Async { @listener.run_session }
# auth reply
command_reply "Reply-Text" => "+OK accepted"
# event reply
command_reply "Reply-Text" => "+OK event listener enabled plain"
# 3 filter replies
command_reply "Reply-Text" => "+OK filter added"
command_reply "Reply-Text" => "+OK filter added"
command_reply "Reply-Text" => "+OK filter added"
# event reply
command_reply "Reply-Text" => "+OK event listener enabled plain"
super
end

Expand All @@ -36,12 +36,13 @@ def teardown
super
end

def test_sends_auth_events_and_filters
# Filters before the subscription, so no unfiltered event gets through.
def test_sends_auth_then_filters_then_events
assert_equal "auth ClueCon", @listener.outgoing_data.shift
assert_equal "event plain CUSTOM CHANNEL_EXECUTE", @listener.outgoing_data.shift
assert_equal "filter Caller-Context default", @listener.outgoing_data.shift
assert_equal "filter Caller-Context example", @listener.outgoing_data.shift
assert_equal "filter Caller-Privacy-Hide-Name no", @listener.outgoing_data.shift
assert_equal "event plain CUSTOM CHANNEL_EXECUTE", @listener.outgoing_data.shift
assert_nil @listener.outgoing_data.shift
end
end