Sha256: 97a6908e6d604a0cc4ff6c008403f319438dc68832118187011a597fcd36bff0

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

var CometIO = function(){
  new EventEmitter().apply(this);
  this.url = "<%= cometio_url %>";
  this.session = null;
  var self = this;

  this.push = function(type, data){
    $.ajax(
      {
        url : self.url,
        data : {type : type, data : data, session : self.session},
        success : function(data){
        },
        error : function(req, stat, e){
          self.emit("error", "CometIO push error");
        },
        complete : function(e){
        },
        type : "POST",
        dataType : "json",
        timeout : 10000
      }
    );
  };

  this.connect = function(){
    self.on("__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();
        },
        error : function(req, stat, e){
          self.emit("error", "CometIO get error");
          setTimeout(self.get, 10000);
        },
        complete : function(e){
        },
        type : "GET",
        dataType : "json",
        timeout : 60000
      }
    );
  };
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinatra-cometio-0.1.5 lib/js/cometio.js
sinatra-cometio-0.1.4 lib/js/cometio.js
sinatra-cometio-0.1.3 lib/js/cometio.js
sinatra-cometio-0.1.2 lib/js/cometio.js
sinatra-cometio-0.1.1 lib/js/cometio.js
sinatra-cometio-0.1.0 lib/js/cometio.js