Class: Jugglite::App
- Inherits:
-
Object
- Object
- Jugglite::App
- Defined in:
- lib/jugglite/app.rb
Overview
Let’s go for plain Rack y’all
Constant Summary collapse
- AsyncResponse =
[-1, {}, []].freeze
- Headers =
{ 'Content-Type' => 'text/event-stream;charset=utf-8', 'Cache-Control' => 'no-cache' # IE (through the Polyfill) will trip without this }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app = nil, options = {}) ⇒ App
constructor
Options include:
path
: the URI path to listen to (‘/stream’)keepalive_timeout
: the timeout in seconds between keepalive comments.
Constructor Details
#initialize(app = nil, options = {}) ⇒ App
Options include: path
: the URI path to listen to (‘/stream’) keepalive_timeout
: the timeout in seconds between keepalive comments
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jugglite/app.rb', line 16 def initialize(app = nil, = {}) @app = app @options = { path: '/stream', namespace: '', keepalive_timeout: 20 }.merge() @subscription_map = {} EventMachine::next_tick { setup_redis } EventMachine::next_tick { setup_keepalive } end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/jugglite/app.rb', line 28 def call(env) if @app.nil? || (env["PATH_INFO"] == @options[:path]) handle_stream(env) else # Running as middleware and path did not match so pass it along @app.call(env) end end |