Module: Padrino::WebSockets::Faye::Routing
- Defined in:
- lib/padrino-websockets/faye/routing.rb
Instance Method Summary collapse
-
#websocket(channel, *args, &block) ⇒ Object
(also: #ws)
Creates a WebSocket endpoint using SpiderGazelle + libuv.
Instance Method Details
#websocket(channel, *args, &block) ⇒ Object Also known as: ws
Creates a WebSocket endpoint using SpiderGazelle + libuv.
It handles upgrading the HTTP connection for you. You can nest this inside controllers as you would do with regular actions in Padrino.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/padrino-websockets/faye/routing.rb', line 13 def websocket(channel, *args, &block) get channel, *args do # Let some other action try to handle the request if it's not a WebSocket. throw :pass unless ::Faye::WebSocket.websocket?(request.env) set_websocket_user ws = ::Faye::WebSocket.new(env, nil, {ping: 15}) Padrino::WebSockets::Faye::EventManager.new(params[:channel] || channel, session['websocket_user'], ws, self, &block) ws.rack_response end end |