Class: Events::Subscribers::ActionCableBridge
- Inherits:
-
Object
- Object
- Events::Subscribers::ActionCableBridge
- Includes:
- Events::Subscriber, Singleton
- Defined in:
- lib/events/subscribers/action_cable_bridge.rb
Overview
Forwards EventBus events to Action Cable, bridging internal pub/sub to external WebSocket clients. Each event is broadcast to the session-specific stream (e.g. “session_42”), matching the stream name used by SessionChannel.
Events are decorated via EventDecorator before broadcast, adding structured data for the session’s current view mode. The TUI receives semantic hashes (role, content, timestamp) and never loads Draper.
Only events with a valid session_id are broadcast — events without one have no destination channel and are silently skipped.
Instance Method Summary collapse
-
#emit(event) ⇒ Object
Receives a Rails.event notification hash, decorates the payload with rendered output, and broadcasts to the session’s Action Cable stream.
Instance Method Details
#emit(event) ⇒ Object
Receives a Rails.event notification hash, decorates the payload with rendered output, and broadcasts to the session’s Action Cable stream. Loads the session to determine the current view_mode for decoration.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/events/subscribers/action_cable_bridge.rb', line 29 def emit(event) payload = event[:payload] return unless payload.is_a?(Hash) session_id = payload[:session_id] return if session_id.nil? mode = session_view_mode(session_id) ActionCable.server.broadcast("session_#{session_id}", decorate_payload(payload, mode)) end |