sinatra-rocketio 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/History.txt +4 -0
- data/Rakefile +7 -0
- data/lib/sinatra-rocketio/version.rb +1 -1
- data/sample/Gemfile.lock +9 -9
- data/sinatra-rocketio.gemspec +7 -7
- data/test/app.rb +70 -0
- data/test/app/config.ru +11 -0
- data/test/app/main.rb +38 -0
- data/test/test_helper.rb +14 -0
- data/test/test_rocketio.rb +100 -0
- metadata +26 -16
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/sample/Gemfile.lock
CHANGED
@@ -36,14 +36,14 @@ GEM
|
|
36
36
|
rack (~> 1.4)
|
37
37
|
rack-protection (~> 1.3)
|
38
38
|
tilt (~> 1.3, >= 1.3.3)
|
39
|
-
sinatra-cometio (0.3.
|
40
|
-
event_emitter (>= 0.2.
|
41
|
-
eventmachine
|
42
|
-
httparty
|
43
|
-
json
|
44
|
-
rack
|
45
|
-
sinatra
|
46
|
-
sinatra-contrib
|
39
|
+
sinatra-cometio (0.3.4)
|
40
|
+
event_emitter (>= 0.2.3)
|
41
|
+
eventmachine (>= 1.0.0)
|
42
|
+
httparty (>= 0.10.2)
|
43
|
+
json (>= 1.7.0)
|
44
|
+
rack (>= 1.5.0)
|
45
|
+
sinatra (>= 1.3.6)
|
46
|
+
sinatra-contrib (>= 1.3.2)
|
47
47
|
sinatra-contrib (1.3.2)
|
48
48
|
backports (>= 2.0)
|
49
49
|
eventmachine
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
eventmachine (>= 0.12.6)
|
66
66
|
rack (>= 1.0.0)
|
67
67
|
thor (0.17.0)
|
68
|
-
tilt (1.3.
|
68
|
+
tilt (1.3.6)
|
69
69
|
websocket (1.0.7)
|
70
70
|
|
71
71
|
PLATFORMS
|
data/sinatra-rocketio.gemspec
CHANGED
@@ -15,11 +15,11 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
-
gem.add_dependency "rack"
|
19
|
-
gem.add_dependency "sinatra"
|
20
|
-
gem.add_dependency "eventmachine"
|
21
|
-
gem.add_dependency "event_emitter"
|
22
|
-
gem.add_dependency "sinatra-contrib"
|
23
|
-
gem.add_dependency "sinatra-cometio"
|
24
|
-
gem.add_dependency "sinatra-websocketio"
|
18
|
+
gem.add_dependency "rack", ">= 1.5.0"
|
19
|
+
gem.add_dependency "sinatra", ">= 1.3.6"
|
20
|
+
gem.add_dependency "eventmachine", ">= 1.0.0"
|
21
|
+
gem.add_dependency "event_emitter", ">= 0.2.3"
|
22
|
+
gem.add_dependency "sinatra-contrib", ">= 1.3.2"
|
23
|
+
gem.add_dependency "sinatra-cometio", ">= 0.3.4"
|
24
|
+
gem.add_dependency "sinatra-websocketio", ">= 0.1.2"
|
25
25
|
end
|
data/test/app.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class App
|
4
|
+
|
5
|
+
def self.running
|
6
|
+
@running ? true : false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.port
|
10
|
+
ENV['PORT'] || 5000
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.ws_port
|
14
|
+
ENV['WS_PORT'] || 8080
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.websocketio_url
|
18
|
+
"ws://localhost:#{ws_port}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.cometio_url
|
22
|
+
"http://localhost:#{port}/cometio/io"
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.pid_file
|
27
|
+
ENV['PID_FILE'] || "/tmp/sinatra-rocketio-testapp.pid"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.app_dir
|
31
|
+
File.expand_path 'app', File.dirname(__FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.pid
|
35
|
+
return unless @running
|
36
|
+
File.open(pid_file) do |f|
|
37
|
+
pid = f.gets.strip.to_i
|
38
|
+
return pid if pid > 0
|
39
|
+
end
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.start
|
44
|
+
return if @running
|
45
|
+
File.delete pid_file if File.exists? pid_file
|
46
|
+
Thread.new do
|
47
|
+
IO::popen "cd #{app_dir} && PID_FILE=#{pid_file} WS_PORT=#{ws_port} rackup config.ru -p #{port} > /dev/null 2>&1"
|
48
|
+
end
|
49
|
+
@running = true
|
50
|
+
100.times do
|
51
|
+
if File.exists? pid_file
|
52
|
+
sleep 2
|
53
|
+
return true
|
54
|
+
end
|
55
|
+
sleep 0.1
|
56
|
+
end
|
57
|
+
@running = false
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.stop
|
62
|
+
return unless @running
|
63
|
+
if File.exists? pid_file
|
64
|
+
system "kill -9 #{pid}"
|
65
|
+
File.delete pid_file
|
66
|
+
end
|
67
|
+
@running = false
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/test/app/config.ru
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'sinatra/base'
|
4
|
+
$stdout.sync = true
|
5
|
+
$:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
|
6
|
+
require 'sinatra/rocketio'
|
7
|
+
require File.dirname(__FILE__)+'/main'
|
8
|
+
|
9
|
+
set :websocketio, :port => ENV['WS_PORT'].to_i
|
10
|
+
|
11
|
+
run TestApp
|
data/test/app/main.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
pid_file = ENV['PID_FILE'] || "/tmp/sinatra-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
|
+
class TestApp < Sinatra::Base
|
12
|
+
register Sinatra::RocketIO
|
13
|
+
io = Sinatra::RocketIO
|
14
|
+
|
15
|
+
get '/' do
|
16
|
+
"sinatra-rocketio v#{Sinatra::RocketIO::VERSION}"
|
17
|
+
end
|
18
|
+
|
19
|
+
io.on :connect do |session, type|
|
20
|
+
puts "new client <session:#{session}> <type:#{type}>"
|
21
|
+
end
|
22
|
+
|
23
|
+
io.on :disconnect do |session, type|
|
24
|
+
puts "disconnect client <session:#{session}> <type:#{type}>"
|
25
|
+
end
|
26
|
+
|
27
|
+
io.on :broadcast do |data, from, type|
|
28
|
+
puts from
|
29
|
+
puts "broadcast <session:#{from}> <type:#{type}> - #{data.to_json}"
|
30
|
+
push :broadcast, data
|
31
|
+
end
|
32
|
+
|
33
|
+
io.on :message do |data, from, type|
|
34
|
+
puts "message <session:#{from}> <type:#{type}> - #{data.to_json}"
|
35
|
+
push :message, data, :to => data['to']
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'em-cometio-client'
|
6
|
+
require 'em-websocketio-client'
|
7
|
+
require File.expand_path 'app', File.dirname(__FILE__)
|
8
|
+
|
9
|
+
|
10
|
+
['SIGHUP', 'SIGINT', 'SIGKILL', 'SIGTERM'].each do |sig|
|
11
|
+
Kernel.trap sig do
|
12
|
+
App.stop
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestRocketIO < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
App.start
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
App.stop
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_websocket_to_comet
|
14
|
+
## websocket --> server --> comet
|
15
|
+
post_data = {:time => Time.now.to_s, :msg => 'hello!!', :to => nil}
|
16
|
+
res = nil
|
17
|
+
res2 = nil
|
18
|
+
EM::run do
|
19
|
+
client = EM::WebSocketIO::Client.new(App.websocketio_url).connect
|
20
|
+
client.on :message do |data|
|
21
|
+
res = data
|
22
|
+
end
|
23
|
+
|
24
|
+
client.on :disconnect do
|
25
|
+
EM.stop_event_loop
|
26
|
+
end
|
27
|
+
|
28
|
+
client.on :connect do |session|
|
29
|
+
client2 = EM::CometIO::Client.new(App.cometio_url).connect
|
30
|
+
client2.on :connect do |session2|
|
31
|
+
post_data['to'] = session2
|
32
|
+
client.push :message, post_data
|
33
|
+
end
|
34
|
+
client2.on :message do |data|
|
35
|
+
res2 = data
|
36
|
+
client2.close
|
37
|
+
client.close
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
EM::defer do
|
42
|
+
50.times do
|
43
|
+
break if res != nil
|
44
|
+
sleep 0.1
|
45
|
+
end
|
46
|
+
client.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
assert res2 != nil, 'server not respond'
|
50
|
+
assert res2["time"] == post_data[:time]
|
51
|
+
assert res2["msg"] == post_data[:msg]
|
52
|
+
assert res == nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_comet_to_websocket
|
56
|
+
## comet --> server --> websocket
|
57
|
+
post_data = {:time => Time.now.to_s, :msg => 'hello!!', :to => nil}
|
58
|
+
res = nil
|
59
|
+
res2 = nil
|
60
|
+
EM::run do
|
61
|
+
client = EM::CometIO::Client.new(App.cometio_url).connect
|
62
|
+
client.on :message do |data|
|
63
|
+
res = data
|
64
|
+
end
|
65
|
+
|
66
|
+
client.on :disconnect do
|
67
|
+
EM.stop_event_loop
|
68
|
+
end
|
69
|
+
|
70
|
+
client.on :connect do |session|
|
71
|
+
client2 = EM::WebSocketIO::Client.new(App.websocketio_url).connect
|
72
|
+
client2.on :connect do |session2|
|
73
|
+
post_data['to'] = session2
|
74
|
+
client.push :message, post_data
|
75
|
+
end
|
76
|
+
client2.on :message do |data|
|
77
|
+
res2 = data
|
78
|
+
client2.close
|
79
|
+
client.close
|
80
|
+
end
|
81
|
+
client2.on :disconnect do
|
82
|
+
EM.stop_event_loop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
EM::defer do
|
87
|
+
50.times do
|
88
|
+
break if res != nil
|
89
|
+
sleep 0.1
|
90
|
+
end
|
91
|
+
client.close
|
92
|
+
end
|
93
|
+
end
|
94
|
+
assert res2 != nil, 'server not respond'
|
95
|
+
assert res2["time"] == post_data[:time]
|
96
|
+
assert res2["msg"] == post_data[:msg]
|
97
|
+
assert res == nil
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.5.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: sinatra
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 1.3.6
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 1.3.6
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: eventmachine
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 1.0.0
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.0.0
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: event_emitter
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 0.2.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 0.2.3
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: sinatra-contrib
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: 1.3.2
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: 1.3.2
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: sinatra-cometio
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 0.3.4
|
102
102
|
type: :runtime
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 0.3.4
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: sinatra-websocketio
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.1.2
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.1.2
|
126
126
|
description: Node.js like WebSocket/Comet I/O plugin for Sinatra
|
127
127
|
email:
|
128
128
|
- hashimoto@shokai.org
|
@@ -157,6 +157,11 @@ files:
|
|
157
157
|
- sample/views/index.haml
|
158
158
|
- sample/views/main.scss
|
159
159
|
- sinatra-rocketio.gemspec
|
160
|
+
- test/app.rb
|
161
|
+
- test/app/config.ru
|
162
|
+
- test/app/main.rb
|
163
|
+
- test/test_helper.rb
|
164
|
+
- test/test_rocketio.rb
|
160
165
|
homepage: https://github.com/shokai/sinatra-rocketio
|
161
166
|
licenses: []
|
162
167
|
post_install_message:
|
@@ -181,4 +186,9 @@ rubygems_version: 1.8.24
|
|
181
186
|
signing_key:
|
182
187
|
specification_version: 3
|
183
188
|
summary: Node.js like WebSocket/Comet I/O plugin for Sinatra
|
184
|
-
test_files:
|
189
|
+
test_files:
|
190
|
+
- test/app.rb
|
191
|
+
- test/app/config.ru
|
192
|
+
- test/app/main.rb
|
193
|
+
- test/test_helper.rb
|
194
|
+
- test/test_rocketio.rb
|