class

Freshen::Broker

Inherits Reference < Object

Thread-safe pub/sub Server-Sent Events (SSE) stream broker. Manages active client stream connections, concurrent non-blocking broadcasts, dead socket pruning, and periodic keep-alive heartbeats.

Constructors

new(heartbeat_interval : Time::Span = 15.seconds)
Source

Instance methods

active_client_count

Returns the count of currently registered active clients.

Source
broadcast(event : Event) : Nil

Broadcasts a structured SSE Event payload to all connected clients.

Source
broadcast_raw(payload : String) : Nil

Broadcasts a raw SSE payload string to all connected clients concurrently.

Source
close

Shuts down the broker and clears all active connections.

Source
heartbeat_interval
Source
register_client(id : String, stream : IO) : Nil

Registers an IO stream with an explicit client identifier.

Source
running?
Source
subscribe(stream : IO, id : String = UUID.v4.to_s) : String

Subscribes an IO stream with an auto-generated or explicit client identifier.

Source
unregister(id : String) : Nil

Unregisters an active client upon disconnection.

Source
unregister_client(id : String) : Nil

Alias for unregister.

Source