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

Kept out of APM as its own transaction by default — heartbeats are the highest-volume, least-interesting cable action, so reporting each one distorts throughput and average response time without adding signal. The wrapper no-ops unless the host runs a supported agent; see WhereIsWaldo::Apm and config.ignore_heartbeat_apm. The real work lives in perform_heartbeat, which is private so a client can't invoke it directly as a channel action (only public methods are processable actions).



42
43
44
# File 'app/channels/where_is_waldo/presence_channel.rb', line 42

def heartbeat(data)
  WhereIsWaldo::Apm.ignoring_transaction { perform_heartbeat(data) }
end

#subscribedObject



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

#unsubscribedObject



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