sinatra-cometio 0.0.8 → 0.0.9
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/.gitignore +22 -3
- data/Gemfile +3 -4
- data/History.txt +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +145 -0
- data/Rakefile +1 -29
- data/lib/{sinatra-cometio.rb → sinatra-cometio/version.rb} +1 -1
- data/lib/sinatra/cometio.rb +1 -1
- data/sinatra-cometio.gemspec +25 -0
- metadata +28 -76
- data/.gemtest +0 -0
- data/Gemfile.lock +0 -33
- data/README.rdoc +0 -136
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/test/test_helper.rb +0 -3
- data/test/test_sinatra-cometio.rb +0 -11
data/.gitignore
CHANGED
@@ -1,4 +1,23 @@
|
|
1
|
-
|
1
|
+
.DS_Store
|
2
|
+
*.tmp
|
2
3
|
*~
|
3
|
-
|
4
|
-
|
4
|
+
*#*
|
5
|
+
vendor
|
6
|
+
.sass-cache
|
7
|
+
.bundle
|
8
|
+
config.yml
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
.config
|
12
|
+
.yardoc
|
13
|
+
InstalledFiles
|
14
|
+
_yardoc
|
15
|
+
coverage
|
16
|
+
doc/
|
17
|
+
lib/bundler/man
|
18
|
+
pkg
|
19
|
+
rdoc
|
20
|
+
spec/reports
|
21
|
+
test/tmp
|
22
|
+
test/version_tmp
|
23
|
+
tmp
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sho Hashimoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
sinatra-cometio
|
2
|
+
===============
|
3
|
+
|
4
|
+
* Node.js like Comet I/O plugin for Sinatra.
|
5
|
+
* http://shokai.github.com/sinatra-cometio
|
6
|
+
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
% gem install sinatra-cometio
|
12
|
+
|
13
|
+
|
14
|
+
Requirements
|
15
|
+
------------
|
16
|
+
* Ruby 1.8.7+ or 1.9.2+
|
17
|
+
* Sinatra 1.3.0+
|
18
|
+
* EventMachine
|
19
|
+
* jQuery
|
20
|
+
|
21
|
+
|
22
|
+
Usage
|
23
|
+
-----
|
24
|
+
|
25
|
+
### Server --(Comet)--> Client
|
26
|
+
|
27
|
+
Server Side
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'sinatra'
|
31
|
+
require 'sinatra/cometio'
|
32
|
+
CometIO.push :temperature, 35 # to all clients
|
33
|
+
CometIO.push :light, {:value => 150}, {:to => session_id} # to specific client
|
34
|
+
```
|
35
|
+
|
36
|
+
Client Side
|
37
|
+
|
38
|
+
```html
|
39
|
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
40
|
+
<script src="<%= cometio_js %>"></script>
|
41
|
+
```
|
42
|
+
```javascript
|
43
|
+
var io = new CometIO().connect();
|
44
|
+
io.on("temperature", function(value){
|
45
|
+
console.log("server temperature : " + value);
|
46
|
+
}); // => "server temperature : 35"
|
47
|
+
io.on("light", function(data){
|
48
|
+
console.log("server light sensor : " + data.value);
|
49
|
+
}); // => "server light sensor : 150"
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
### Client --(Ajax)--> Server
|
54
|
+
|
55
|
+
Client Side
|
56
|
+
|
57
|
+
```javascript
|
58
|
+
io.push("chat", {name: "shokai", message: "hello"}); // client -> server
|
59
|
+
```
|
60
|
+
|
61
|
+
Server Side
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
CometIO.on :chat do |data, session|
|
65
|
+
puts "#{data['name']} : #{data['message']} <#{session}>"
|
66
|
+
end
|
67
|
+
## => "shokai : hello <12abcde345f6g7h8ijk>"
|
68
|
+
```
|
69
|
+
|
70
|
+
### On "connect" Event
|
71
|
+
|
72
|
+
Client Side
|
73
|
+
|
74
|
+
```javascript
|
75
|
+
io.on("connect", function(session){
|
76
|
+
alert("connect!!");
|
77
|
+
});
|
78
|
+
```
|
79
|
+
|
80
|
+
Server Side
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
CometIO.on :connect do |session|
|
84
|
+
puts "new client <#{session}>"
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### On "error" Event
|
89
|
+
|
90
|
+
Client Side
|
91
|
+
|
92
|
+
```javascript
|
93
|
+
io.on("error", function(err){
|
94
|
+
console.error(err);
|
95
|
+
});
|
96
|
+
```
|
97
|
+
|
98
|
+
### Remove Event Listener
|
99
|
+
|
100
|
+
Server Side
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
event_id = CometIO.on :chat do |data, from|
|
104
|
+
puts "#{data} - from#{from}"
|
105
|
+
end
|
106
|
+
CometIO.removeListener event_id
|
107
|
+
```
|
108
|
+
|
109
|
+
or
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
CometIO.removeListener :chat # remove all "chat" listener
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
Client Side
|
117
|
+
|
118
|
+
```javascript
|
119
|
+
var event_id = io.on("error", function(err){
|
120
|
+
console.error("CometIO error : "err);
|
121
|
+
});
|
122
|
+
io.removeListener(event_id);
|
123
|
+
```
|
124
|
+
|
125
|
+
or
|
126
|
+
|
127
|
+
```javascript
|
128
|
+
io.removeListener("error"); // remove all "error" listener
|
129
|
+
```
|
130
|
+
|
131
|
+
Sample App
|
132
|
+
----------
|
133
|
+
chat app
|
134
|
+
|
135
|
+
- http://cometio-chat.herokuapp.com
|
136
|
+
- https://github.com/shokai/sinatra-cometio/tree/master/sample
|
137
|
+
|
138
|
+
|
139
|
+
Contributing
|
140
|
+
------------
|
141
|
+
1. Fork it
|
142
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
143
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
144
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
145
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,29 +1 @@
|
|
1
|
-
require
|
2
|
-
gem 'hoe', '>= 3.1.0'
|
3
|
-
require 'hoe'
|
4
|
-
require 'fileutils'
|
5
|
-
require './lib/sinatra-cometio'
|
6
|
-
|
7
|
-
Hoe.plugin :newgem
|
8
|
-
# Hoe.plugin :website
|
9
|
-
# Hoe.plugin :cucumberfeatures
|
10
|
-
|
11
|
-
# Generate all the Rake tasks
|
12
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec 'sinatra-cometio' do
|
14
|
-
self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
|
15
|
-
self.rubyforge_name = self.name # TODO this is default value
|
16
|
-
self.extra_deps = [['sinatra','>= 1.3.3'],
|
17
|
-
['eventmachine', '>= 1.0.0'],
|
18
|
-
['json', '>= 1.7.0'],
|
19
|
-
['sinatra-contrib', '>= 1.3.2'],
|
20
|
-
['event_emitter', '>= 0.1.0']]
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'newgem/tasks'
|
25
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
-
|
27
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
-
# remove_task :default
|
29
|
-
# task :default => [:spec, :features]
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/sinatra/cometio.rb
CHANGED
@@ -4,7 +4,7 @@ require 'digest/md5'
|
|
4
4
|
require 'event_emitter'
|
5
5
|
require 'sinatra/streaming'
|
6
6
|
require File.expand_path 'application', File.dirname(__FILE__)
|
7
|
-
require File.expand_path '../sinatra-cometio', File.dirname(__FILE__)
|
7
|
+
require File.expand_path '../sinatra-cometio/version', File.dirname(__FILE__)
|
8
8
|
|
9
9
|
class CometIO
|
10
10
|
def self.sessions
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'sinatra-cometio/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "sinatra-cometio"
|
7
|
+
gem.version = SinatraCometio::VERSION
|
8
|
+
gem.authors = ["Sho Hashimoto"]
|
9
|
+
gem.email = ["hashimoto@shokai.org"]
|
10
|
+
gem.description = %q{Node.js like Comet I/O plugin for Sinatra.}
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.homepage = "http://shokai.github.com/sinatra-cometio"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency 'rack'
|
20
|
+
gem.add_dependency 'sinatra', '>= 1.3.3'
|
21
|
+
gem.add_dependency 'eventmachine', '>= 1.0.0'
|
22
|
+
gem.add_dependency 'sinatra-contrib', '>= 1.3.2'
|
23
|
+
gem.add_dependency 'json', '>= 1.7.0'
|
24
|
+
gem.add_dependency 'event_emitter', '>= 0.1.0'
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-cometio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: rack
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,15 +26,15 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: sinatra
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
37
|
+
version: 1.3.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,15 +42,15 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 1.3.3
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: eventmachine
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
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: 1.
|
61
|
+
version: 1.0.0
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: sinatra-contrib
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,13 +76,13 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.3.2
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: json
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: 1.7.0
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,76 +90,40 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: rdoc
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '3.10'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '3.10'
|
93
|
+
version: 1.7.0
|
110
94
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
95
|
+
name: event_emitter
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|
113
97
|
none: false
|
114
98
|
requirements:
|
115
99
|
- - ! '>='
|
116
100
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
118
|
-
type: :
|
101
|
+
version: 0.1.0
|
102
|
+
type: :runtime
|
119
103
|
prerelease: false
|
120
104
|
version_requirements: !ruby/object:Gem::Requirement
|
121
105
|
none: false
|
122
106
|
requirements:
|
123
107
|
- - ! '>='
|
124
108
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.
|
126
|
-
|
127
|
-
name: hoe
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '3.2'
|
134
|
-
type: :development
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
|
-
requirements:
|
139
|
-
- - ~>
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '3.2'
|
142
|
-
description: Node.js like Comet I/O plugin for Sinatra
|
109
|
+
version: 0.1.0
|
110
|
+
description: Node.js like Comet I/O plugin for Sinatra.
|
143
111
|
email:
|
144
112
|
- hashimoto@shokai.org
|
145
113
|
executables: []
|
146
114
|
extensions: []
|
147
|
-
extra_rdoc_files:
|
148
|
-
- History.txt
|
149
|
-
- Manifest.txt
|
150
|
-
- PostInstall.txt
|
151
|
-
- README.rdoc
|
115
|
+
extra_rdoc_files: []
|
152
116
|
files:
|
153
117
|
- .gitignore
|
154
118
|
- Gemfile
|
155
|
-
- Gemfile.lock
|
156
119
|
- History.txt
|
120
|
+
- LICENSE.txt
|
157
121
|
- Manifest.txt
|
158
122
|
- PostInstall.txt
|
159
|
-
- README.
|
123
|
+
- README.md
|
160
124
|
- Rakefile
|
161
125
|
- lib/js/cometio.js
|
162
|
-
- lib/sinatra-cometio.rb
|
126
|
+
- lib/sinatra-cometio/version.rb
|
163
127
|
- lib/sinatra/application.rb
|
164
128
|
- lib/sinatra/cometio.rb
|
165
129
|
- sample/.gitignore
|
@@ -172,18 +136,11 @@ files:
|
|
172
136
|
- sample/public/js/index.js
|
173
137
|
- sample/views/index.haml
|
174
138
|
- sample/views/main.scss
|
175
|
-
-
|
176
|
-
- script/destroy
|
177
|
-
- script/generate
|
178
|
-
- test/test_helper.rb
|
179
|
-
- test/test_sinatra-cometio.rb
|
180
|
-
- .gemtest
|
139
|
+
- sinatra-cometio.gemspec
|
181
140
|
homepage: http://shokai.github.com/sinatra-cometio
|
182
141
|
licenses: []
|
183
142
|
post_install_message:
|
184
|
-
rdoc_options:
|
185
|
-
- --main
|
186
|
-
- README.rdoc
|
143
|
+
rdoc_options: []
|
187
144
|
require_paths:
|
188
145
|
- lib
|
189
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -192,9 +149,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
149
|
- - ! '>='
|
193
150
|
- !ruby/object:Gem::Version
|
194
151
|
version: '0'
|
195
|
-
segments:
|
196
|
-
- 0
|
197
|
-
hash: -4407411256198505630
|
198
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
153
|
none: false
|
200
154
|
requirements:
|
@@ -202,11 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
156
|
- !ruby/object:Gem::Version
|
203
157
|
version: '0'
|
204
158
|
requirements: []
|
205
|
-
rubyforge_project:
|
159
|
+
rubyforge_project:
|
206
160
|
rubygems_version: 1.8.24
|
207
161
|
signing_key:
|
208
162
|
specification_version: 3
|
209
|
-
summary: Node.js like Comet I/O plugin for Sinatra
|
210
|
-
test_files:
|
211
|
-
- test/test_helper.rb
|
212
|
-
- test/test_sinatra-cometio.rb
|
163
|
+
summary: Node.js like Comet I/O plugin for Sinatra.
|
164
|
+
test_files: []
|
data/.gemtest
DELETED
File without changes
|
data/Gemfile.lock
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
RedCloth (4.2.9)
|
5
|
-
activesupport (2.3.14)
|
6
|
-
hoe (3.2.0)
|
7
|
-
rake (~> 0.8)
|
8
|
-
newgem (1.5.3)
|
9
|
-
RedCloth (>= 4.1.1)
|
10
|
-
activesupport (~> 2.3.4)
|
11
|
-
hoe (>= 2.4.0)
|
12
|
-
rubigen (>= 1.5.3)
|
13
|
-
syntax (>= 1.0.0)
|
14
|
-
rack (1.4.1)
|
15
|
-
rack-protection (1.2.0)
|
16
|
-
rack
|
17
|
-
rake (0.9.2.2)
|
18
|
-
rubigen (1.5.8)
|
19
|
-
activesupport (>= 2.3.5, < 3.2.0)
|
20
|
-
sinatra (1.3.3)
|
21
|
-
rack (~> 1.3, >= 1.3.6)
|
22
|
-
rack-protection (~> 1.2)
|
23
|
-
tilt (~> 1.3, >= 1.3.3)
|
24
|
-
syntax (1.0.0)
|
25
|
-
tilt (1.3.3)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
hoe
|
32
|
-
newgem
|
33
|
-
sinatra
|
data/README.rdoc
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
= sinatra-cometio
|
2
|
-
|
3
|
-
* http://shokai.github.com/sinatra-cometio
|
4
|
-
|
5
|
-
== INSTALL:
|
6
|
-
|
7
|
-
* gem install sinatra-cometio
|
8
|
-
|
9
|
-
== DESCRIPTION:
|
10
|
-
|
11
|
-
Node.js like Comet I/O plugin for Sinatra
|
12
|
-
|
13
|
-
== REQUIREMENTS:
|
14
|
-
|
15
|
-
* Ruby 1.8.7+ or 1.9.2+
|
16
|
-
* Sinatra 1.3.0+
|
17
|
-
* EventMachine
|
18
|
-
* jQuery
|
19
|
-
|
20
|
-
== SYNOPSIS:
|
21
|
-
|
22
|
-
=== Server --(Comet)--> Client
|
23
|
-
|
24
|
-
Server Side
|
25
|
-
|
26
|
-
require 'sinatra'
|
27
|
-
require 'sinatra/cometio'
|
28
|
-
CometIO.push :temperature, 35 # to all clients
|
29
|
-
CometIO.push :light, {:value => 150}, {:to => session_id} # to specific client
|
30
|
-
|
31
|
-
Client Side
|
32
|
-
|
33
|
-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
34
|
-
<script src="<%= cometio_js %>"></script>
|
35
|
-
|
36
|
-
var io = new CometIO().connect();
|
37
|
-
io.on("temperature", function(value){
|
38
|
-
console.log("server temperature : " + value);
|
39
|
-
}); // => "server temperature : 35"
|
40
|
-
io.on("light", function(data){
|
41
|
-
console.log("server light sensor : + data.value);
|
42
|
-
}); // => "server light sensor : 150"
|
43
|
-
|
44
|
-
=== Client --(Ajax)--> Server
|
45
|
-
|
46
|
-
Client Side
|
47
|
-
|
48
|
-
io.push("chat", {name: "shokai", message: "hello"}); // client -> server
|
49
|
-
|
50
|
-
Server Side
|
51
|
-
|
52
|
-
CometIO.on :chat do |data, session|
|
53
|
-
puts "#{data['name']} : #{data['message']} <#{session}>"
|
54
|
-
end
|
55
|
-
## => "shokai : hello <12abcde345f6g7h8ijk>"
|
56
|
-
|
57
|
-
=== On "connect" Event
|
58
|
-
|
59
|
-
Client Side
|
60
|
-
|
61
|
-
io.on("connect", function(session){
|
62
|
-
alert("connect!!");
|
63
|
-
});
|
64
|
-
|
65
|
-
Server Side
|
66
|
-
|
67
|
-
CometIO.on :connect do |session|
|
68
|
-
puts "new client <#{session}>"
|
69
|
-
end
|
70
|
-
|
71
|
-
=== On "error" Event
|
72
|
-
|
73
|
-
Client Side
|
74
|
-
|
75
|
-
io.on("error", function(err){
|
76
|
-
console.error(err);
|
77
|
-
});
|
78
|
-
|
79
|
-
|
80
|
-
=== Remove Event Listener
|
81
|
-
|
82
|
-
Server Side
|
83
|
-
|
84
|
-
event_id = CometIO.on :chat do |data, from|
|
85
|
-
puts "#{data} - from#{from}"
|
86
|
-
end
|
87
|
-
CometIO.removeListener event_id
|
88
|
-
|
89
|
-
or
|
90
|
-
|
91
|
-
CometIO.removeListener :chat # remove all "chat" listener
|
92
|
-
|
93
|
-
|
94
|
-
Client Side
|
95
|
-
|
96
|
-
var event_id = io.on("error", function(err){
|
97
|
-
console.error("CometIO error : "err);
|
98
|
-
});
|
99
|
-
io.removeListener(event_id);
|
100
|
-
|
101
|
-
or
|
102
|
-
|
103
|
-
io.removeListener("error"); // remove all "error" listener
|
104
|
-
|
105
|
-
== Sample App
|
106
|
-
|
107
|
-
chat app
|
108
|
-
|
109
|
-
- http://cometio-chat.herokuapp.com
|
110
|
-
- https://github.com/shokai/sinatra-cometio/tree/master/sample
|
111
|
-
|
112
|
-
|
113
|
-
== LICENSE:
|
114
|
-
|
115
|
-
(The MIT License)
|
116
|
-
|
117
|
-
Copyright (c) 2012 Sho Hashimoto
|
118
|
-
|
119
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
120
|
-
a copy of this software and associated documentation files (the
|
121
|
-
'Software'), to deal in the Software without restriction, including
|
122
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
123
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
124
|
-
permit persons to whom the Software is furnished to do so, subject to
|
125
|
-
the following conditions:
|
126
|
-
|
127
|
-
The above copyright notice and this permission notice shall be
|
128
|
-
included in all copies or substantial portions of the Software.
|
129
|
-
|
130
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
131
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
132
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
133
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
134
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
135
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
136
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/sinatra-cometio.rb'}"
|
9
|
-
puts "Loading sinatra-cometio gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
DELETED