Module: WhereIsWaldo

Defined in:
lib/where_is_waldo.rb,
lib/where_is_waldo/engine.rb,
lib/where_is_waldo/version.rb,
lib/where_is_waldo/configuration.rb,
app/models/where_is_waldo/presence.rb,
app/services/where_is_waldo/roster.rb,
app/jobs/where_is_waldo/application_job.rb,
app/services/where_is_waldo/broadcaster.rb,
app/channels/where_is_waldo/jwt_connection.rb,
app/channels/where_is_waldo/roster_channel.rb,
app/services/where_is_waldo/roster_delivery.rb,
app/channels/where_is_waldo/presence_channel.rb,
app/jobs/where_is_waldo/presence_cleanup_job.rb,
app/models/where_is_waldo/application_record.rb,
app/services/where_is_waldo/presence_service.rb,
app/models/concerns/where_is_waldo/broadcastable.rb,
app/services/where_is_waldo/adapters/base_adapter.rb,
app/services/where_is_waldo/adapters/redis_adapter.rb,
app/channels/where_is_waldo/application_cable/channel.rb,
app/services/where_is_waldo/adapters/database_adapter.rb,
lib/generators/where_is_waldo/install/install_generator.rb,
app/channels/where_is_waldo/application_cable/connection.rb

Defined Under Namespace

Modules: Adapters, ApplicationCable, Broadcastable, Generators, JwtConnection, RosterDelivery Classes: ApplicationJob, ApplicationRecord, Broadcaster, Configuration, Engine, Presence, PresenceChannel, PresenceCleanupJob, PresenceService, Roster, RosterChannel

Constant Summary collapse

VERSION =
File.read(File.expand_path("../../VERSION", __dir__)).strip

Class Method Summary collapse

Class Method Details

.all_online_ids(timeout: nil) ⇒ Object

Get all online subject IDs (no scope filtering)



54
55
56
# File 'lib/where_is_waldo.rb', line 54

def all_online_ids(timeout: nil)
  PresenceService.all_online_ids(timeout: timeout)
end

.broadcast_to(scope, message_type, data = {}) ⇒ Object

Broadcast to subjects in a scope

Examples:

WhereIsWaldo.broadcast_to(org.members, :notification, { message: "Hello" })



115
116
117
# File 'lib/where_is_waldo.rb', line 115

def broadcast_to(scope, message_type, data = {})
  Broadcaster.broadcast_to(scope, message_type, data)
end

.broadcast_to_online(scope, message_type, data = {}) ⇒ Object

Broadcast only to online subjects in a scope

Examples:

WhereIsWaldo.broadcast_to_online(org.members, :alert, { message: "Urgent" })



121
122
123
# File 'lib/where_is_waldo.rb', line 121

def broadcast_to_online(scope, message_type, data = {})
  Broadcaster.broadcast_to_online(scope, message_type, data)
end

.broadcast_to_session(session_id, message_type, data = {}) ⇒ Object

Broadcast to a specific session

Examples:

WhereIsWaldo.broadcast_to_session(session_id, :force_logout, { reason: "..." })



127
128
129
# File 'lib/where_is_waldo.rb', line 127

def broadcast_to_session(session_id, message_type, data = {})
  Broadcaster.broadcast_to_session(session_id, message_type, data)
end

.cleanup(timeout: nil) ⇒ Object



78
79
80
# File 'lib/where_is_waldo.rb', line 78

def cleanup(timeout: nil)
  PresenceService.cleanup(timeout: timeout)
end

.configObject



17
18
19
# File 'lib/where_is_waldo.rb', line 17

def config
  configuration
end

.configurationObject



9
10
11
# File 'lib/where_is_waldo.rb', line 9

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



13
14
15
# File 'lib/where_is_waldo.rb', line 13

def configure
  yield(configuration)
end

.connectObject

Presence Management ===



27
28
29
# File 'lib/where_is_waldo.rb', line 27

def connect(...)
  PresenceService.connect(...)
end

.disconnectObject



31
32
33
# File 'lib/where_is_waldo.rb', line 31

def disconnect(...)
  PresenceService.disconnect(...)
end

.heartbeatObject



35
36
37
# File 'lib/where_is_waldo.rb', line 35

def heartbeat(...)
  PresenceService.heartbeat(...)
end

.online(scope, timeout: nil) ⇒ Object

Get online subjects from a scope

Examples:

WhereIsWaldo.online(org.members) => AR relation of online members



43
44
45
# File 'lib/where_is_waldo.rb', line 43

def online(scope, timeout: nil)
  PresenceService.online(scope, timeout: timeout)
end

.online_ids(scope, timeout: nil) ⇒ Object

Get online subject IDs from a scope

Examples:

WhereIsWaldo.online_ids(org.members.admin)



49
50
51
# File 'lib/where_is_waldo.rb', line 49

def online_ids(scope, timeout: nil)
  PresenceService.online_ids(scope, timeout: timeout)
end

.presence_on(subject_id, platform, timeout: nil) ⇒ Object

Presence status for a subject on a specific device/platform.

Examples:

WhereIsWaldo.presence_on(user.id, :mobile) # => "idle"



96
97
98
# File 'lib/where_is_waldo.rb', line 96

def presence_on(subject_id, platform, timeout: nil)
  Roster.device_status(subject_id, platform, timeout: timeout)
end

.publish_presence(subject_id, timeout: nil) ⇒ Object

Broadcast a compact presence delta for a subject to their org's roster stream. Call on transitions only (usually automatic via PresenceChannel).



102
103
104
# File 'lib/where_is_waldo.rb', line 102

def publish_presence(subject_id, timeout: nil)
  Roster.publish(subject_id, timeout: timeout)
end

.reset_configuration!Object



21
22
23
# File 'lib/where_is_waldo.rb', line 21

def reset_configuration!
  @configuration = Configuration.new
end

.roster_snapshot(org, timeout: nil) ⇒ Object

Full roster state for an org record (every member + current presence).



85
86
87
# File 'lib/where_is_waldo.rb', line 85

def roster_snapshot(org, timeout: nil)
  Roster.snapshot(org, timeout: timeout)
end

.roster_state_for(subject_id, timeout: nil) ⇒ Object

Aggregate presence state ({ status:, devices: }) for one subject.



90
91
92
# File 'lib/where_is_waldo.rb', line 90

def roster_state_for(subject_id, timeout: nil)
  Roster.state_for(subject_id, timeout: timeout)
end

.roster_stream_for(subject) ⇒ Object

Shared roster stream name for the org a subject belongs to.



107
108
109
# File 'lib/where_is_waldo.rb', line 107

def roster_stream_for(subject)
  Roster.stream_for_subject(subject)
end

.session_statusObject



74
75
76
# File 'lib/where_is_waldo.rb', line 74

def session_status(...)
  PresenceService.session_status(...)
end

.sessions_for_subjectObject



70
71
72
# File 'lib/where_is_waldo.rb', line 70

def sessions_for_subject(...)
  PresenceService.sessions_for_subject(...)
end

.subject_online?Boolean

NOTE: don't use ActiveSupport's delegate here. delegate generates the method via class_eval with a STRING, and a string-eval'd body's Module.nesting is just the target class — for a class << self inside module WhereIsWaldo, that's [#<Class:WhereIsWaldo>], WITHOUT WhereIsWaldo itself. Constant lookup for PresenceService inside the generated method then can't walk up to the enclosing module and raises uninitialized constant #<Class:WhereIsWaldo>::PresenceService. A plain def inherits the enclosing lexical nesting and resolves correctly.

Returns:

  • (Boolean)


66
67
68
# File 'lib/where_is_waldo.rb', line 66

def subject_online?(...)
  PresenceService.subject_online?(...)
end