Class: Events::Subscribers::SessionStateBroadcaster
- Inherits:
-
Object
- Object
- Events::Subscribers::SessionStateBroadcaster
- Includes:
- Events::Subscriber
- Defined in:
- lib/events/subscribers/session_state_broadcaster.rb
Overview
Broadcasts session state over ActionCable in response to Events::SessionStateChanged. Sends session_state to the session stream and, for sub-agents, child_state to the parent stream so the HUD updates without a full children refresh.
Instance Method Summary collapse
Instance Method Details
#emit(event) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/events/subscribers/session_state_broadcaster.rb', line 17 def emit(event) payload = event[:payload] session_id = payload[:session_id] state = payload[:state] action_payload = {"action" => "session_state", "state" => state, "session_id" => session_id} ActionCable.server.broadcast("session_#{session_id}", action_payload) parent_id = Session.where(id: session_id).pick(:parent_session_id) return unless parent_id parent_payload = action_payload.merge("action" => "child_state", "child_id" => session_id) ActionCable.server.broadcast("session_#{parent_id}", parent_payload) end |