sinatra-cometio 0.5.6 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2d4bcecc45017cc73256cad7afa8424be83162c
4
- data.tar.gz: d722c7b6be85852d63d1b011ce97fa8d1c293138
3
+ metadata.gz: a88f058c708fa162b68b6f66cb07535ef05c8f67
4
+ data.tar.gz: 2f6bd541e6c0139cba9d6b29a18249faff22134c
5
5
  SHA512:
6
- metadata.gz: 3faffbfe215f98cd092e2ce48a9ca849c16dff81de741030b71936988069fbd620605e0d762ccb68d19f57b734600ee693beec8b8d6f0ae248fe64307f093508
7
- data.tar.gz: b795964ad56a975f1ee07993c6130efdd73cb80c439db4bae11aeb63be86b9638f2a6da2fb66828b7939feea5a13f24a9af17722274ac918438ae74de2fb4743
6
+ metadata.gz: c4cdefcf0d376a53ba88d47e8319f5eab919dbb49c20171ec8f58976b2a4178167ade6558d29d2072e9940da479691a32acdb626004cf5912a583b06a5662c7a
7
+ data.tar.gz: 5a8f974d7a6f815e88557557102cf0c98e25a711dbbad647f3e4948363b7d42e819382ea23a37ea47c1ca0cf9c1261dc7656a10b1b87ad0e0ae258a67b0a1ac7
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.5.7 2013-05-27
2
+
3
+ * bugfix JSON parse error at classic style
4
+ * set :cometio, :allow_crossdomain => true
5
+ * add constructor arguments in JS lib
6
+
1
7
  === 0.5.6 2013-05-23
2
8
 
3
9
  * post with JSON for nested Array
data/README.md CHANGED
@@ -30,7 +30,7 @@ Server Side
30
30
  ```ruby
31
31
  require 'sinatra'
32
32
  require 'sinatra/cometio'
33
- set :cometio, :timeout => 120, :post_interval => 1
33
+ set :cometio, :timeout => 120, :post_interval => 1, :allow_crossdomain => false
34
34
 
35
35
  run Sinatra::Application
36
36
  ```
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
- this.url = "<%= cometio_url %>";
4
- this.session = null;
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
- data = JSON.parse params[:json] rescue halt 500, 'JSON parse error'
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
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module CometIO
3
- VERSION = '0.5.6'
3
+ VERSION = '0.5.7'
4
4
  end
5
5
  end
data/sample/config.ru CHANGED
@@ -14,6 +14,6 @@ require 'sass'
14
14
  require File.dirname(__FILE__)+'/main'
15
15
 
16
16
  set :haml, :escape_html => true
17
- set :cometio, :timeout => 60, :post_interval => 2
17
+ set :cometio, :timeout => 60, :post_interval => 2, :allow_crossdomain => false
18
18
 
19
19
  run ChatApp
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.6
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-22 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler