Class: Events::Subscribers::TransientBroadcaster

Inherits:
Object
  • Object
show all
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 events reach clients via Event::Broadcasting callbacks; this subscriber handles events that never touch the database.

Examples:

Registering at boot

Events::Bus.subscribe(Events::Subscribers::TransientBroadcaster.new)

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

Parameters:

  • event (Hash)

    Rails.event notification hash



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