Class: Rack::SockJS

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/sockjs.rb

Defined Under Namespace

Classes: DebugRequest, ExtractServerAndSession, MissingHandler, RenderErrors, ResetScriptName

Constant Summary collapse

SERVER_SESSION_REGEXP =
%r{/([^/]*)/([^/]*)}
DEFAULT_OPTIONS =
{
  :sockjs_url => "http://cdn.sockjs.org/sockjs-#{::SockJS::PROTOCOL_VERSION}.min.js"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_class, options = nil) ⇒ SockJS

Returns a new instance of SockJS.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rack/sockjs.rb', line 144

def initialize(session_class, options = nil)
  #TODO refactor Connection to App
  connection = ::SockJS::Connection.new(session_class, options)

  options ||= {}

  options = DEFAULT_OPTIONS.merge(options)

  @routing = Rack::Mount::RouteSet.new do |set|
    ::SockJS::Endpoint.add_routes(set, connection, options)

    set.add_route(MissingHandler.new(options), {}, {}, :missing)
  end

  routing = @routing

  @app = Rack::Builder.new do
    use Rack::SockJS::ResetScriptName
    use DebugRequest
    run routing
  end.to_app
end

Instance Attribute Details

#routingObject (readonly)

Returns the value of attribute routing.



167
168
169
# File 'lib/rack/sockjs.rb', line 167

def routing
  @routing
end

Instance Method Details

#call(env) ⇒ Object



169
170
171
# File 'lib/rack/sockjs.rb', line 169

def call(env)
  @app.call(env)
end