Class: Jugglite::App

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(app = nil, options = {}) ⇒ App

Options include: path : the URI path to listen to (defaults to ‘/stream’) keepalive_timeout : the timeout in seconds between keepalive comments (defaults to 20) namespace : a namespace used as prefix for redis pubsub channels allowed_channels :

* an array with allowed channel names
* a proc that takes a Rack::Request and returns an array of allowed channels for that particular request


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jugglite/app.rb', line 20

def initialize(app = nil, options = {})
  @app = app
  @options = {
    path: '/stream',
    namespace: '',
    keepalive_timeout: 20
  }.merge(options)
  @subscription_map = {}
  EventMachine::next_tick { setup_redis }
  EventMachine::next_tick { setup_keepalive }
end

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/jugglite/app.rb', line 32

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