lib/js/cometio.js in sinatra-cometio-0.0.1 vs lib/js/cometio.js in sinatra-cometio-0.0.2
- old
+ new
@@ -1,21 +1,41 @@
var CometIO = function(){
this.url = "<%= cometio_url %>";
+ this.session = null;
var self = this;
this.push = function(type, data){
- $.post(self.url, {type : type, data : data});
+ $.ajax(
+ {
+ url : self.url,
+ data : {type : type, data : data, session : self.session},
+ success : function(data){
+ },
+ error : function(req, stat, e){
+ },
+ complete : function(e){
+ },
+ type : "POST",
+ dataType : "json",
+ timeout : 10000
+ }
+ );
};
this.connect = function(){
+ self.on("set_session_id", function(session){
+ self.session = session;
+ self.emit("connect", self.session);
+ });
self.get();
return self;
};
this.get = function(){
$.ajax(
{
url : self.url,
+ data : {session : self.session},
success : function(data){
if(data){
self.emit(data.type, data.data);
}
self.get();