ws_client 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ws_client.rb +27 -19
- data/lib/ws_client/version.rb +1 -1
- 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: d6c418fc7b686210fc3ea7d779fa8953b7990209
|
4
|
+
data.tar.gz: a0843638a3b961aba33b3c89bf35add83a110c58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717b41e9d41803e667c625b9f2b372db5e9cc8bb078176dfc801c0088f77cae419a7bf5917c3aba53a6bcdd32bccd50758a1b21ac303efe0d0c8e931bdcd7dad
|
7
|
+
data.tar.gz: c97d5e0c0fe34c5ca963afbef21b59dcb6a086826fc1ca4035c224e750f0884bee79a1521876016ae2d44b51d3da44f2b91eaca92bee024eeee35c557ea7d027
|
data/lib/ws_client.rb
CHANGED
@@ -62,13 +62,8 @@ module WsClient
|
|
62
62
|
connect(nil)
|
63
63
|
end
|
64
64
|
|
65
|
-
def send_data(data, opt={:type => :text})
|
66
|
-
@thread ||= poll # utilize the polling interface, could probably be split into another class
|
67
|
-
write_data(data, opt)
|
68
|
-
end
|
69
|
-
|
70
65
|
# Returns all responses that have been accepted
|
71
|
-
def send_data_and_wait(data, timeout, opt = { :type => :text })
|
66
|
+
def send_data_and_wait(data, timeout = MS_2, opt = { :type => :text })
|
72
67
|
response_data = []
|
73
68
|
write_data(data, opt)
|
74
69
|
pull_next_message_off_of_socket(@socket, timeout)
|
@@ -82,6 +77,7 @@ module WsClient
|
|
82
77
|
|
83
78
|
response_data
|
84
79
|
end
|
80
|
+
alias_method :send_data, :send_data_and_wait
|
85
81
|
|
86
82
|
def close
|
87
83
|
return if @closed
|
@@ -92,7 +88,6 @@ module WsClient
|
|
92
88
|
@closed = true
|
93
89
|
@socket.close if @socket
|
94
90
|
@socket = nil
|
95
|
-
Thread.kill @thread if @thread
|
96
91
|
end
|
97
92
|
|
98
93
|
def closed?
|
@@ -134,18 +129,6 @@ module WsClient
|
|
134
129
|
emit :open if @handshaked
|
135
130
|
end
|
136
131
|
|
137
|
-
def poll
|
138
|
-
return Thread.new(@socket) do |socket|
|
139
|
-
while !@closed do
|
140
|
-
pull_next_message_off_of_socket(socket)
|
141
|
-
|
142
|
-
message_queue.length.times do
|
143
|
-
emit :message, message_queue.pop
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
132
|
def pull_next_message_off_of_socket(socket, timeout = 10, last_frame = nil)
|
150
133
|
read_sockets, _, _ = IO.select([socket], nil, nil, timeout)
|
151
134
|
|
@@ -204,4 +187,29 @@ module WsClient
|
|
204
187
|
end
|
205
188
|
end
|
206
189
|
end
|
190
|
+
|
191
|
+
class AsyncClient < ::WsClient::Client
|
192
|
+
def close
|
193
|
+
super
|
194
|
+
ensure
|
195
|
+
Thread.kill @thread if @thread
|
196
|
+
end
|
197
|
+
|
198
|
+
def send_data(data, opt={:type => :text})
|
199
|
+
@thread ||= poll # utilize the polling interface, could probably be split into another class
|
200
|
+
write_data(data, opt)
|
201
|
+
end
|
202
|
+
|
203
|
+
def poll
|
204
|
+
return Thread.new(@socket) do |socket|
|
205
|
+
while !@closed do
|
206
|
+
pull_next_message_off_of_socket(socket)
|
207
|
+
|
208
|
+
message_queue.length.times do
|
209
|
+
emit :message, message_queue.pop
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
207
215
|
end
|
data/lib/ws_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ws_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-08-
|
12
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|