sinatra-cometio 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.md +4 -0
- data/lib/sinatra-cometio/version.rb +1 -1
- data/lib/sinatra/application.rb +1 -1
- data/lib/sinatra/cometio.rb +3 -2
- data/sample/main.rb +4 -0
- metadata +2 -2
data/History.txt
CHANGED
data/README.md
CHANGED
data/lib/sinatra/application.rb
CHANGED
@@ -27,7 +27,7 @@ module Sinatra
|
|
27
27
|
|
28
28
|
get '/cometio/io' do
|
29
29
|
stream :keep_open do |s|
|
30
|
-
session = params[:session].to_s.empty? ? CometIO.create_session : params[:session]
|
30
|
+
session = params[:session].to_s.empty? ? CometIO.create_session(request.ip) : params[:session]
|
31
31
|
CometIO.sessions[session][:stream] = s
|
32
32
|
CometIO.sessions[session][:last] = Time.now
|
33
33
|
CometIO.emit :connect, session if params[:session].to_s.empty?
|
data/lib/sinatra/cometio.rb
CHANGED
@@ -21,6 +21,7 @@ class CometIO
|
|
21
21
|
self.sessions.each do |id, s|
|
22
22
|
next unless s[:last] and s[:last] < Time.now-60
|
23
23
|
self.sessions.delete id rescue next
|
24
|
+
self.emit :disconnect, id
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -52,8 +53,8 @@ class CometIO
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
|
-
def self.create_session
|
56
|
-
Digest::MD5.hexdigest "#{Time.now.to_i}_#{Time.now.usec}"
|
56
|
+
def self.create_session(ip_addr)
|
57
|
+
Digest::MD5.hexdigest "#{Time.now.to_i}_#{Time.now.usec}_#{ip_addr}"
|
57
58
|
end
|
58
59
|
end
|
59
60
|
EventEmitter.apply CometIO
|
data/sample/main.rb
CHANGED
@@ -9,6 +9,10 @@ CometIO.on :connect do |session|
|
|
9
9
|
CometIO.push :chat, {:name => "system", :message => "welcome <#{session}>"}, {:to => session}
|
10
10
|
end
|
11
11
|
|
12
|
+
CometIO.on :disconnect do |session|
|
13
|
+
puts "disconnect client <#{session}>"
|
14
|
+
end
|
15
|
+
|
12
16
|
EM::defer do
|
13
17
|
loop do
|
14
18
|
CometIO.push :chat, :name => 'clock', :message => Time.now.to_s
|
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.1.
|
4
|
+
version: 0.1.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-02-
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|