Module: Garufa::Subscriptions
Instance Method Summary collapse
- #add(subscription) ⇒ Object
- #all ⇒ Object
- #channel_size(channel) ⇒ Object
- #channel_stats(channel) ⇒ Object
- #include?(subscription) ⇒ Boolean
- #notify(channels, event, options = {}) ⇒ Object
- #notify_channel(channel, event, options) ⇒ Object
- #remove(subscription) ⇒ Object
- #stats ⇒ Object
Instance Method Details
#add(subscription) ⇒ Object
19 20 21 22 |
# File 'lib/garufa/subscriptions.rb', line 19 def add(subscription) subs = subscriptions[subscription.channel] ||= Set.new @semaphore.synchronize { subs.add subscription } end |
#all ⇒ Object
11 12 13 |
# File 'lib/garufa/subscriptions.rb', line 11 def all subscriptions end |
#channel_size(channel) ⇒ Object
59 60 61 |
# File 'lib/garufa/subscriptions.rb', line 59 def channel_size(channel) stats.channel_size(channel) end |
#channel_stats(channel) ⇒ Object
63 64 65 |
# File 'lib/garufa/subscriptions.rb', line 63 def channel_stats(channel) stats.single_channel(channel) end |
#include?(subscription) ⇒ Boolean
54 55 56 57 |
# File 'lib/garufa/subscriptions.rb', line 54 def include?(subscription) subs = subscriptions[subscription.channel] subs && subs.include?(subscription) end |
#notify(channels, event, options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/garufa/subscriptions.rb', line 30 def notify(channels, event, = {}) channels.each do |channel| notify_channel(channel, event, ) end end |
#notify_channel(channel, event, options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/garufa/subscriptions.rb', line 36 def notify_channel(channel, event, ) return if channel_size(channel).zero? subs = subscriptions[channel] @semaphore.synchronize { subs.each do |sub| # Skip notifying if the same socket_id is provided next if sub.socket_id == [:socket_id] # Skip notifying the same member (probably from different tabs) next if sub.presence_channel? and sub.channel_data == [:data] sub.notify Message.channel_event(channel, event, [:data]) end } end |
#remove(subscription) ⇒ Object
24 25 26 27 28 |
# File 'lib/garufa/subscriptions.rb', line 24 def remove(subscription) channel = subscription.channel subscriptions[channel].delete subscription subscriptions.delete(channel) if channel_size(channel).zero? end |
#stats ⇒ Object
15 16 17 |
# File 'lib/garufa/subscriptions.rb', line 15 def stats @stats ||= API::Stats.new(subscriptions) end |