Class: WhereIsWaldo::PresenceChannel
- Inherits:
-
ApplicationCable::Channel
- Object
- ActionCable::Channel::Base
- ApplicationCable::Channel
- WhereIsWaldo::PresenceChannel
- Defined in:
- app/channels/where_is_waldo/presence_channel.rb
Instance Method Summary collapse
Instance Method Details
#heartbeat(data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/channels/where_is_waldo/presence_channel.rb', line 35 def heartbeat(data) return if presence_suppressed? data = data.with_indifferent_access tab_visible = data[:tab_visible] != false subject_active = data[:subject_active] != false WhereIsWaldo.heartbeat( session_id: waldo_session_id, subject_id: waldo_subject_id, tab_visible: tab_visible, subject_active: subject_active, last_activity_at: data[:last_activity_at], metadata: data[:metadata] || {} ) # Efficiency: only touch the roster when THIS session's activity/visibility # actually flips. Steady-state heartbeats (no change) cost zero broadcasts. return unless roster_transition?(tab_visible, subject_active) @wiw_tab_visible = tab_visible @wiw_subject_active = subject_active publish_roster_change end |
#subscribed ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/channels/where_is_waldo/presence_channel.rb', line 5 def subscribed stream_from subject_stream # The subject_stream subscription above is unconditional: even when the # subscriber's presence is suppressed (see suppress_presence_proc), the # tab is a legitimate consumer of WhereIsWaldo.broadcast_to signaling # and shouldn't be cut off from messages just because it doesn't count # as "present." return if presence_suppressed? register_presence # Seed the local transition gate, resolve the roster delivery strategy for # this subject's account once, and announce arrival. @wiw_tab_visible = true @wiw_subject_active = true @wiw_roster_strategy = resolve_roster_strategy publish_roster_change end |
#unsubscribed ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/channels/where_is_waldo/presence_channel.rb', line 25 def unsubscribed return if presence_suppressed? WhereIsWaldo.disconnect(session_id: waldo_session_id, subject_id: waldo_subject_id) # Recompute the subject's aggregate (they may still be present in another # tab/device) and announce the change to the org roster. publish_roster_change end |