Class: Xeno::StreamsController::SseWriter

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/xeno/streams_controller.rb

Overview

SSE framing: id:/event: headers per frame, comment keepalives.

Instance Method Summary collapse

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

#closeObject



26
# File 'app/controllers/xeno/streams_controller.rb', line 26

def close = @sse.close

#content_typeObject



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)

#keepaliveObject



25
# File 'app/controllers/xeno/streams_controller.rb', line 25

def keepalive = @stream.write(": keepalive\n\n")