lib/js/cometio.js in sinatra-cometio-0.1.5 vs lib/js/cometio.js in sinatra-cometio-0.1.6
- old
+ new
@@ -1,9 +1,10 @@
var CometIO = function(){
new EventEmitter().apply(this);
this.url = "<%= cometio_url %>";
this.session = null;
+ var running = false;
var self = this;
this.push = function(type, data){
$.ajax(
{
@@ -22,19 +23,27 @@
}
);
};
this.connect = function(){
+ if(running) return self;
self.on("__session_id", function(session){
self.session = session;
self.emit("connect", self.session);
});
+ running = true;
self.get();
return self;
};
+ this.close = function(){
+ running = false;
+ self.removeListener("__session_id");
+ };
+
this.get = function(){
+ if(!running) return;
$.ajax(
{
url : self.url,
data : {session : self.session},
success : function(data){
@@ -49,10 +58,10 @@
},
complete : function(e){
},
type : "GET",
dataType : "json",
- timeout : 60000
+ timeout : <%= (CometIO.options[:xhr_interval]+10)*1000 %>
}
);
};
};