em-rocketio-client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ === 0.0.2 2013-03-25
2
+
3
+ * use EM::HttpRequest to get settings
4
+ * use comet if websocket port close
5
+
6
+ === 0.0.1 2013-03-24
7
+
8
+ * implement EM::RocketIO::Client
9
+ * add tests
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
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "em-cometio-client"
28
28
  spec.add_dependency "em-websocketio-client"
29
+ spec.add_dependency "em-http-request"
29
30
  spec.add_dependency "eventmachine"
30
31
  spec.add_dependency "event_emitter"
31
32
  end
@@ -1,7 +1,7 @@
1
1
  require "em-cometio-client"
2
2
  require "em-websocketio-client"
3
+ require "em-http"
3
4
  require "event_emitter"
4
- require "httparty"
5
5
 
6
6
  require "em-rocketio-client/version"
7
7
  require "em-rocketio-client/client"
@@ -8,28 +8,54 @@ module EventMachine
8
8
  attr_reader :settings, :type, :io
9
9
 
10
10
  def initialize(url, opt={:type => :websocket})
11
- @settings = JSON.parse HTTParty.get("#{url}/rocketio/settings").body
12
- type = opt[:type].to_sym
13
- if type == :websocket and @settings.include? 'websocket'
14
- @type = :websocket
15
- @io = EM::WebSocketIO::Client.new @settings['websocket']
16
- elsif type == :comet or @settings.include? 'comet'
17
- @type = :comet
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
- @io.connect
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
 
@@ -1,7 +1,7 @@
1
1
  module EventMachine
2
2
  module RocketIO
3
3
  class Client
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -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('http://localhost:5000').connect
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.1
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: 2360181630930510065
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: 2360181630930510065
221
+ hash: -1144909537786035636
205
222
  requirements: []
206
223
  rubyforge_project:
207
224
  rubygems_version: 1.8.24