Class: WhereIsWaldo::PresenceChannel

Inherits:
ApplicationCable::Channel show all
Defined in:
app/channels/where_is_waldo/presence_channel.rb

Instance Method Summary collapse

Instance Method Details

#heartbeat(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/channels/where_is_waldo/presence_channel.rb', line 26

def heartbeat(data)
  data = data.with_indifferent_access

  tab_visible = data[:tab_visible] != false
  subject_active = data[:subject_active] != false

  WhereIsWaldo.heartbeat(
    session_id: waldo_session_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

#subscribedObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/channels/where_is_waldo/presence_channel.rb', line 5

def subscribed
  stream_from subject_stream

  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

#unsubscribedObject



18
19
20
21
22
23
24
# File 'app/channels/where_is_waldo/presence_channel.rb', line 18

def unsubscribed
  WhereIsWaldo.disconnect(session_id: waldo_session_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