Class: Rage::SSE::Stream
- Inherits:
-
Object
- Object
- Rage::SSE::Stream
- Defined in:
- lib/rage/sse/stream.rb
Overview
The class representing an unbounded Server-Sent Events stream. It allows for broadcasting messages to all connected clients subscribed to the stream.
Create a stream:
render sse: Rage::SSE.stream([current_user, "notifications"])
Broadcast a message to all connections subscribed to the stream:
Rage::SSE.broadcast([current_user, "notifications"], "You have a new notification!")
Close the stream:
Rage::SSE.close_stream([current_user, "notifications"])
Messages to known streams are buffered until a connection is fully established:
# Create a stream first
stream = Rage::SSE.stream([current_user, "notifications"])
# No connection yet, but the message is buffered
Rage::SSE.broadcast([current_user, "notifications"], "You have a new notification!")
# Establish a connection, which will claim the buffered message
render sse: stream
Instance Method Summary collapse
-
#initialize(streamable:) ⇒ Stream
constructor
A new instance of Stream.