websocket-client-simple 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/History.txt +5 -0
- data/lib/websocket-client-simple/client.rb +9 -9
- data/lib/websocket-client-simple/version.rb +1 -1
- data/test/test_websocket_client_simple.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4ea337a582d882d5b994ae917ead5f8bb7d8366
|
4
|
+
data.tar.gz: c5ba071b095d13b4d2e0a94b5d005f5bb0d40e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce374970d37e555925969ef5bb6c126c5020e0fdd3743d6a996604802b1751620819984c40efc7bb8d5749fc25e23930c5f9ec8f88ad57577623a423cb3d3773
|
7
|
+
data.tar.gz: 60453f1fcb3df824ffcbc88f099d38dbb2576c8a4b14a208d44ce2157bed2b3f2f23d0236e041410b62188c099d9f46506ac5d742a445b1225b557fe45397210
|
data/.travis.yml
CHANGED
data/History.txt
CHANGED
@@ -8,13 +8,13 @@ module WebSocket
|
|
8
8
|
|
9
9
|
class Client
|
10
10
|
include EventEmitter
|
11
|
-
attr_reader :url
|
11
|
+
attr_reader :url, :handshake
|
12
12
|
|
13
13
|
def initialize(url)
|
14
14
|
@url = url
|
15
15
|
uri = URI.parse url
|
16
16
|
@socket = TCPSocket.new(uri.host, uri.port || 80)
|
17
|
-
@
|
17
|
+
@handshake = ::WebSocket::Handshake::Client.new :url => url
|
18
18
|
@handshaked = false
|
19
19
|
frame = ::WebSocket::Frame::Incoming::Client.new
|
20
20
|
@closed = false
|
@@ -26,10 +26,10 @@ module WebSocket
|
|
26
26
|
@thread = Thread.new do
|
27
27
|
while !@closed do
|
28
28
|
begin
|
29
|
-
recv_data = @socket.getc
|
30
|
-
|
31
|
-
@
|
32
|
-
if @
|
29
|
+
next unless recv_data = @socket.getc
|
30
|
+
unless @handshaked
|
31
|
+
@handshake << recv_data
|
32
|
+
if @handshake.finished?
|
33
33
|
@handshaked = true
|
34
34
|
emit :open
|
35
35
|
end
|
@@ -45,13 +45,13 @@ module WebSocket
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
@socket.write @
|
48
|
+
@socket.write @handshake.to_s
|
49
49
|
end
|
50
50
|
|
51
51
|
def send(data, opt={:type => :text})
|
52
52
|
return if !@handshaked or @closed
|
53
53
|
type = opt[:type]
|
54
|
-
frame = ::WebSocket::Frame::Outgoing::Client.new(:data => data, :type => type, :version => @
|
54
|
+
frame = ::WebSocket::Frame::Outgoing::Client.new(:data => data, :type => type, :version => @handshake.version)
|
55
55
|
begin
|
56
56
|
@socket.write frame.to_s
|
57
57
|
rescue Errno::EPIPE => e
|
@@ -70,7 +70,7 @@ module WebSocket
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def open?
|
73
|
-
!@closed
|
73
|
+
@handshake.finished? and !@closed
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -33,7 +33,9 @@ class TestWebSocketClientSimple < MiniTest::Test
|
|
33
33
|
EM::add_timer 1 do
|
34
34
|
url = "ws://localhost:#{port}"
|
35
35
|
client1 = WebSocket::Client::Simple.connect url
|
36
|
+
assert_equal client1.open?, false
|
36
37
|
client2 = WebSocket::Client::Simple.connect url
|
38
|
+
assert_equal client2.open?, false
|
37
39
|
|
38
40
|
client1.on :message do |msg|
|
39
41
|
res1.push msg
|
@@ -58,6 +60,8 @@ class TestWebSocketClientSimple < MiniTest::Test
|
|
58
60
|
end
|
59
61
|
|
60
62
|
EM::add_timer 3 do
|
63
|
+
assert_equal client1.open?, true
|
64
|
+
assert_equal client2.open?, true
|
61
65
|
client1.close
|
62
66
|
client2.close
|
63
67
|
EM::stop_event_loop
|
@@ -65,12 +69,12 @@ class TestWebSocketClientSimple < MiniTest::Test
|
|
65
69
|
end
|
66
70
|
}
|
67
71
|
|
68
|
-
|
69
|
-
|
72
|
+
assert_equal msgs.size, res1.size
|
73
|
+
assert_equal msgs.size, res2.size
|
70
74
|
|
71
75
|
msgs.each_with_index do |msg,i|
|
72
|
-
|
73
|
-
|
76
|
+
assert_equal msg, res1[i].to_s
|
77
|
+
assert_equal msg, res2[i].to_s
|
74
78
|
end
|
75
79
|
|
76
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket-client-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|