Class: EventSourceController

Inherits:
ApplicationController
  • Object
show all
Includes:
ActionController::Live, ActiveEvent::EventSourceServer
Defined in:
lib/generators/drails/app/templates/event_source_controller.rb

Instance Method Summary collapse

Instance Method Details

#streamObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/generators/drails/app/templates/event_source_controller.rb', line 5

def stream
  event_connection.start
  response.headers['Content-Type'] = 'text/event-stream'
  sse = ActiveEvent::SSE.new(response.stream)
  subscribe_to event_queue do |delivery_info, properties, body|
    sse.write({:id => body}, :event => 'refresh')
  end
rescue IOError
ensure
  sse.close
end