Class: TurboCable::RackHandler
- Inherits:
-
Object
- Object
- TurboCable::RackHandler
- Defined in:
- lib/turbo_cable/rack_handler.rb
Overview
Rack middleware for handling WebSocket connections using Rack hijack Uses RFC 6455 WebSocket protocol (no dependencies required)
Constant Summary collapse
- GUID =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RackHandler
constructor
A new instance of RackHandler.
Constructor Details
#initialize(app) ⇒ RackHandler
Returns a new instance of RackHandler.
11 12 13 14 15 |
# File 'lib/turbo_cable/rack_handler.rb', line 11 def initialize(app) @app = app @connections = {} # stream => [sockets] @mutex = Mutex.new end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/turbo_cable/rack_handler.rb', line 17 def call(env) # Handle WebSocket upgrade for /cable if env["PATH_INFO"] == "/cable" && websocket_request?(env) handle_websocket(env) # Return -1 to indicate we've hijacked the connection [ -1, {}, [] ] elsif env["PATH_INFO"] == "/_broadcast" && env["REQUEST_METHOD"] == "POST" handle_broadcast(env) else @app.call(env) end end |