Class: Events::Subscribers::TransientBroadcaster
- Inherits:
-
Object
- Object
- Events::Subscribers::TransientBroadcaster
- Includes:
- Events::Subscriber
- Defined in:
- lib/events/subscribers/transient_broadcaster.rb
Overview
Bridges transient (non-persisted) events to ActionCable so clients receive them over WebSocket. Persisted messages reach clients via Message::Broadcasting callbacks; this subscriber handles events that never touch the database.
Constant Summary collapse
- TRANSIENT_TYPES =
Event types that are broadcast without persistence.
[Events::BounceBack::TYPE].freeze
Instance Method Summary collapse
Instance Method Details
#emit(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/events/subscribers/transient_broadcaster.rb', line 19 def emit(event) payload = event[:payload] return unless payload.is_a?(Hash) event_type = payload[:type] return unless TRANSIENT_TYPES.include?(event_type) session_id = payload[:session_id] return unless session_id ActionCable.server.broadcast( "session_#{session_id}", payload.transform_keys(&:to_s) ) end |