Module: Rage::SSE
- Defined in:
- lib/rage/sse/sse.rb
Defined Under Namespace
Classes: ConnectionProxy, Message, Stream
Class Method Summary collapse
-
.broadcast(streamable, data) ⇒ Object
Broadcast a message to all clients subscribed to a given stream.
-
.close_stream(streamable) ⇒ Object
Close an unbounded SSE stream.
-
.message(data, id: nil, event: nil, retry: nil) ⇒ Message
A factory method for creating Server-Sent Events.
-
.stream(streamable) ⇒ Stream
A factory method for creating unbounded SSE streams.
Class Method Details
.broadcast(streamable, data) ⇒ Object
Broadcast a message to all clients subscribed to a given stream.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rage/sse/sse.rb', line 75 def self.broadcast(streamable, data) Rage::Telemetry.tracer.span_sse_stream_broadcast(stream: streamable) do stream_name = Rage::Internal.stream_name_for(streamable) serialized_data = __serialize(data) InternalBroadcast.broadcast(stream_name, serialized_data, Iodine::PubSub::CLUSTER) if Iodine.running? @__adapter&.publish(PUBSUB_BROADCASTER_ID, stream_name, serialized_data) end true end |
.close_stream(streamable) ⇒ Object
Close an unbounded SSE stream. Unbounded streams will remain open until either the client disconnects or the server explicitly closes them.
58 59 60 61 62 63 64 65 |
# File 'lib/rage/sse/sse.rb', line 58 def self.close_stream(streamable) stream_name = Rage::Internal.stream_name_for(streamable) InternalBroadcast.broadcast(stream_name, CLOSE_STREAM_MSG, Iodine::PubSub::CLUSTER) if Iodine.running? @__adapter&.publish(PUBSUB_BROADCASTER_ID, stream_name, CLOSE_STREAM_MSG) true end |