Class: PusherFake::Channel::Presence
- Defined in:
- lib/pusher-fake/channel/presence.rb
Instance Attribute Summary collapse
-
#members ⇒ Hash
readonly
Channel members hash.
Attributes inherited from Public
Instance Method Summary collapse
-
#initialize(name) ⇒ Presence
constructor
Create a new Presence object.
-
#remove(connection) ⇒ Object
Remove the
connection
from the channel and notify the channel. -
#subscription_data ⇒ Hash
Return a hash containing presence information for the channel.
Methods inherited from Private
#add, #authentication_for, #authorized?
Methods inherited from Public
Constructor Details
#initialize(name) ⇒ Presence
Create a new PusherFake::Channel::Presence object.
10 11 12 13 14 |
# File 'lib/pusher-fake/channel/presence.rb', line 10 def initialize(name) super @members = {} end |
Instance Attribute Details
#members ⇒ Hash (readonly)
Returns Channel members hash.
5 6 7 |
# File 'lib/pusher-fake/channel/presence.rb', line 5 def members @members end |
Instance Method Details
#remove(connection) ⇒ Object
Remove the connection
from the channel and notify the channel.
Also trigger the member_removed webhook.
21 22 23 24 25 26 27 28 29 |
# File 'lib/pusher-fake/channel/presence.rb', line 21 def remove(connection) super if members.key?(connection) trigger("member_removed", channel: name, user_id: members[connection][:user_id]) emit("pusher_internal:member_removed", members.delete(connection)) end end |
#subscription_data ⇒ Hash
Return a hash containing presence information for the channel.
34 35 36 37 38 39 40 41 42 |
# File 'lib/pusher-fake/channel/presence.rb', line 34 def subscription_data hash = Hash[ members.map { |_, member| [member[:user_id], member[:user_info]] } ] { presence: { hash: hash, count: members.size } } end |