Class: PusherFake::Channel::Presence
- Defined in:
- lib/pusher-fake/channel/presence.rb
Overview
A presence channel.
Constant Summary
Constants inherited from Public
PusherFake::Channel::Public::CACHE_CHANNEL_PREFIX
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
#add, #emit, #includes?, #trigger
Constructor Details
#initialize(name) ⇒ Presence
Create a new PusherFake::Channel::Presence object.
13 14 15 16 17 |
# File 'lib/pusher-fake/channel/presence.rb', line 13 def initialize(name) super @members = {} end |
Instance Attribute Details
#members ⇒ Hash (readonly)
Returns Channel members hash.
8 9 10 |
# File 'lib/pusher-fake/channel/presence.rb', line 8 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.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pusher-fake/channel/presence.rb', line 24 def remove(connection) super return unless members.key?(connection) trigger("member_removed", channel: name, user_id: members[connection][:user_id]) emit("pusher_internal:member_removed", members.delete(connection)) end |
#subscription_data ⇒ Hash
Return a hash containing presence information for the channel.
38 39 40 41 42 |
# File 'lib/pusher-fake/channel/presence.rb', line 38 def subscription_data hash = members.to_h { |_, member| [member[:user_id], member[:user_info]] } { presence: { hash: hash, count: members.size } } end |