Class: WhereIsWaldo::RosterDelivery::Poll

Inherits:
Base
  • Object
show all
Defined in:
app/services/where_is_waldo/roster_delivery.rb

Overview

Heartbeat/poll pull: the client polls; the server transmits a per-viewer, server-filtered snapshot (first poll / resync) or diff (subsequent). The diff baseline lives in Rails.cache keyed per session (tab), TTL'd so a stale/expired cursor self-heals into a full snapshot. Handles ANY visibility rule via config.roster_visible_to. No broadcasts.

Direct Known Subclasses

Nudge

Instance Method Summary collapse

Instance Method Details

#modeObject

Overridden by :nudge so the snapshot advertises the right mode.



76
77
78
# File 'app/services/where_is_waldo/roster_delivery.rb', line 76

def mode
  :poll
end

#on_transition(_subject_id) ⇒ Object

No push work on transition — pull clients poll for changes.



98
# File 'app/services/where_is_waldo/roster_delivery.rb', line 98

def on_transition(_subject_id); end

#poll_messages(subject, session_id) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'app/services/where_is_waldo/roster_delivery.rb', line 86

def poll_messages(subject, session_id)
  current = current_members(subject)
  baseline = read_baseline(session_id)
  write_baseline(session_id, current)

  # Cache miss / expired cursor -> full snapshot (self-healing resync).
  return [Roster.snapshot_message(current.values, mode: mode)] if baseline.nil?

  diff_messages(baseline, current)
end

#subscribe_plan(subject, session_id) ⇒ Object



80
81
82
83
84
# File 'app/services/where_is_waldo/roster_delivery.rb', line 80

def subscribe_plan(subject, session_id)
  current = current_members(subject)
  write_baseline(session_id, current)
  { streams: subscribe_streams(subject), messages: [Roster.snapshot_message(current.values, mode: mode)] }
end