em-rocketio-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/em-rocketio-client/client.rb +28 -10
- data/lib/em-rocketio-client/version.rb +1 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -7,32 +7,50 @@ module EventMachine
|
|
7
7
|
include EventEmitter
|
8
8
|
attr_reader :settings, :type, :io
|
9
9
|
|
10
|
+
public
|
10
11
|
def initialize(url, opt={:type => :websocket})
|
11
|
-
|
12
|
+
@url = url
|
13
|
+
@type = opt[:type].to_sym
|
14
|
+
@settings = nil
|
15
|
+
@io = nil
|
16
|
+
@ws_close_timer = nil
|
17
|
+
get_settings
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def get_settings
|
23
|
+
url = "#{@url}/rocketio/settings"
|
24
|
+
http = EM::HttpRequest.new(url).get
|
12
25
|
http.callback do |res|
|
13
26
|
begin
|
14
27
|
@settings = JSON.parse res.response
|
15
28
|
emit :__settings
|
16
29
|
rescue => e
|
17
|
-
emit :error, e
|
30
|
+
emit :error, "#{e} (#{url})"
|
31
|
+
EM::add_timer 10 do
|
32
|
+
get_settings
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
|
-
http.errback do |
|
21
|
-
|
36
|
+
http.errback do |e|
|
37
|
+
if e.error == Errno::ECONNREFUSED
|
38
|
+
emit :error, "connection refused (#{url})"
|
39
|
+
else
|
40
|
+
emit :error, "#{err.error} (#{url})"
|
41
|
+
end
|
42
|
+
EM::add_timer 10 do
|
43
|
+
get_settings
|
44
|
+
end
|
22
45
|
end
|
23
|
-
@settings = nil
|
24
|
-
@type = opt[:type].to_sym
|
25
|
-
@io = nil
|
26
|
-
@ws_close_timer = nil
|
27
|
-
self
|
28
46
|
end
|
29
47
|
|
48
|
+
public
|
30
49
|
def connect
|
31
50
|
this = self
|
32
51
|
once :__settings do
|
33
52
|
if @type == :websocket and @settings.include? 'websocket'
|
34
53
|
@io = EM::WebSocketIO::Client.new(@settings['websocket']).connect
|
35
|
-
@type = :websocket
|
36
54
|
elsif @type == :comet or @settings.include? 'comet'
|
37
55
|
@io = EM::CometIO::Client.new(@settings['comet']).connect
|
38
56
|
@type = :comet
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-rocketio-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -209,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
segments:
|
211
211
|
- 0
|
212
|
-
hash:
|
212
|
+
hash: 489993316475369448
|
213
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
214
|
none: false
|
215
215
|
requirements:
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
segments:
|
220
220
|
- 0
|
221
|
-
hash:
|
221
|
+
hash: 489993316475369448
|
222
222
|
requirements: []
|
223
223
|
rubyforge_project:
|
224
224
|
rubygems_version: 1.8.24
|