Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support excluding recipients

  • Loading branch information...
commit 9065e057a251194faf366c6dcb3ac0741aec89b3 1 parent 8fe1aca
@tristandunn authored
View
1  CHANGELOG.markdown
@@ -2,6 +2,7 @@
## 0.4.0 — Unreleased
+* Support excluding recipients. (Tristan Dunn)
* Update dependencies. (Tristan Dunn)
## 0.3.0 — December 12, 2012
View
7 features/channel_trigger.feature
@@ -82,3 +82,10 @@ Feature: Triggering events on a channel
| private-chat-2 |
Then I should receive a "message" event on the "private-chat-1" channel
And Bob should receive a "message" event on the "private-chat-2" channel
+
+ Scenario: Server triggers an event and excludes a client by socket ID
+ Given I am subscribed to the "chat" channel
+ And Bob is subscribed to the "chat" channel
+ When a "message" event is triggered on the "chat" channel, ignoring Bob
+ Then I should receive a "message" event on the "chat" channel
+ And Bob should not receive a "message" event on the "chat" channel
View
11 features/step_definitions/event_steps.rb
@@ -2,6 +2,17 @@
Pusher.trigger(channel, event, {})
end
+When %{a "$event" event is triggered on the "$channel" channel, ignoring $name} do |event, channel, name|
+ name = nil if name == "me"
+ socket_id = nil
+
+ using_session(name) do
+ socket_id = page.evaluate_script("Pusher.instance.connection.socket_id")
+ end
+
+ Pusher.trigger(channel, event, {}, socket_id: socket_id)
+end
+
When %{a "$event" event is triggered on the following channels:} do |event, table|
channels = table.hashes.collect { |hash| hash["name"] }
View
4 lib/pusher-fake/channel/public.rb
@@ -27,8 +27,10 @@ def add(connection, options = {})
#
# @param [String] event The event name.
# @param [Hash] data The event data.
- def emit(event, data)
+ def emit(event, data, options = {})
connections.each do |connection|
+ next if connection.socket.object_id == options[:socket_id]
+
connection.emit(event, data, name)
end
end
View
2  lib/pusher-fake/server/application.rb
@@ -11,7 +11,7 @@ def self.call(environment)
event = MultiJson.load(request.body.read)
event["channels"].each do |channel|
- Channel.factory(channel).emit(event["name"], event["data"])
+ Channel.factory(channel).emit(event["name"], event["data"], socket_id: event["socket_id"])
end
Rack::Response.new("{}").finish
View
12 spec/lib/pusher-fake/channel/public_spec.rb
@@ -52,9 +52,11 @@
let(:data) { stub }
let(:name) { "name" }
let(:event) { "event" }
+ let(:socket_1) { stub }
+ let(:socket_2) { stub }
let(:connections) { [connection_1, connection_2] }
- let(:connection_1) { stub(emit: nil) }
- let(:connection_2) { stub(emit: nil) }
+ let(:connection_1) { stub(emit: nil, socket: socket_1) }
+ let(:connection_2) { stub(emit: nil, socket: socket_2) }
subject { PusherFake::Channel::Public.new(name) }
@@ -67,6 +69,12 @@
connection_1.should have_received(:emit).with(event, data, name)
connection_2.should have_received(:emit).with(event, data, name)
end
+
+ it "ignores connection if socket_id matches the connections socket object_id" do
+ subject.emit(event, data, socket_id: socket_2.object_id)
+ connection_1.should have_received(:emit).with(event, data, name)
+ connection_2.should have_received(:emit).never
+ end
end
describe PusherFake::Channel, "#includes?" do
View
7 spec/lib/pusher-fake/server/application_spec.rb
@@ -5,12 +5,13 @@
let(:data) { mock }
let(:json) { mock }
let(:name) { "event-name" }
- let(:event) { { "channels" => channels, "name" => name, "data" => data } }
+ let(:event) { { "channels" => channels, "name" => name, "data" => data, "socket_id" => socket_id } }
let(:request) { stub(body: body) }
let(:channels) { ["channel-1", "channel-2"] }
let(:response) { mock }
let(:channel_1) { stub(emit: true) }
let(:channel_2) { stub(emit: true) }
+ let(:socket_id) { stub }
let(:environment) { mock }
subject { PusherFake::Server::Application }
@@ -45,8 +46,8 @@
it "emits the event to the channels" do
subject.call(environment)
- channel_1.should have_received(:emit).with(name, data)
- channel_2.should have_received(:emit).with(name, data)
+ channel_1.should have_received(:emit).with(name, data, socket_id: socket_id)
+ channel_2.should have_received(:emit).with(name, data, socket_id: socket_id)
end
it "creates a Rack response with an empty JSON object" do
Please sign in to comment.
Something went wrong with that request. Please try again.