Class: WebSocket::Driver::Draft76
- Inherits:
-
Draft75
- Object
- WebSocket::Driver
- Draft75
- WebSocket::Driver::Draft76
- Defined in:
- lib/websocket/driver/draft76.rb
Constant Summary collapse
- BODY_SIZE =
8
Constants inherited from WebSocket::Driver
ConfigurationError, MAX_LENGTH, PORTS, ProtocolError, STATES, URIError
Instance Attribute Summary
Attributes inherited from WebSocket::Driver
Instance Method Summary collapse
- #close(reason = nil, code = nil) ⇒ Object
-
#initialize(socket, options = {}) ⇒ Draft76
constructor
A new instance of Draft76.
- #start ⇒ Object
- #version ⇒ Object
Methods inherited from Draft75
Methods inherited from WebSocket::Driver
#add_extension, #binary, #ping, #pong, #set_header, #state, #text
Methods included from EventEmitter
#add_listener, #emit, #listener_count, #listeners, #on, #remove_all_listeners, #remove_listener
Constructor Details
#initialize(socket, options = {}) ⇒ Draft76
Returns a new instance of Draft76.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/websocket/driver/draft76.rb', line 7 def initialize(socket, = {}) super input = (@socket.env['rack.input'] || StringIO.new('')).read input = input.dup if input.frozen? @stage = -1 @body = input.force_encoding(Encoding::BINARY) @headers.clear @headers['Upgrade'] = 'WebSocket' @headers['Connection'] = 'Upgrade' @headers['Sec-WebSocket-Origin'] = @socket.env['HTTP_ORIGIN'] @headers['Sec-WebSocket-Location'] = @socket.url end |
Instance Method Details
#close(reason = nil, code = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/websocket/driver/draft76.rb', line 31 def close(reason = nil, code = nil) return false if @ready_state == 3 @socket.write([0xFF, 0x00].pack('C*')) if @ready_state == 1 @ready_state = 3 emit(:close, CloseEvent.new(nil, nil)) true end |
#start ⇒ Object
25 26 27 28 29 |
# File 'lib/websocket/driver/draft76.rb', line 25 def start return false unless super send_handshake_body true end |
#version ⇒ Object
21 22 23 |
# File 'lib/websocket/driver/draft76.rb', line 21 def version 'hixie-76' end |