Class: Volt::WebsocketHandler
- Defined in:
- lib/volt/server/websocket/websocket_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ WebsocketHandler
constructor
A new instance of WebsocketHandler.
Constructor Details
#initialize(app) ⇒ WebsocketHandler
Returns a new instance of WebsocketHandler.
7 8 9 |
# File 'lib/volt/server/websocket/websocket_handler.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/volt/server/websocket/websocket_handler.rb', line 11 def call(env) if Faye::WebSocket.websocket?(env) ws = Faye::WebSocket.new(env) socket_connection_handler = SocketConnectionHandler.new(ws) ws.on :message do |event| socket_connection_handler.(event.data) end ws.on :close do |event| socket_connection_handler.closed ws = nil end # Return async Rack response ws.rack_response else # Call down to the app @app.call(env) end end |