From 496a2c58647ad33094df3c83f35b352728d97232 Mon Sep 17 00:00:00 2001 From: Sumit Birla Date: Wed, 12 Feb 2014 14:05:40 -0500 Subject: [PATCH 1/2] allow event filters --- README.md | 5 +++++ TODO | 2 -- lib/librevox/listener/inbound.rb | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3427661..e6c4e0a 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,10 @@ port is quite simple: it takes an optional hash with arguments: Librevox.start SomeListener, :host => "1.2.3.4", :port => "8087", :auth => "pwd" + +filters can be applied to a listerner with the filters argument + + Librevox.start SomeListener, :filters = ["Event-Name CHANNEL_EXECUTE", "Event-NAME HEARTBEAT"] Multiple listeners can be started at once by passing a block to `Librevox.start`: @@ -129,6 +133,7 @@ Multiple listeners can be started at once by passing a block to `Librevox.start` run SomeListener run OtherListener, :port => "8080" end + ## Closing connection diff --git a/TODO b/TODO index c18d42f..3e09ef6 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ - check command/application input and raise ArgumentError, possibly. -- filter events - - move test suite from bacon -> test/unit. - test how this works in async mode - I imagine that it might mess with diff --git a/lib/librevox/listener/inbound.rb b/lib/librevox/listener/inbound.rb index 96165ae..d7ed772 100644 --- a/lib/librevox/listener/inbound.rb +++ b/lib/librevox/listener/inbound.rb @@ -8,7 +8,8 @@ def initialize args={} @auth = args[:auth] || "ClueCon" @host, @port = args.values_at(:host, :port) - + @filters = args[:filters] || [] + EventMachine.add_shutdown_hook {@shutdown = true} end @@ -17,6 +18,7 @@ def connection_completed super send_data "auth #{@auth}\n\n" send_data "event plain ALL\n\n" + @filters.each { |f| send_data "filter #{f}\n\n" } end def unbind From 76d158c8b02bd18c127dcf012a42bc467bc66b8c Mon Sep 17 00:00:00 2001 From: sumitbirla Date: Wed, 12 Feb 2014 14:15:28 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6c4e0a..e2326ce 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ it takes an optional hash with arguments: filters can be applied to a listerner with the filters argument - Librevox.start SomeListener, :filters = ["Event-Name CHANNEL_EXECUTE", "Event-NAME HEARTBEAT"] + Librevox.start SomeListener, :filters => ["Event-Name CHANNEL_EXECUTE", "Event-NAME HEARTBEAT"] Multiple listeners can be started at once by passing a block to `Librevox.start`: