Module: Roda::RodaPlugins::Websockets::RequestMethods
- Defined in:
- lib/roda/plugins/websockets.rb
Instance Method Summary collapse
-
#websocket(opts = OPTS) ⇒ Object
If the request is a websocket request, yield a websocket to the block, and return the appropriate rack response after the block returns.
-
#websocket? ⇒ Boolean
True if this request is a websocket request, false otherwise.
Instance Method Details
#websocket(opts = OPTS) ⇒ Object
If the request is a websocket request, yield a websocket to the block, and return the appropriate rack response after the block returns. opts is an options hash used when creating the websocket, except the following options are handled specially:
- :protocols
-
Set the protocols to accept, should be an array of strings.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/roda/plugins/websockets.rb', line 92 def websocket(opts=OPTS) if websocket? always do opts = Hash[roda_class.opts[:websockets_opts]].merge!(opts) ws = WebSocket.new(env, opts.delete(:protocols), opts) yield ws halt ws.rack_response end end end |
#websocket? ⇒ Boolean
True if this request is a websocket request, false otherwise.
81 82 83 |
# File 'lib/roda/plugins/websockets.rb', line 81 def websocket? WebSocket.websocket?(env) end |