Module: Event::Broadcasting

Extended by:
ActiveSupport::Concern
Included in:
Event
Defined in:
app/models/concerns/event/broadcasting.rb

Overview

Broadcasts Event records to connected WebSocket clients via ActionCable. Follows the Turbo Streams pattern: events are broadcast on both create and update, with an action type so clients can distinguish append from replace operations.

Each broadcast includes the Event’s database ID, enabling clients to maintain an ID-indexed store for efficient in-place updates (e.g. when token counts arrive asynchronously from CountEventTokensJob).

Examples:

Create broadcast payload

{
  "type" => "user_message", "content" => "hello", ...,
  "id" => 42, "action" => "create",
  "rendered" => { "basic" => { "role" => "user", "content" => "hello" } }
}

Update broadcast payload (e.g. token count arrives)

{
  "type" => "user_message", "content" => "hello", ...,
  "id" => 42, "action" => "update",
  "rendered" => { "debug" => { "role" => "user", "content" => "hello", "tokens" => 15 } }
}

Constant Summary collapse

ACTION_CREATE =
"create"
ACTION_UPDATE =
"update"