Class: Terminalwire::V2::Rails::Dispatcher
- Inherits:
-
Object
- Object
- Terminalwire::V2::Rails::Dispatcher
- Defined in:
- lib/terminalwire/v2/rails.rb
Overview
Routes a WebSocket upgrade to the v1 or v2 handler by inspecting the advertised subprotocol on the Rack env — no socket is accepted until the branch is chosen, so a connection only ever reaches one handler.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(v1:, v2:) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(v1:, v2:) ⇒ Dispatcher
Returns a new instance of Dispatcher.
275 276 277 278 |
# File 'lib/terminalwire/v2/rails.rb', line 275 def initialize(v1:, v2:) @v1 = v1 @v2 = v2 end |
Instance Method Details
#call(env) ⇒ Object
280 281 282 283 |
# File 'lib/terminalwire/v2/rails.rb', line 280 def call(env) protos = env["HTTP_SEC_WEBSOCKET_PROTOCOL"].to_s.split(/,\s*/) (protos.include?(SUBPROTOCOL) ? @v2 : @v1).call(env) end |