em-rocketio-client 0.0.1 → 0.0.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.
- data/History.txt +9 -0
- data/README.md +3 -0
- data/em-rocketio-client.gemspec +1 -0
- data/lib/em-rocketio-client.rb +1 -1
- data/lib/em-rocketio-client/client.rb +42 -16
- data/lib/em-rocketio-client/version.rb +1 -1
- data/sample/cui_chat_client.rb +3 -3
- metadata +20 -3
data/History.txt
ADDED
data/README.md
CHANGED
@@ -62,6 +62,9 @@ start [chat server](https://github.com/shokai/rocketio-chat-sample)
|
|
62
62
|
sample chat client
|
63
63
|
|
64
64
|
% ruby sample/cui_chat_client.rb
|
65
|
+
% ruby sample/cui_chat_client.rb http://localhost:5000 comet
|
66
|
+
% ruby sample/cui_chat_client.rb http://localhost:5000 websocket
|
67
|
+
% ruby sample/cui_chat_client.rb http://rocketio-chat.herokuapp.com
|
65
68
|
|
66
69
|
|
67
70
|
Test
|
data/em-rocketio-client.gemspec
CHANGED
data/lib/em-rocketio-client.rb
CHANGED
@@ -8,28 +8,54 @@ module EventMachine
|
|
8
8
|
attr_reader :settings, :type, :io
|
9
9
|
|
10
10
|
def initialize(url, opt={:type => :websocket})
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@io = EM::CometIO::Client.new @settings['comet']
|
19
|
-
else
|
20
|
-
raise Error, "cannot find #{type} IO #{url}"
|
21
|
-
end
|
22
|
-
this = self
|
23
|
-
if @io
|
24
|
-
@io.on :* do |event_name, *args|
|
25
|
-
this.emit event_name, *args
|
11
|
+
http = EM::HttpRequest.new("#{url}/rocketio/settings").get
|
12
|
+
http.callback do |res|
|
13
|
+
begin
|
14
|
+
@settings = JSON.parse res.response
|
15
|
+
emit :__settings
|
16
|
+
rescue => e
|
17
|
+
emit :error, e
|
26
18
|
end
|
27
19
|
end
|
20
|
+
http.errback do |err|
|
21
|
+
emit :error, err
|
22
|
+
end
|
23
|
+
@settings = nil
|
24
|
+
@type = opt[:type].to_sym
|
25
|
+
@io = nil
|
26
|
+
@ws_close_timer = nil
|
28
27
|
self
|
29
28
|
end
|
30
29
|
|
31
30
|
def connect
|
32
|
-
|
31
|
+
this = self
|
32
|
+
once :__settings do
|
33
|
+
if @type == :websocket and @settings.include? 'websocket'
|
34
|
+
@io = EM::WebSocketIO::Client.new(@settings['websocket']).connect
|
35
|
+
@type = :websocket
|
36
|
+
elsif @type == :comet or @settings.include? 'comet'
|
37
|
+
@io = EM::CometIO::Client.new(@settings['comet']).connect
|
38
|
+
@type = :comet
|
39
|
+
else
|
40
|
+
raise Error, "cannnot found #{@type} IO"
|
41
|
+
end
|
42
|
+
@io.on :* do |event_name, *args|
|
43
|
+
this.emit event_name, *args
|
44
|
+
end
|
45
|
+
if @type == :websocket
|
46
|
+
@ws_close_timer = EM::add_timer 3 do
|
47
|
+
close
|
48
|
+
emit :error, "websocket port is not open"
|
49
|
+
@type = :comet
|
50
|
+
connect
|
51
|
+
end
|
52
|
+
once :connect do
|
53
|
+
EM::cancel_timer @ws_close_timer if @ws_close_timer
|
54
|
+
@ws_close_timer = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
emit :__settings if @settings
|
33
59
|
self
|
34
60
|
end
|
35
61
|
|
data/sample/cui_chat_client.rb
CHANGED
@@ -4,13 +4,13 @@ require 'rubygems'
|
|
4
4
|
require 'em-rocketio-client'
|
5
5
|
|
6
6
|
name = `whoami`.strip || 'shokai'
|
7
|
+
url = ARGV.shift || 'http://localhost:5000'
|
8
|
+
type = ARGV.shift || :websocket
|
7
9
|
|
8
10
|
EM::run do
|
9
|
-
io = EM::RocketIO::Client.new(
|
11
|
+
io = EM::RocketIO::Client.new(url, :type => type).connect
|
10
12
|
# io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
|
11
13
|
|
12
|
-
puts "waiting #{io.url}"
|
13
|
-
|
14
14
|
io.on :connect do |session|
|
15
15
|
puts "#{io.type} connect!! (sessin_id:#{session})"
|
16
16
|
end
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: em-http-request
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
126
142
|
- !ruby/object:Gem::Dependency
|
127
143
|
name: eventmachine
|
128
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +180,7 @@ extra_rdoc_files: []
|
|
164
180
|
files:
|
165
181
|
- .gitignore
|
166
182
|
- Gemfile
|
183
|
+
- History.txt
|
167
184
|
- LICENSE.txt
|
168
185
|
- README.md
|
169
186
|
- Rakefile
|
@@ -192,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
209
|
version: '0'
|
193
210
|
segments:
|
194
211
|
- 0
|
195
|
-
hash:
|
212
|
+
hash: -1144909537786035636
|
196
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
214
|
none: false
|
198
215
|
requirements:
|
@@ -201,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
218
|
version: '0'
|
202
219
|
segments:
|
203
220
|
- 0
|
204
|
-
hash:
|
221
|
+
hash: -1144909537786035636
|
205
222
|
requirements: []
|
206
223
|
rubyforge_project:
|
207
224
|
rubygems_version: 1.8.24
|