Class: WebSocket::Protocol::Draft75
Constant Summary
STATES
Instance Attribute Summary
#protocol, #ready_state
Instance Method Summary
collapse
#binary, #close, jruby?, #onclose, #onerror, #onmessage, #onopen, #ping, rbx?, #start, #state, #text
Constructor Details
#initialize(socket, options = {}) ⇒ Draft75
Returns a new instance of Draft75.
5
6
7
8
|
# File 'lib/websocket/protocol/draft75.rb', line 5
def initialize(socket, options = {})
super
@stage = 0
end
|
Instance Method Details
#frame(data, type = nil, error_type = nil) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/websocket/protocol/draft75.rb', line 57
def frame(data, type = nil, error_type = nil)
return queue([data, type, error_type]) if @ready_state == 0
data = Protocol.encode(data)
frame = ["\x00", data, "\xFF"].map(&Protocol.method(:encode)) * ''
@socket.write(frame)
true
end
|
#parse(buffer) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/websocket/protocol/draft75.rb', line 14
def parse(buffer)
buffer = buffer.bytes if buffer.respond_to?(:bytes)
buffer.each do |data|
case @stage
when -1 then
@head << data
send_handshake_body
when 0 then
parse_leading_byte(data)
when 1 then
value = (data & 0x7F)
@length = value + 128 * @length
if @closing and @length.zero?
@ready_state = 3
dispatch(:onclose, CloseEvent.new(nil, nil))
elsif (0x80 & data) != 0x80
if @length.zero?
dispatch(:onmessage, MessageEvent.new(''))
@stage = 0
else
@buffer = []
@stage = 2
end
end
when 2 then
if data == 0xFF
dispatch(:onmessage, MessageEvent.new(Protocol.encode(@buffer)))
@stage = 0
else
@buffer << data
if @length and @buffer.size == @length
@stage = 0
end
end
end
end
end
|
#version ⇒ Object
10
11
12
|
# File 'lib/websocket/protocol/draft75.rb', line 10
def version
'hixie-75'
end
|