Class: Pubsubstub::StreamAction
- Inherits:
-
Object
- Object
- Pubsubstub::StreamAction
- Includes:
- Logging
- Defined in:
- lib/pubsubstub/stream_action.rb
Constant Summary collapse
- HEADERS =
{ 'Content-Type' => 'text/event-stream', 'Cache-Control' => 'no-cache', 'X-Accel-Buffering' => 'no', 'Connection' => 'keep-alive', }.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ StreamAction
constructor
A new instance of StreamAction.
Methods included from Logging
Constructor Details
#initialize ⇒ StreamAction
Returns a new instance of StreamAction.
11 12 13 14 |
# File 'lib/pubsubstub/stream_action.rb', line 11 def initialize(*) @subscriptions = Set.new @mutex = Mutex.new end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pubsubstub/stream_action.rb', line 16 def call(env) spawn_helper_threads last_event_id = env['HTTP_LAST_EVENT_ID'] request = Rack::Request.new(env) channels = (request.params['channels'] || [:default]).map(&Channel.method(:new)) stream = if use_persistent_connections? subscribe_connection(channels, last_event_id) else send_scrollback(channels, last_event_id) end [200, HEADERS.dup, stream] end |