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 CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.2 2013-2-17
2
+
3
+ * emit event when client disconnect
4
+ * create session_ID from IP Addr
5
+
1
6
  === 0.1.1 2013-2-7
2
7
 
3
8
  * fix
data/README.md CHANGED
@@ -83,6 +83,10 @@ Server Side
83
83
  CometIO.on :connect do |session|
84
84
  puts "new client <#{session}>"
85
85
  end
86
+
87
+ CometIO.on :disconnect do |session|
88
+ puts "client disconnected <#{session}>"
89
+ end
86
90
  ```
87
91
 
88
92
  ### On "error" Event
@@ -1,3 +1,3 @@
1
1
  module SinatraCometIO
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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?
@@ -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.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-07 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack