websocket-driver 0.2.0-java → 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/websocket/driver.rb +19 -11
- data/lib/websocket/driver/client.rb +1 -1
- data/lib/websocket/driver/draft75.rb +3 -4
- data/lib/websocket/driver/draft76.rb +2 -2
- data/lib/websocket/driver/hybi.rb +10 -8
- data/lib/websocket/driver/server.rb +1 -1
- metadata +26 -28
data/CHANGELOG.md
CHANGED
data/lib/websocket/driver.rb
CHANGED
@@ -78,7 +78,7 @@ module WebSocket
|
|
78
78
|
|
79
79
|
def start
|
80
80
|
return false unless @ready_state == 0
|
81
|
-
@socket.write(handshake_response)
|
81
|
+
@socket.write(Driver.encode(handshake_response, :binary))
|
82
82
|
open unless @stage == -1
|
83
83
|
true
|
84
84
|
end
|
@@ -116,14 +116,6 @@ module WebSocket
|
|
116
116
|
true
|
117
117
|
end
|
118
118
|
|
119
|
-
def self.encode(string, validate_encoding = false)
|
120
|
-
if Array === string
|
121
|
-
string = utf8_string(string)
|
122
|
-
return nil if validate_encoding and !valid_utf8?(string)
|
123
|
-
end
|
124
|
-
utf8_string(string)
|
125
|
-
end
|
126
|
-
|
127
119
|
def self.client(socket, options = {})
|
128
120
|
Client.new(socket, options.merge(:masking => true))
|
129
121
|
end
|
@@ -143,6 +135,23 @@ module WebSocket
|
|
143
135
|
end
|
144
136
|
end
|
145
137
|
|
138
|
+
def self.encode(string, encoding = nil)
|
139
|
+
if Array === string
|
140
|
+
string = string.pack('C*')
|
141
|
+
encoding ||= :binary
|
142
|
+
else
|
143
|
+
encoding ||= :utf8
|
144
|
+
end
|
145
|
+
case encoding
|
146
|
+
when :binary
|
147
|
+
string.force_encoding('ASCII-8BIT') if string.respond_to?(:force_encoding)
|
148
|
+
when :utf8
|
149
|
+
string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
|
150
|
+
return nil unless valid_utf8?(string)
|
151
|
+
end
|
152
|
+
string
|
153
|
+
end
|
154
|
+
|
146
155
|
def self.utf8_string(string)
|
147
156
|
string = string.pack('C*') if Array === string
|
148
157
|
string.respond_to?(:force_encoding) ?
|
@@ -150,8 +159,7 @@ module WebSocket
|
|
150
159
|
string
|
151
160
|
end
|
152
161
|
|
153
|
-
def self.valid_utf8?(
|
154
|
-
string = utf8_string(byte_array)
|
162
|
+
def self.valid_utf8?(string)
|
155
163
|
if defined?(UTF8_MATCH)
|
156
164
|
UTF8_MATCH =~ string ? true : false
|
157
165
|
else
|
@@ -41,7 +41,7 @@ module WebSocket
|
|
41
41
|
|
42
42
|
when 2 then
|
43
43
|
if data == 0xFF
|
44
|
-
emit(:message, MessageEvent.new(Driver.encode(@buffer)))
|
44
|
+
emit(:message, MessageEvent.new(Driver.encode(@buffer, :utf8)))
|
45
45
|
@stage = 0
|
46
46
|
else
|
47
47
|
if @length
|
@@ -57,9 +57,8 @@ module WebSocket
|
|
57
57
|
|
58
58
|
def frame(data, type = nil, error_type = nil)
|
59
59
|
return queue([data, type, error_type]) if @ready_state == 0
|
60
|
-
|
61
|
-
|
62
|
-
@socket.write(frame)
|
60
|
+
frame = ["\x00", data, "\xFF"].map { |s| Driver.encode(s, :binary) } * ''
|
61
|
+
@socket.write(Driver.encode(frame, :binary))
|
63
62
|
true
|
64
63
|
end
|
65
64
|
|
@@ -23,7 +23,7 @@ module WebSocket
|
|
23
23
|
|
24
24
|
def close(reason = nil, code = nil)
|
25
25
|
return false if @ready_state == 3
|
26
|
-
@socket.write("\xFF\x00")
|
26
|
+
@socket.write(Driver.encode("\xFF\x00", :binary))
|
27
27
|
@ready_state = 3
|
28
28
|
emit(:close, CloseEvent.new(nil, nil))
|
29
29
|
true
|
@@ -63,7 +63,7 @@ module WebSocket
|
|
63
63
|
|
64
64
|
def send_handshake_body
|
65
65
|
return unless signature = handshake_signature
|
66
|
-
@socket.write(signature)
|
66
|
+
@socket.write(Driver.encode(signature, :binary))
|
67
67
|
@stage = 0
|
68
68
|
open
|
69
69
|
parse(@body[BODY_SIZE..-1]) if @body.size > BODY_SIZE
|
@@ -103,11 +103,11 @@ module WebSocket
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def frame(data, type = nil, code = nil)
|
106
|
-
return queue([data, type, code]) if @ready_state
|
106
|
+
return queue([data, type, code]) if @ready_state <= 0
|
107
107
|
return false unless @ready_state == 1
|
108
108
|
|
109
109
|
data = data.to_s unless Array === data
|
110
|
-
data = Driver.encode(data) if String === data
|
110
|
+
data = Driver.encode(data, :utf8) if String === data
|
111
111
|
|
112
112
|
is_text = (String === data)
|
113
113
|
opcode = OPCODES[type || (is_text ? :text : :binary)]
|
@@ -151,7 +151,7 @@ module WebSocket
|
|
151
151
|
|
152
152
|
frame.concat(buffer)
|
153
153
|
|
154
|
-
@socket.write(Driver.encode(frame))
|
154
|
+
@socket.write(Driver.encode(frame, :binary))
|
155
155
|
true
|
156
156
|
end
|
157
157
|
|
@@ -292,7 +292,7 @@ module WebSocket
|
|
292
292
|
@buffer.concat(payload)
|
293
293
|
if @final
|
294
294
|
message = @buffer
|
295
|
-
message = Driver.encode(message,
|
295
|
+
message = Driver.encode(message, :utf8) if @mode == :text
|
296
296
|
reset
|
297
297
|
if message
|
298
298
|
emit(:message, MessageEvent.new(message))
|
@@ -303,7 +303,7 @@ module WebSocket
|
|
303
303
|
|
304
304
|
when OPCODES[:text] then
|
305
305
|
if @final
|
306
|
-
message = Driver.encode(payload,
|
306
|
+
message = Driver.encode(payload, :utf8)
|
307
307
|
if message
|
308
308
|
emit(:message, MessageEvent.new(message))
|
309
309
|
else
|
@@ -331,18 +331,20 @@ module WebSocket
|
|
331
331
|
code = ERRORS[:protocol_error]
|
332
332
|
end
|
333
333
|
|
334
|
-
|
334
|
+
message = Driver.encode(payload[2..-1] || [], :utf8)
|
335
|
+
|
336
|
+
if payload.size > 125 or message.nil?
|
335
337
|
code = ERRORS[:protocol_error]
|
336
338
|
end
|
337
339
|
|
338
|
-
reason = (payload.size > 2) ?
|
340
|
+
reason = (payload.size > 2) ? message : ''
|
339
341
|
shutdown(code, reason || '')
|
340
342
|
|
341
343
|
when OPCODES[:ping] then
|
342
344
|
frame(payload, :pong)
|
343
345
|
|
344
346
|
when OPCODES[:pong] then
|
345
|
-
message = Driver.encode(payload,
|
347
|
+
message = Driver.encode(payload, :utf8)
|
346
348
|
callback = @ping_callbacks[message]
|
347
349
|
@ping_callbacks.delete(message)
|
348
350
|
callback.call if callback
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: java
|
7
7
|
authors:
|
@@ -9,23 +9,21 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
MA==
|
20
|
+
version: '0'
|
22
21
|
none: false
|
23
22
|
requirement: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- -
|
24
|
+
- - '>='
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
MA==
|
26
|
+
version: '0'
|
29
27
|
none: false
|
30
28
|
prerelease: false
|
31
29
|
type: :development
|
@@ -33,17 +31,15 @@ dependencies:
|
|
33
31
|
name: rake-compiler
|
34
32
|
version_requirements: !ruby/object:Gem::Requirement
|
35
33
|
requirements:
|
36
|
-
- -
|
34
|
+
- - '>='
|
37
35
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
39
|
-
MA==
|
36
|
+
version: '0'
|
40
37
|
none: false
|
41
38
|
requirement: !ruby/object:Gem::Requirement
|
42
39
|
requirements:
|
43
|
-
- -
|
40
|
+
- - '>='
|
44
41
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
MA==
|
42
|
+
version: '0'
|
47
43
|
none: false
|
48
44
|
prerelease: false
|
49
45
|
type: :development
|
@@ -51,17 +47,15 @@ dependencies:
|
|
51
47
|
name: rspec
|
52
48
|
version_requirements: !ruby/object:Gem::Requirement
|
53
49
|
requirements:
|
54
|
-
- -
|
50
|
+
- - '>='
|
55
51
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
MA==
|
52
|
+
version: '0'
|
58
53
|
none: false
|
59
54
|
requirement: !ruby/object:Gem::Requirement
|
60
55
|
requirements:
|
61
|
-
- -
|
56
|
+
- - '>='
|
62
57
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
64
|
-
MA==
|
58
|
+
version: '0'
|
65
59
|
none: false
|
66
60
|
prerelease: false
|
67
61
|
type: :development
|
@@ -97,25 +91,29 @@ homepage: http://github.com/faye/websocket-driver-ruby
|
|
97
91
|
licenses: []
|
98
92
|
post_install_message:
|
99
93
|
rdoc_options:
|
100
|
-
-
|
94
|
+
- --main
|
101
95
|
- README.md
|
102
|
-
-
|
96
|
+
- --markup
|
103
97
|
- markdown
|
104
98
|
require_paths:
|
105
99
|
- lib
|
106
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
101
|
requirements:
|
108
|
-
- -
|
102
|
+
- - '>='
|
109
103
|
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: '0'
|
107
|
+
hash: 2
|
112
108
|
none: false
|
113
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
110
|
requirements:
|
115
|
-
- -
|
111
|
+
- - '>='
|
116
112
|
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: '0'
|
116
|
+
hash: 2
|
119
117
|
none: false
|
120
118
|
requirements: []
|
121
119
|
rubyforge_project:
|