Class: Rack::WebSocket::Handler::Thin

Inherits:
Base
  • Object
show all
Defined in:
lib/rack/websocket/handler/thin.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #on_close, #on_error, #on_message, #on_open

Constructor Details

This class inherits a constructor from Rack::WebSocket::Handler::Base

Instance Method Details

#call(env) ⇒ Object

Build request from Rack env



9
10
11
12
13
14
15
# File 'lib/rack/websocket/handler/thin.rb', line 9

def call(env)
  @env = env
  socket = env['async.connection']
  request = request_from_env(env)
  @connection = Connection.new(self, socket, :debug => @options[:debug])
  @connection.dispatch(request) ? async_response : failure_response
end

#close_websocketObject

Forward close_websocket to server



27
28
29
30
31
32
33
# File 'lib/rack/websocket/handler/thin.rb', line 27

def close_websocket
  if @connection
    @connection.close_websocket
  else
    raise WebSocketError, "WebSocket not opened"
  end
end

#send_data(data) ⇒ Object

Forward send_data to server



18
19
20
21
22
23
24
# File 'lib/rack/websocket/handler/thin.rb', line 18

def send_data(data)
  if @connection
    @connection.send data
  else
    raise WebSocketError, "WebSocket not opened"
  end
end