Class: WhereIsWaldo::PresenceService
- Inherits:
-
Object
- Object
- WhereIsWaldo::PresenceService
- Defined in:
- app/services/where_is_waldo/presence_service.rb
Class Method Summary collapse
-
.all_online_ids(timeout: nil) ⇒ Array<Integer>
Get all online subject IDs (no scope filtering).
-
.cleanup(timeout: nil) ⇒ Integer
Cleanup stale records.
-
.connect(session_id:, subject_id:, metadata: {}) ⇒ Boolean
Register a new presence.
-
.disconnect(session_id: nil, subject_id: nil) ⇒ Boolean
Remove a presence by session, or all presences for a subject.
-
.heartbeat(session_id:, tab_visible: true, subject_active: true, last_activity_at: nil, metadata: {}) ⇒ Boolean
Update heartbeat for a session.
-
.online(scope, timeout: nil) ⇒ ActiveRecord::Relation
Get online subjects from an AR scope.
-
.online_ids(scope, timeout: nil) ⇒ Array<Integer>
Get online subject IDs from an AR scope.
-
.session_status ⇒ Hash?
Get status of a specific session.
-
.sessions_for_subject ⇒ Array<Hash>
Get all sessions for a subject.
-
.subject_online?(subject_id) ⇒ Boolean
Check if a subject is online.
Class Method Details
.all_online_ids(timeout: nil) ⇒ Array<Integer>
Get all online subject IDs (no scope filtering)
68 69 70 |
# File 'app/services/where_is_waldo/presence_service.rb', line 68 def all_online_ids(timeout: nil) adapter.online_subject_ids(timeout: timeout) end |
.cleanup(timeout: nil) ⇒ Integer
Cleanup stale records
92 93 94 |
# File 'app/services/where_is_waldo/presence_service.rb', line 92 def cleanup(timeout: nil) adapter.cleanup(timeout: timeout) end |
.connect(session_id:, subject_id:, metadata: {}) ⇒ Boolean
Register a new presence
11 12 13 14 15 16 17 |
# File 'app/services/where_is_waldo/presence_service.rb', line 11 def connect(session_id:, subject_id:, metadata: {}) adapter.connect( session_id: session_id, subject_id: subject_id, metadata: ) end |
.disconnect(session_id: nil, subject_id: nil) ⇒ Boolean
Remove a presence by session, or all presences for a subject
23 24 25 26 27 28 |
# File 'app/services/where_is_waldo/presence_service.rb', line 23 def disconnect(session_id: nil, subject_id: nil) adapter.disconnect( session_id: session_id, subject_id: subject_id ) end |
.heartbeat(session_id:, tab_visible: true, subject_active: true, last_activity_at: nil, metadata: {}) ⇒ Boolean
Update heartbeat for a session
37 38 39 40 41 42 43 44 45 |
# File 'app/services/where_is_waldo/presence_service.rb', line 37 def heartbeat(session_id:, tab_visible: true, subject_active: true, last_activity_at: nil, metadata: {}) adapter.heartbeat( session_id: session_id, tab_visible: tab_visible, subject_active: subject_active, last_activity_at: last_activity_at, metadata: ) end |
.online(scope, timeout: nil) ⇒ ActiveRecord::Relation
Get online subjects from an AR scope
51 52 53 54 |
# File 'app/services/where_is_waldo/presence_service.rb', line 51 def online(scope, timeout: nil) online_ids = adapter.online_subject_ids(timeout: timeout) scope.where(id: online_ids) end |
.online_ids(scope, timeout: nil) ⇒ Array<Integer>
Get online subject IDs from an AR scope
60 61 62 63 |
# File 'app/services/where_is_waldo/presence_service.rb', line 60 def online_ids(scope, timeout: nil) online_ids = adapter.online_subject_ids(timeout: timeout) scope.where(id: online_ids).pluck(:id) end |
.session_status ⇒ Hash?
Get status of a specific session
80 |
# File 'app/services/where_is_waldo/presence_service.rb', line 80 delegate :session_status, to: :adapter |
.sessions_for_subject ⇒ Array<Hash>
Get all sessions for a subject
75 |
# File 'app/services/where_is_waldo/presence_service.rb', line 75 delegate :sessions_for_subject, to: :adapter |
.subject_online?(subject_id) ⇒ Boolean
Check if a subject is online
85 86 87 |
# File 'app/services/where_is_waldo/presence_service.rb', line 85 def subject_online?(subject_id) sessions_for_subject(subject_id).any? end |