Class: WebSocket::Driver::Server
- Inherits:
-
WebSocket::Driver
- Object
- WebSocket::Driver
- WebSocket::Driver::Server
- Defined in:
- lib/websocket/driver/server.rb
Constant Summary collapse
- EVENTS =
%w[open message error close]
Constants inherited from WebSocket::Driver
BINARY, ConfigurationError, MAX_LENGTH, ProtocolError, STATES, UNICODE, URIError
Instance Attribute Summary
Attributes inherited from WebSocket::Driver
Instance Method Summary collapse
- #env ⇒ Object
-
#initialize(socket, options = {}) ⇒ Server
constructor
A new instance of Server.
- #parse(chunk) ⇒ Object
- #url ⇒ Object
- #write(buffer) ⇒ Object
Methods inherited from WebSocket::Driver
#add_extension, #binary, #close, #ping, #pong, #set_header, #start, #state, #text
Methods included from EventEmitter
#add_listener, #emit, #listener_count, #listeners, #on, #remove_all_listeners, #remove_listener
Constructor Details
Instance Method Details
#env ⇒ Object
13 14 15 |
# File 'lib/websocket/driver/server.rb', line 13 def env @http.complete? ? @http.env : nil end |
#parse(chunk) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/websocket/driver/server.rb', line 43 def parse(chunk) return @delegate.parse(chunk) if @delegate @http.parse(chunk) return fail_request('Invalid HTTP request') if @http.error? return unless @http.complete? @delegate = Driver.rack(self, @options) open EVENTS.each do |event| @delegate.on(event) { |e| emit(event, e) } end emit(:connect, ConnectEvent.new) end |
#url ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/websocket/driver/server.rb', line 17 def url return nil unless e = env url = "ws://#{e['HTTP_HOST']}" url << e['PATH_INFO'] url << "?#{e['QUERY_STRING']}" unless e['QUERY_STRING'] == '' url end |
#write(buffer) ⇒ Object
60 61 62 |
# File 'lib/websocket/driver/server.rb', line 60 def write(buffer) @socket.write(buffer) end |