sinatra-cometio 0.3.1 → 0.3.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/History.txt +4 -0
- data/README.md +10 -8
- data/lib/sinatra-cometio/application.rb +1 -1
- data/lib/sinatra-cometio/version.rb +1 -1
- data/sample/main.rb +5 -4
- metadata +2 -2
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -34,8 +34,10 @@ set :cometio, :timeout => 120
|
|
34
34
|
run Sinatra::Application
|
35
35
|
```
|
36
36
|
```ruby
|
37
|
-
|
38
|
-
|
37
|
+
io = Sinatra::CometIO
|
38
|
+
|
39
|
+
io.push :temperature, 35 # to all clients
|
40
|
+
io.push :light, {:value => 150}, {:to => session_id} # to specific client
|
39
41
|
```
|
40
42
|
|
41
43
|
Client Side
|
@@ -66,7 +68,7 @@ io.push("chat", {name: "shokai", message: "hello"}); // client -> server
|
|
66
68
|
Server Side
|
67
69
|
|
68
70
|
```ruby
|
69
|
-
|
71
|
+
io.on :chat do |data, session|
|
70
72
|
puts "#{data['name']} : #{data['message']} <#{session}>"
|
71
73
|
end
|
72
74
|
## => "shokai : hello <12abcde345f6g7h8ijk>"
|
@@ -85,11 +87,11 @@ io.on("connect", function(session){
|
|
85
87
|
Server Side
|
86
88
|
|
87
89
|
```ruby
|
88
|
-
|
90
|
+
io.on :connect do |session|
|
89
91
|
puts "new client <#{session}>"
|
90
92
|
end
|
91
93
|
|
92
|
-
|
94
|
+
io.on :disconnect do |session|
|
93
95
|
puts "client disconnected <#{session}>"
|
94
96
|
end
|
95
97
|
```
|
@@ -109,16 +111,16 @@ io.on("error", function(err){
|
|
109
111
|
Server Side
|
110
112
|
|
111
113
|
```ruby
|
112
|
-
event_id =
|
114
|
+
event_id = io.on :chat do |data, from|
|
113
115
|
puts "#{data} - from#{from}"
|
114
116
|
end
|
115
|
-
|
117
|
+
io.removeListener event_id
|
116
118
|
```
|
117
119
|
|
118
120
|
or
|
119
121
|
|
120
122
|
```ruby
|
121
|
-
|
123
|
+
io.removeListener :chat # remove all "chat" listener
|
122
124
|
```
|
123
125
|
|
124
126
|
|
data/sample/main.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
class ChatApp < Sinatra::Base
|
2
2
|
register Sinatra::CometIO
|
3
|
+
io = Sinatra::CometIO
|
3
4
|
|
4
|
-
|
5
|
+
io.on :chat do |data, from|
|
5
6
|
puts "#{data['name']} : #{data['message']} (from:#{from})"
|
6
7
|
push :chat, data
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
io.on :connect do |session|
|
10
11
|
puts "new client <#{session}>"
|
11
12
|
push :chat, {:name => "system", :message => "new client <#{session}>"}
|
12
13
|
push :chat, {:name => "system", :message => "welcome <#{session}>"}, {:to => session}
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
io.on :disconnect do |session|
|
16
17
|
puts "disconnect client <#{session}>"
|
17
18
|
push :chat, {:name => "system", :message => "bye <#{session}>"}
|
18
19
|
end
|
19
20
|
|
20
21
|
EM::defer do
|
21
22
|
loop do
|
22
|
-
|
23
|
+
io.push :chat, :name => 'clock', :message => Time.now.to_s
|
23
24
|
sleep 60
|
24
25
|
end
|
25
26
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|