lib/js/cometio.js in sinatra-cometio-0.3.5 vs lib/js/cometio.js in sinatra-cometio-0.3.6

- old
+ new

@@ -29,35 +29,36 @@ self.on("__session_id", function(session){ self.session = session; self.emit("connect", self.session); }); running = true; - self.get(); + get(); return self; }; this.close = function(){ running = false; self.removeListener("__session_id"); }; - this.get = function(){ + var get = function(){ if(!running) return; $.ajax( { url : self.url, data : {session : self.session}, success : function(data_arr){ - if(typeof data_arr === "undefined" || !data_arr.length) return; - for(var i = 0; i < data_arr.length; i++){ - var data = data_arr[i]; - if(data) self.emit(data.type, data.data); + if(data_arr !== null || typeof data_arr !== "undefined" || !!data_arr.length){ + for(var i = 0; i < data_arr.length; i++){ + var data = data_arr[i]; + if(data) self.emit(data.type, data.data); + } } - self.get(); + get(); }, error : function(req, stat, e){ self.emit("error", "CometIO get error"); - setTimeout(self.get, 10000); + setTimeout(get, 10000); }, complete : function(e){ }, type : "GET", dataType : "json",