sinatra-cometio 0.1.6 → 0.1.7

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 CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.7 2013-3-3
2
+
3
+ * bugfix CometIO Ruby client
4
+ * change config key xhr_interval -> timeout
5
+
1
6
  === 0.1.6 2013-3-3
2
7
 
3
8
  * add IO close function - CometIO.close()
data/README.md CHANGED
@@ -141,7 +141,7 @@ require 'sinatra'
141
141
  require 'sinatra/cometio'
142
142
  require File.dirname(__FILE__)+'/main'
143
143
 
144
- set :cometio, :xhr_interval => 20
144
+ set :cometio, :timeout => 60
145
145
 
146
146
  run Sinatra::Application
147
147
  ```
data/lib/js/cometio.js CHANGED
@@ -60,7 +60,7 @@ var CometIO = function(){
60
60
  },
61
61
  type : "GET",
62
62
  dataType : "json",
63
- timeout : <%= (CometIO.options[:xhr_interval]+10)*1000 %>
63
+ timeout : <%= (CometIO.options[:timeout]+10)*1000 %>
64
64
  }
65
65
  );
66
66
  };
@@ -48,7 +48,7 @@ module Sinatra::CometIO
48
48
  end
49
49
  end
50
50
 
51
- EM::add_timer CometIO.options[:xhr_interval] do
51
+ EM::add_timer CometIO.options[:timeout] do
52
52
  begin
53
53
  s.write({:type => :__heartbeat, :data => {:time => Time.now.to_i}}.to_json)
54
54
  s.flush
@@ -2,7 +2,7 @@ class CometIO
2
2
 
3
3
  def self.default_options
4
4
  {
5
- :xhr_interval => [15, lambda{|v| v.kind_of? Fixnum and v >= 10 }]
5
+ :timeout => [120, lambda{|v| v.kind_of? Fixnum and v >= 20 }]
6
6
  }
7
7
  end
8
8
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module CometIO
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
@@ -21,7 +21,7 @@ class CometIO
21
21
 
22
22
  def self.gc
23
23
  self.sessions.each do |id, s|
24
- next unless s[:last] and s[:last] < Time.now-CometIO.options[:xhr_interval]*2-10
24
+ next unless s[:last] and s[:last] < Time.now-CometIO.options[:timeout]*2-10
25
25
  self.sessions.delete id rescue next
26
26
  self.emit :disconnect, id
27
27
  end
@@ -30,7 +30,7 @@ class CometIO
30
30
  EM::defer do
31
31
  loop do
32
32
  self.gc
33
- sleep CometIO.options[:xhr_interval]+5
33
+ sleep CometIO.options[:timeout]+5
34
34
  end
35
35
  end
36
36
 
@@ -20,11 +20,10 @@ class CometIO
20
20
 
21
21
  def push(type, data)
22
22
  begin
23
- res = HTTParty.post @url, :body => {:type => type, :data => data, :session => @session}
23
+ res = HTTParty.post @url, :timeout => 10, :body => {:type => type, :data => data, :session => @session}
24
+ emit :error, "CometIO push error" unless res.code == 200
24
25
  rescue StandardError, Timeout::Error => e
25
26
  emit :error, "CometIO push error"
26
- ensure
27
- emit :error, "CometIO push error" unless res.code == 200
28
27
  end
29
28
  end
30
29
 
@@ -49,7 +48,7 @@ class CometIO
49
48
  Thread.new do
50
49
  while @running do
51
50
  begin
52
- res = HTTParty.get "#{@url}?session=#{@session}", :timeout => 60000
51
+ res = HTTParty.get "#{@url}?session=#{@session}", :timeout => 120
53
52
  unless res.code == 200
54
53
  self.emit :error, "CometIO get error"
55
54
  sleep 10
@@ -57,9 +56,12 @@ class CometIO
57
56
  else
58
57
  data = JSON.parse res.body
59
58
  self.emit data['type'], data['data']
59
+ next
60
60
  end
61
- rescue StandardError, Timeout::Error
62
- self.emit :error, "CometIO get error"
61
+ rescue Timeout::Error, JSON::ParserError
62
+ next
63
+ rescue StandardError
64
+ self.emit :error, "CometIO get error 2"
63
65
  sleep 10
64
66
  next
65
67
  end
data/sample/config.ru CHANGED
@@ -10,6 +10,6 @@ require 'sinatra/cometio'
10
10
  require File.dirname(__FILE__)+'/main'
11
11
 
12
12
  set :haml, :escape_html => true
13
- set :cometio, :xhr_interval => 20
13
+ set :cometio, :timeout => 60
14
14
 
15
15
  run Sinatra::Application
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.6
4
+ version: 0.1.7
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-03 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack