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.
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 and broadcasts the payload to the session’s Action Cable stream.
Instance Method Details
#emit(event) ⇒ Object
Receives a Rails.event notification hash and broadcasts the payload to the session’s Action Cable stream.
24 25 26 27 28 29 30 31 32 |
# File 'lib/events/subscribers/action_cable_bridge.rb', line 24 def emit(event) payload = event[:payload] return unless payload.is_a?(Hash) session_id = payload[:session_id] return if session_id.nil? ActionCable.server.broadcast("session_#{session_id}", payload) end |