Class: Rack::Stream::Handlers::EventSource

Inherits:
AbstractHandler show all
Defined in:
lib/rack/stream/handlers/event_source.rb

Overview

Handler to stream to EventSource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractHandler

#chunk, #initialize

Constructor Details

This class inherits a constructor from Rack::Stream::Handlers::AbstractHandler

Class Method Details

.accepts?(app) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/rack/stream/handlers/event_source.rb', line 6

def self.accepts?(app)
  ::Faye::EventSource.eventsource?(app.env)
end

Instance Method Details

#closeObject

TODO: browser initiates connection again, isn't closed



11
12
13
14
15
# File 'lib/rack/stream/handlers/event_source.rb', line 11

def close
  @body.callback {
    @es.close
  }
end

#openObject



17
18
19
20
21
22
# File 'lib/rack/stream/handlers/event_source.rb', line 17

def open
  @es = ::Faye::EventSource.new(@app.env)
  @es.onopen = lambda do |event|
    @body.each {|c| @es.send(c)}
  end
end