Class: PusherFake::Channel::Public
- Inherits:
-
Object
- Object
- PusherFake::Channel::Public
- Defined in:
- lib/pusher-fake/channel/public.rb
Overview
A public channel.
Direct Known Subclasses
Constant Summary collapse
- CACHE_CHANNEL_PREFIX =
/^(private-|presence-){0,1}cache-/
Instance Attribute Summary collapse
-
#connections ⇒ Array
readonly
Connections in this channel.
-
#name ⇒ String
readonly
The channel name.
Instance Method Summary collapse
-
#add(connection, options = {}) ⇒ Object
Add the connection to the channel.
-
#emit(event, data, options = {}) ⇒ Object
Emit an event to the channel.
-
#includes?(connection) ⇒ Boolean
Determine if the
connection
is in the channel. -
#initialize(name) ⇒ Public
constructor
Create a new Public object.
-
#remove(connection) ⇒ Object
Remove the
connection
from the channel. -
#subscription_data ⇒ Hash
abstract
Return subscription data for the channel.
- #trigger(name, data = {}) ⇒ Object
Constructor Details
#initialize(name) ⇒ Public
Create a new PusherFake::Channel::Public object.
18 19 20 21 22 |
# File 'lib/pusher-fake/channel/public.rb', line 18 def initialize(name) @name = name @last_event = nil @connections = [] end |
Instance Attribute Details
#connections ⇒ Array (readonly)
Returns Connections in this channel.
10 11 12 |
# File 'lib/pusher-fake/channel/public.rb', line 10 def connections @connections end |
#name ⇒ String (readonly)
Returns The channel name.
13 14 15 |
# File 'lib/pusher-fake/channel/public.rb', line 13 def name @name end |
Instance Method Details
#add(connection, options = {}) ⇒ Object
Add the connection to the channel.
28 29 30 31 |
# File 'lib/pusher-fake/channel/public.rb', line 28 def add(connection, = {}) subscription_succeeded(connection, ) emit_last_event(connection) end |
#emit(event, data, options = {}) ⇒ Object
Emit an event to the channel.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pusher-fake/channel/public.rb', line 37 def emit(event, data, = {}) if cache_channel? @last_event = [event, data] end connections.each do |connection| unless connection.id == [:socket_id] connection.emit(event, data, name) end end end |
#includes?(connection) ⇒ Boolean
Determine if the connection
is in the channel.
53 54 55 |
# File 'lib/pusher-fake/channel/public.rb', line 53 def includes?(connection) connections.index(connection) end |
#remove(connection) ⇒ Object
Remove the connection
from the channel.
If it is the last connection, trigger the channel_vacated webhook.
62 63 64 65 66 |
# File 'lib/pusher-fake/channel/public.rb', line 62 def remove(connection) connections.delete(connection) trigger("channel_vacated", channel: name) if connections.empty? end |
#subscription_data ⇒ Hash
This method is abstract.
Return subscription data for the channel.
72 73 74 |
# File 'lib/pusher-fake/channel/public.rb', line 72 def subscription_data {} end |
#trigger(name, data = {}) ⇒ Object
76 77 78 |
# File 'lib/pusher-fake/channel/public.rb', line 76 def trigger(name, data = {}) PusherFake::Webhook.trigger(name, data) end |