From d1f2b70ed6e4de159a90aadb9a24dcabc50ea1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Hauge=20Bj=C3=B8rnskov?= <19725+henrikbjorn@users.noreply.github.com> Date: Thu, 1 Oct 2026 10:13:40 +0200 Subject: [PATCH] Add an inbound connection's filters before subscribing to events FreeSWITCH sends every subscribed event while a connection has no filters. run_session subscribed first and added the filters after, so until the last filter reply came back, the connection received the subscribed events of every channel on the node. Filters now go first, then the subscription. --- lib/librevox/listener/inbound.rb | 11 +++++++---- .../librevox/listener/inbound_filter_test.rb | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/librevox/listener/inbound.rb b/lib/librevox/listener/inbound.rb index 480d6cd..7517bef 100644 --- a/lib/librevox/listener/inbound.rb +++ b/lib/librevox/listener/inbound.rb @@ -31,10 +31,9 @@ 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| @@ -42,6 +41,10 @@ def run_session end end + events = self.class.subscribe_events || ['ALL'] + + send_message "event plain #{events.join(' ')}" + connection_completed end diff --git a/test/functional/librevox/listener/inbound_filter_test.rb b/test/functional/librevox/listener/inbound_filter_test.rb index d41a43d..cf770fc 100644 --- a/test/functional/librevox/listener/inbound_filter_test.rb +++ b/test/functional/librevox/listener/inbound_filter_test.rb @@ -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 @@ -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