em-rocketio-client 0.0.3 → 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be3c3fd9b1d6aad850a146c222942eced15b0bd8
4
+ data.tar.gz: f38e6bb9809160bb9fd8936dbe1ee906ec992385
5
+ SHA512:
6
+ metadata.gz: 3f6a42bbfffbd243929871741d4a02d01e3be031ac89b935952d4f409b3cad8e5d156e1ef179ffe12e82b460d927d08c255dae238a1298a26be94260a2e566d2
7
+ data.tar.gz: ab4236ac8877dd8022f1dfe20e6870d7aef17849c1465accaa8ed454fcac0a5f5437cb9aa9e38ecf04a0b19c85adac433af5f30591b753f95a2fdd0c430112e2
data/.gitignore CHANGED
@@ -1,8 +1,11 @@
1
+ *~
2
+ *#*
1
3
  *.gem
2
4
  *.rbc
3
5
  .bundle
4
6
  .config
5
7
  .yardoc
8
+ .ruby-version
6
9
  InstalledFiles
7
10
  _yardoc
8
11
  coverage
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.0 2013-04-01
2
+
3
+ * support Sinatra::RocketIO v0.2.0
4
+
1
5
  === 0.0.3 2013-03-25
2
6
 
3
7
  * retry get /rocketio/settings
data/README.md CHANGED
@@ -20,7 +20,7 @@ require 'em-rocketio-client'
20
20
  EM::run do
21
21
  io = EM::RocketIO::Client.new('http://localhost:5000').connect
22
22
  # io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
23
-
23
+ # io = EM::RocketIO::Client.new('http://localhost:5000', :channel => '1').connect
24
24
  io.on :connect do |session|
25
25
  puts "#{io.type} connect!! (sessin_id:#{session})"
26
26
  end
@@ -72,9 +72,15 @@ Test
72
72
 
73
73
  % gem install bundler
74
74
  % bundle install
75
+
76
+ start server
77
+
75
78
  % export PORT=5000
76
79
  % export WS_PORT=8080
77
- % export PID_FILE=/tmp/em-rocketio-client-testapp.pid
80
+ % rake test_server
81
+
82
+ run test
83
+
78
84
  % rake test
79
85
 
80
86
 
data/Rakefile CHANGED
@@ -5,4 +5,10 @@ Rake::TestTask.new do |t|
5
5
  t.pattern = "test/test_*.rb"
6
6
  end
7
7
 
8
+ desc "Start test server"
9
+ task :test_server do
10
+ require File.expand_path 'test/app', File.dirname(__FILE__)
11
+ App.start
12
+ end
13
+
8
14
  task :default => :test
@@ -5,12 +5,13 @@ module EventMachine
5
5
  end
6
6
 
7
7
  include EventEmitter
8
- attr_reader :settings, :type, :io
8
+ attr_reader :settings, :type, :io, :channel
9
9
 
10
10
  public
11
- def initialize(url, opt={:type => :websocket})
11
+ def initialize(url, opt={:type => :websocket, :channel => nil})
12
12
  @url = url
13
13
  @type = opt[:type].to_sym
14
+ @channel = opt[:channel] ? opt[:channel].to_s : nil
14
15
  @settings = nil
15
16
  @io = nil
16
17
  @ws_close_timer = nil
@@ -37,7 +38,7 @@ module EventMachine
37
38
  if e.error == Errno::ECONNREFUSED
38
39
  emit :error, "connection refused (#{url})"
39
40
  else
40
- emit :error, "#{err.error} (#{url})"
41
+ emit :error, "#{e.error} (#{url})"
41
42
  end
42
43
  EM::add_timer 10 do
43
44
  get_settings
@@ -58,8 +59,13 @@ module EventMachine
58
59
  raise Error, "cannnot found #{@type} IO"
59
60
  end
60
61
  @io.on :* do |event_name, *args|
62
+ event_name = :__connect if event_name == :connect
61
63
  this.emit event_name, *args
62
64
  end
65
+ this.on :__connect do
66
+ this.io.push :__channel_id, this.channel
67
+ this.emit :connect
68
+ end
63
69
  if @type == :websocket
64
70
  @ws_close_timer = EM::add_timer 3 do
65
71
  close
@@ -82,7 +88,7 @@ module EventMachine
82
88
  end
83
89
 
84
90
  def push(type, data={})
85
- @io.push type, data
91
+ @io.push type, data if @io
86
92
  end
87
93
 
88
94
  def method_missing(name, *args)
@@ -1,7 +1,7 @@
1
1
  module EventMachine
2
2
  module RocketIO
3
3
  class Client
4
- VERSION = "0.0.3"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -11,8 +11,8 @@ EM::run do
11
11
  io = EM::RocketIO::Client.new(url, :type => type).connect
12
12
  # io = EM::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
13
13
 
14
- io.on :connect do |session|
15
- puts "#{io.type} connect!! (sessin_id:#{session})"
14
+ io.on :connect do
15
+ puts "#{io.type} connect!! (sessin_id:#{io.session})"
16
16
  end
17
17
 
18
18
  io.on :disconnect do
data/test/app.rb CHANGED
@@ -24,48 +24,15 @@ class App
24
24
  "http://localhost:#{port}/cometio/io"
25
25
  end
26
26
 
27
- def self.pid_file
28
- ENV['PID_FILE'] || "/tmp/em-rocketio-testapp.pid"
29
- end
30
-
31
27
  def self.app_dir
32
28
  File.expand_path 'app', File.dirname(__FILE__)
33
29
  end
34
30
 
35
- def self.pid
36
- return unless @running
37
- File.open(pid_file) do |f|
38
- pid = f.gets.strip.to_i
39
- return pid if pid > 0
40
- end
41
- return
42
- end
43
-
44
31
  def self.start
45
- return if @running
46
- File.delete pid_file if File.exists? pid_file
47
- Thread.new do
48
- IO::popen "cd #{app_dir} && PID_FILE=#{pid_file} WS_PORT=#{ws_port} rackup config.ru -p #{port} > /dev/null 2>&1"
49
- end
32
+ return if running
50
33
  @running = true
51
- 100.times do
52
- if File.exists? pid_file
53
- sleep 2
54
- return true
55
- end
56
- sleep 0.1
57
- end
58
- @running = false
59
- return false
60
- end
61
-
62
- def self.stop
63
- return unless @running
64
- if File.exists? pid_file
65
- system "kill -9 #{pid}"
66
- File.delete pid_file
67
- end
68
- @running = false
34
+ cmd = "cd #{app_dir} && WS_PORT=#{ws_port} rackup config.ru -p #{port}"
35
+ system cmd
69
36
  end
70
37
 
71
38
  end
data/test/app/main.rb CHANGED
@@ -1,13 +1,3 @@
1
- pid_file = ENV['PID_FILE'] || "/tmp/em-rocketio-test-pid"
2
- EM::defer do
3
- while !EM::reactor_running? do
4
- sleep 0.1
5
- end
6
- File.open(pid_file, "w+") do |f|
7
- f.write Process.pid.to_s
8
- end
9
- end
10
-
11
1
  class TestApp < Sinatra::Base
12
2
  register Sinatra::RocketIO
13
3
  io = Sinatra::RocketIO
@@ -16,23 +6,28 @@ class TestApp < Sinatra::Base
16
6
  "sinatra-rocketio v#{Sinatra::RocketIO::VERSION}"
17
7
  end
18
8
 
19
- io.on :connect do |session, type|
20
- puts "new client <session:#{session}> <type:#{type}>"
9
+ io.on :connect do |client|
10
+ puts "new client <session:#{client.session}> <type:#{client.type}>"
21
11
  end
22
12
 
23
- io.on :disconnect do |session, type|
24
- puts "disconnect client <session:#{session}> <type:#{type}>"
13
+ io.on :disconnect do |client|
14
+ puts "disconnect client <session:#{client.session}> <type:#{client.type}>"
25
15
  end
26
16
 
27
- io.on :broadcast do |data, from, type|
17
+ io.on :broadcast do |data, client|
28
18
  puts from
29
- puts "broadcast <session:#{from}> <type:#{type}> - #{data.to_json}"
19
+ puts "broadcast <session:#{client.session}> <type:#{client.type}> - #{data.to_json}"
30
20
  push :broadcast, data
31
21
  end
32
22
 
33
- io.on :message do |data, from, type|
34
- puts "message <session:#{from}> <type:#{type}> - #{data.to_json}"
23
+ io.on :message do |data, client|
24
+ puts "message <session:#{client.session}> <type:#{client.type}> - #{data.to_json}"
35
25
  push :message, data, :to => data['to']
36
26
  end
37
27
 
28
+ io.on :to_channel do |data, client|
29
+ puts "message to channel:#{client.channel} <type:#{client.type}> - #{data.to_json}"
30
+ push :to_channel, data, :channel => client.channel
31
+ end
32
+
38
33
  end
@@ -0,0 +1,54 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestChannel < MiniTest::Unit::TestCase
4
+
5
+ def test_channel
6
+ ## client1(comet, channel "aaa") ---> server --> client3(websocket, channel "aaa")
7
+ ## client2(websocket, channel "bbb") not receive data from channel "aaa"
8
+ post_data = {:time => Time.now.to_s, :msg => 'hello!!'}
9
+ res = nil
10
+ res2 = nil
11
+ res3 = nil
12
+ EM::run do
13
+ client = EM::RocketIO::Client.new(App.url, :type => :comet, :channel => "aaa").connect
14
+ client.on :to_channel do |data|
15
+ res = data
16
+ end
17
+
18
+ client.on :connect do
19
+ client2 = EM::RocketIO::Client.new(App.url, :type => :websocket, :channel => "bbb").connect
20
+ client2.on :connect do
21
+ client3 = EM::RocketIO::Client.new(App.url, :type => :websocket, :channel => "aaa").connect
22
+ client3.on :connect do
23
+ client.push :to_channel, post_data
24
+ end
25
+ client3.on :to_channel do |data|
26
+ res3 = data
27
+ client3.close
28
+ end
29
+ end
30
+ client2.on :to_channel do |data|
31
+ res2 = data
32
+ client2.close
33
+ end
34
+ end
35
+
36
+ EM::defer do
37
+ 50.times do
38
+ break if res != nil and res3 != nil
39
+ sleep 0.1
40
+ end
41
+ client.close
42
+ EM::stop
43
+ end
44
+ end
45
+ assert res != nil, 'server not respond'
46
+ assert res["time"] == post_data[:time]
47
+ assert res["msg"] == post_data[:msg]
48
+ assert res3 != nil, 'server not respond'
49
+ assert res3["time"] == post_data[:time]
50
+ assert res3["msg"] == post_data[:msg]
51
+ assert res2 == nil, 'channel error'
52
+ end
53
+
54
+ end
@@ -2,14 +2,6 @@ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
3
  class TestEmRocketioClient < MiniTest::Unit::TestCase
4
4
 
5
- def setup
6
- App.start
7
- end
8
-
9
- def teardown
10
- App.stop
11
- end
12
-
13
5
  def test_websocket_to_comet
14
6
  ## websocket --> server --> comet
15
7
  post_data = {:time => Time.now.to_s, :msg => 'hello!!', :to => nil}
@@ -30,10 +22,10 @@ class TestEmRocketioClient < MiniTest::Unit::TestCase
30
22
  end
31
23
  end
32
24
 
33
- client.on :connect do |session|
25
+ client.on :connect do
34
26
  client2 = EM::RocketIO::Client.new(App.url, :type => :comet).connect
35
- client2.on :connect do |session2|
36
- post_data['to'] = session2
27
+ client2.on :connect do
28
+ post_data['to'] = client2.session
37
29
  client.push :message, post_data
38
30
  end
39
31
  client2.on :message do |data|
@@ -74,10 +66,10 @@ class TestEmRocketioClient < MiniTest::Unit::TestCase
74
66
  end
75
67
  end
76
68
 
77
- client.on :connect do |session|
69
+ client.on :connect do
78
70
  client2 = EM::RocketIO::Client.new(App.url, :type => :websocket).connect
79
- client2.on :connect do |session2|
80
- post_data['to'] = session2
71
+ client2.on :connect do
72
+ post_data['to'] = client2.session
81
73
  client.push :message, post_data
82
74
  end
83
75
  client2.on :message do |data|
data/test/test_helper.rb CHANGED
@@ -4,10 +4,3 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
4
4
  require 'minitest/autorun'
5
5
  require 'em-rocketio-client'
6
6
  require File.expand_path 'app', File.dirname(__FILE__)
7
-
8
-
9
- ['SIGHUP', 'SIGINT', 'SIGKILL', 'SIGTERM'].each do |sig|
10
- Kernel.trap sig do
11
- App.stop
12
- end
13
- end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-rocketio-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sho Hashimoto
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
11
+ date: 2013-04-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,145 +27,127 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sinatra-rocketio
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: thin
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: em-cometio-client
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: em-websocketio-client
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: em-http-request
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: eventmachine
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: event_emitter
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: '0'
166
146
  type: :runtime
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: '0'
174
153
  description: Sinatra RocketIO client for eventmachine
@@ -192,42 +171,37 @@ files:
192
171
  - test/app.rb
193
172
  - test/app/config.ru
194
173
  - test/app/main.rb
174
+ - test/test_channel.rb
195
175
  - test/test_em_rocketio_client.rb
196
176
  - test/test_helper.rb
197
177
  homepage: https://github.com/shokai/em-rocketio-client
198
178
  licenses:
199
179
  - MIT
180
+ metadata: {}
200
181
  post_install_message:
201
182
  rdoc_options: []
202
183
  require_paths:
203
184
  - lib
204
185
  required_ruby_version: !ruby/object:Gem::Requirement
205
- none: false
206
186
  requirements:
207
- - - ! '>='
187
+ - - '>='
208
188
  - !ruby/object:Gem::Version
209
189
  version: '0'
210
- segments:
211
- - 0
212
- hash: 489993316475369448
213
190
  required_rubygems_version: !ruby/object:Gem::Requirement
214
- none: false
215
191
  requirements:
216
- - - ! '>='
192
+ - - '>='
217
193
  - !ruby/object:Gem::Version
218
194
  version: '0'
219
- segments:
220
- - 0
221
- hash: 489993316475369448
222
195
  requirements: []
223
196
  rubyforge_project:
224
- rubygems_version: 1.8.24
197
+ rubygems_version: 2.0.3
225
198
  signing_key:
226
- specification_version: 3
199
+ specification_version: 4
227
200
  summary: Sinatra RocketIO client for eventmachine
228
201
  test_files:
229
202
  - test/app.rb
230
203
  - test/app/config.ru
231
204
  - test/app/main.rb
205
+ - test/test_channel.rb
232
206
  - test/test_em_rocketio_client.rb
233
207
  - test/test_helper.rb