Class: Xeno::StreamsController::SseWriter
- Inherits:
-
Object
- Object
- Xeno::StreamsController::SseWriter
- Defined in:
- app/controllers/xeno/streams_controller.rb
Overview
SSE framing: id:/event: headers per frame, comment keepalives.
Instance Method Summary collapse
- #close ⇒ Object
- #content_type ⇒ Object
- #event(record) ⇒ Object
-
#initialize(stream) ⇒ SseWriter
constructor
A new instance of SseWriter.
- #keepalive ⇒ Object
Constructor Details
#initialize(stream) ⇒ SseWriter
Returns a new instance of SseWriter.
18 19 20 21 |
# File 'app/controllers/xeno/streams_controller.rb', line 18 def initialize(stream) @stream = stream @sse = ActionController::Live::SSE.new(stream) end |
Instance Method Details
#close ⇒ Object
26 |
# File 'app/controllers/xeno/streams_controller.rb', line 26 def close = @sse.close |
#content_type ⇒ Object
23 |
# File 'app/controllers/xeno/streams_controller.rb', line 23 def content_type = "text/event-stream" |
#event(record) ⇒ Object
24 |
# File 'app/controllers/xeno/streams_controller.rb', line 24 def event(record) = @sse.write(record.envelope, event: record.event_type, id: record.index) |
#keepalive ⇒ Object
25 |
# File 'app/controllers/xeno/streams_controller.rb', line 25 def keepalive = @stream.write(": keepalive\n\n") |