sinatra-rocketio 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/Gemfile +1 -0
- data/History.txt +4 -0
- data/README.md +1 -0
- data/lib/js/rocketio.js +9 -1
- data/lib/sinatra/rocketio.rb +1 -2
- data/lib/sinatra-rocketio/application.rb +17 -6
- data/lib/sinatra-rocketio/javascript.rb +2 -2
- data/lib/sinatra-rocketio/options.rb +2 -0
- data/lib/sinatra-rocketio/rocketio.rb +21 -13
- data/lib/sinatra-rocketio/version.rb +1 -1
- data/sample/Gemfile +2 -1
- data/sample/Gemfile.lock +2 -1
- data/sample/config.ru +1 -0
- data/sinatra-rocketio.gemspec +2 -1
- metadata +19 -3
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
data/lib/js/rocketio.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
var RocketIO = function(){
|
2
2
|
new EventEmitter().apply(this);
|
3
|
-
this.type = null; // comet, websocket
|
3
|
+
this.type = null; // "comet", "websocket"
|
4
4
|
this.session = null;
|
5
5
|
this.io = null;
|
6
6
|
var self = this;
|
@@ -9,14 +9,22 @@ var RocketIO = function(){
|
|
9
9
|
this.connect = function(){
|
10
10
|
self.io = function(){
|
11
11
|
if(self.type === "comet") return;
|
12
|
+
if(typeof WebSocketIO === "undefined") return;
|
12
13
|
var io = new WebSocketIO();
|
13
14
|
io.session = self.session;
|
14
15
|
return io.connect();
|
15
16
|
}() || function(){
|
17
|
+
if(typeof CometIO === "undefined") return;
|
16
18
|
var io = new CometIO();
|
17
19
|
io.session = self.session;
|
18
20
|
return io.connect();
|
19
21
|
}();
|
22
|
+
if(typeof self.io === "undefined"){
|
23
|
+
setTimeout(function(){
|
24
|
+
self.emit("error", "WebSocketIO and CometIO are not available")
|
25
|
+
}, 100);
|
26
|
+
return self;
|
27
|
+
};
|
20
28
|
if(self.io.url.match(/^ws:\/\/.+/)) self.type = "websocket";
|
21
29
|
else if(self.io.url.match(/cometio/)) self.type = "comet";
|
22
30
|
else self.type = "unknown";
|
data/lib/sinatra/rocketio.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'eventmachine'
|
2
|
-
require '
|
3
|
-
require 'sinatra/websocketio'
|
2
|
+
require 'event_emitter'
|
4
3
|
require File.expand_path '../sinatra-rocketio/version', File.dirname(__FILE__)
|
5
4
|
require File.expand_path '../sinatra-rocketio/helpers', File.dirname(__FILE__)
|
6
5
|
require File.expand_path '../sinatra-rocketio/options', File.dirname(__FILE__)
|
@@ -2,13 +2,24 @@ module Sinatra
|
|
2
2
|
module RocketIO
|
3
3
|
|
4
4
|
def self.registered(app)
|
5
|
-
app.register Sinatra::CometIO
|
6
|
-
app.register Sinatra::WebSocketIO
|
7
5
|
app.helpers Sinatra::RocketIO::Helpers
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
EM::defer do
|
7
|
+
while !EM::reactor_running? do
|
8
|
+
sleep 1
|
9
|
+
end
|
10
|
+
if options[:comet]
|
11
|
+
require 'sinatra/cometio'
|
12
|
+
app.register Sinatra::CometIO
|
13
|
+
end
|
14
|
+
if options[:websocket]
|
15
|
+
require 'sinatra/websocketio'
|
16
|
+
app.register Sinatra::WebSocketIO
|
17
|
+
end
|
18
|
+
app.get '/rocketio/rocketio.js' do
|
19
|
+
content_type 'application/javascript'
|
20
|
+
@js ||= ERB.new(Sinatra::RocketIO.javascript).result(binding)
|
21
|
+
end
|
22
|
+
Sinatra::RocketIO.emit :regist_events
|
12
23
|
end
|
13
24
|
end
|
14
25
|
|
@@ -7,9 +7,9 @@ module Sinatra
|
|
7
7
|
js_file_names.each do |i|
|
8
8
|
js += case i
|
9
9
|
when 'cometio.js'
|
10
|
-
Sinatra::CometIO.javascript
|
10
|
+
options[:comet] ? Sinatra::CometIO.javascript('cometio.js') : ''
|
11
11
|
when 'websocketio.js'
|
12
|
-
Sinatra::WebSocketIO.javascript
|
12
|
+
options[:websocket] ? Sinatra::WebSocketIO.javascript('websocketio.js') : ''
|
13
13
|
else
|
14
14
|
j = ''
|
15
15
|
File.open(File.expand_path "../js/#{i}", File.dirname(__FILE__)) do |f|
|
@@ -2,8 +2,8 @@ module Sinatra
|
|
2
2
|
module RocketIO
|
3
3
|
|
4
4
|
def self.push(type, data, opt={})
|
5
|
-
Sinatra::CometIO.push type, data, opt
|
6
|
-
Sinatra::WebSocketIO.push type, data, opt
|
5
|
+
Sinatra::CometIO.push type, data, opt if options[:comet]
|
6
|
+
Sinatra::WebSocketIO.push type, data, opt if options[:websocket]
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.sessions
|
@@ -15,18 +15,26 @@ module Sinatra
|
|
15
15
|
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
18
19
|
EventEmitter.apply Sinatra::RocketIO
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
|
21
|
+
Sinatra::RocketIO.once :regist_events do
|
22
|
+
if options[:comet]
|
23
|
+
Sinatra::CometIO.on :* do |event_name, *args|
|
24
|
+
if args.size > 1
|
25
|
+
Sinatra::RocketIO.emit event_name, args[0], args[1], :comet
|
26
|
+
else
|
27
|
+
Sinatra::RocketIO.emit event_name, args[0], :comet
|
28
|
+
end
|
29
|
+
end
|
24
30
|
end
|
25
|
-
|
26
|
-
Sinatra::WebSocketIO.on :* do |event_name, *args|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
if options[:websocket]
|
32
|
+
Sinatra::WebSocketIO.on :* do |event_name, *args|
|
33
|
+
if args.size > 1
|
34
|
+
Sinatra::RocketIO.emit event_name, args[0], args[1], :websocket
|
35
|
+
else
|
36
|
+
Sinatra::RocketIO.emit event_name, args[0], :websocket
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
data/sample/Gemfile
CHANGED
data/sample/Gemfile.lock
CHANGED
data/sample/config.ru
CHANGED
data/sinatra-rocketio.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.version = Sinatra::RocketIO::VERSION
|
8
8
|
gem.authors = ["Sho Hashimoto"]
|
9
9
|
gem.email = ["hashimoto@shokai.org"]
|
10
|
-
gem.description = %q{Node.js like I/O plugin for Sinatra}
|
10
|
+
gem.description = %q{Node.js like WebSocket/Comet I/O plugin for Sinatra}
|
11
11
|
gem.summary = gem.description
|
12
12
|
gem.homepage = "https://github.com/shokai/sinatra-rocketio"
|
13
13
|
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency "rack"
|
19
19
|
gem.add_dependency "sinatra"
|
20
20
|
gem.add_dependency "eventmachine"
|
21
|
+
gem.add_dependency "event_emitter"
|
21
22
|
gem.add_dependency "sinatra-contrib"
|
22
23
|
gem.add_dependency "sinatra-cometio"
|
23
24
|
gem.add_dependency "sinatra-websocketio"
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: event_emitter
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: sinatra-contrib
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +123,7 @@ dependencies:
|
|
107
123
|
- - ! '>='
|
108
124
|
- !ruby/object:Gem::Version
|
109
125
|
version: '0'
|
110
|
-
description: Node.js like I/O plugin for Sinatra
|
126
|
+
description: Node.js like WebSocket/Comet I/O plugin for Sinatra
|
111
127
|
email:
|
112
128
|
- hashimoto@shokai.org
|
113
129
|
executables: []
|
@@ -164,5 +180,5 @@ rubyforge_project:
|
|
164
180
|
rubygems_version: 1.8.24
|
165
181
|
signing_key:
|
166
182
|
specification_version: 3
|
167
|
-
summary: Node.js like I/O plugin for Sinatra
|
183
|
+
summary: Node.js like WebSocket/Comet I/O plugin for Sinatra
|
168
184
|
test_files: []
|