sinatra-rocketio 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/sinatra-rocketio/version.rb +1 -1
- data/lib/sinatra/rocketio/client.rb +26 -3
- metadata +3 -3
data/History.txt
CHANGED
@@ -14,15 +14,38 @@ module Sinatra
|
|
14
14
|
include EventEmitter
|
15
15
|
attr_reader :settings, :type, :io
|
16
16
|
|
17
|
+
public
|
17
18
|
def initialize(url, opt={:type => :websocket})
|
19
|
+
@url = url
|
18
20
|
@type = opt[:type].to_sym
|
19
21
|
@io = nil
|
20
|
-
@settings =
|
22
|
+
@settings = nil
|
21
23
|
@ws_close_thread = nil
|
22
24
|
self
|
23
25
|
end
|
24
26
|
|
27
|
+
private
|
28
|
+
def get_settings
|
29
|
+
url = "#{@url}/rocketio/settings"
|
30
|
+
begin
|
31
|
+
res = HTTParty.get url
|
32
|
+
unless res.code == 200
|
33
|
+
emit :error, "#{res.code} get error (#{url})"
|
34
|
+
sleep 10
|
35
|
+
get_settings
|
36
|
+
else
|
37
|
+
@settings = JSON.parse res.body
|
38
|
+
end
|
39
|
+
rescue => e
|
40
|
+
emit :error, "#{e} (#{url})"
|
41
|
+
sleep 10
|
42
|
+
get_settings
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
public
|
25
47
|
def connect
|
48
|
+
get_settings unless @settings
|
26
49
|
this = self
|
27
50
|
if @type == :websocket and @settings.include? 'websocket'
|
28
51
|
@io = Sinatra::WebSocketIO::Client.new(@settings['websocket']).connect
|
@@ -54,11 +77,11 @@ module Sinatra
|
|
54
77
|
end
|
55
78
|
|
56
79
|
def close
|
57
|
-
@io.close
|
80
|
+
@io.close if @io
|
58
81
|
end
|
59
82
|
|
60
83
|
def push(type, data)
|
61
|
-
@io.push type, data
|
84
|
+
@io.push type, data if @io
|
62
85
|
end
|
63
86
|
|
64
87
|
def method_missing(name, *args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rocketio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -271,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
271
|
version: '0'
|
272
272
|
segments:
|
273
273
|
- 0
|
274
|
-
hash:
|
274
|
+
hash: 1593017263457838199
|
275
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
276
|
none: false
|
277
277
|
requirements:
|
@@ -280,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
280
|
version: '0'
|
281
281
|
segments:
|
282
282
|
- 0
|
283
|
-
hash:
|
283
|
+
hash: 1593017263457838199
|
284
284
|
requirements: []
|
285
285
|
rubyforge_project:
|
286
286
|
rubygems_version: 1.8.24
|