sinatra-cometio 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +6 -0
- data/README.md +1 -1
- data/lib/js/cometio.js +6 -5
- data/lib/sinatra-cometio/application.rb +3 -1
- data/lib/sinatra-cometio/options.rb +2 -1
- data/lib/sinatra-cometio/version.rb +1 -1
- data/sample/config.ru +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a88f058c708fa162b68b6f66cb07535ef05c8f67
|
4
|
+
data.tar.gz: 2f6bd541e6c0139cba9d6b29a18249faff22134c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4cdefcf0d376a53ba88d47e8319f5eab919dbb49c20171ec8f58976b2a4178167ade6558d29d2072e9940da479691a32acdb626004cf5912a583b06a5662c7a
|
7
|
+
data.tar.gz: 5a8f974d7a6f815e88557557102cf0c98e25a711dbbad647f3e4948363b7d42e819382ea23a37ea47c1ca0cf9c1261dc7656a10b1b87ad0e0ae258a67b0a1ac7
|
data/History.txt
CHANGED
data/README.md
CHANGED
data/lib/js/cometio.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
var CometIO = function(){
|
1
|
+
var CometIO = function(url, opts){
|
2
2
|
new EventEmitter().apply(this);
|
3
|
-
|
4
|
-
this.
|
3
|
+
if(typeof opts === "undefined" || opts === null) opts = {};
|
4
|
+
this.url = url || "<%= cometio_url %>";
|
5
|
+
this.session = opts.session || null;
|
5
6
|
var running = false;
|
6
7
|
var self = this;
|
7
8
|
var post_queue = [];
|
@@ -32,7 +33,7 @@ var CometIO = function(){
|
|
32
33
|
);
|
33
34
|
post_queue = [];
|
34
35
|
};
|
35
|
-
setInterval(flush, <%= (CometIO.options[:post_interval]*1000).to_i %>);
|
36
|
+
setInterval(flush, <%= (Sinatra::CometIO.options[:post_interval]*1000).to_i %>);
|
36
37
|
|
37
38
|
this.push = function(type, data){
|
38
39
|
if(!running || !self.session){
|
@@ -81,7 +82,7 @@ var CometIO = function(){
|
|
81
82
|
},
|
82
83
|
type : "GET",
|
83
84
|
dataType : "json",
|
84
|
-
timeout : <%= (CometIO.options[:timeout]+10)*1000 %>
|
85
|
+
timeout : <%= (Sinatra::CometIO.options[:timeout]+10)*1000 %>
|
85
86
|
}
|
86
87
|
);
|
87
88
|
};
|
@@ -11,6 +11,7 @@ module Sinatra
|
|
11
11
|
end
|
12
12
|
|
13
13
|
app.get '/cometio/io' do
|
14
|
+
response["Access-Control-Allow-Origin"] = "*" if CometIO.options[:allow_crossdomain]
|
14
15
|
stream :keep_open do |s|
|
15
16
|
session = params[:session].to_s.empty? ? CometIO.create_session(request.ip) : params[:session]
|
16
17
|
CometIO.sessions[session][:stream] = s
|
@@ -41,7 +42,8 @@ module Sinatra
|
|
41
42
|
end
|
42
43
|
|
43
44
|
app.post '/cometio/io' do
|
44
|
-
|
45
|
+
response["Access-Control-Allow-Origin"] = "*" if CometIO.options[:allow_crossdomain]
|
46
|
+
data = ::JSON.parse params[:json] rescue halt 500, 'JSON parse error'
|
45
47
|
from = data['session']
|
46
48
|
halt 400, 'no session' if !from or from.empty?
|
47
49
|
events = data['events']
|
@@ -12,7 +12,8 @@ module Sinatra
|
|
12
12
|
def self.default_options
|
13
13
|
{
|
14
14
|
:timeout => [120, lambda{|v| v.kind_of? Fixnum and v >= 20 }],
|
15
|
-
:post_interval => [1, lambda{|v| [Fixnum, Float].include? v.class and v >= 1 }]
|
15
|
+
:post_interval => [1, lambda{|v| [Fixnum, Float].include? v.class and v >= 1 }],
|
16
|
+
:allow_crossdomain => [false, lambda{|v| [true, false].include? v }]
|
16
17
|
}
|
17
18
|
end
|
18
19
|
|
data/sample/config.ru
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-cometio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|