Sha256: a53663adf8ca4c480ae12ebc35ad1b9e2e5f366b2a362c2804e33eb0d67c0f3e
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
var RocketIO = function(opts){ new EventEmitter().apply(this); this.type = null; // "comet", "websocket" this.session = null; this.channel = null; this.io = null; var self = this; var ws_close_timer = null; if(typeof opts === "object"){ this.channel = ""+opts.channel; } this.connect = function(){ self.io = function(){ if(self.type === "comet") return; if(typeof WebSocketIO === "undefined") return; var io = new WebSocketIO(); io.session = self.session; return io.connect(); }() || function(){ if(typeof CometIO === "undefined") return; var io = new CometIO(); io.session = self.session; return io.connect(); }(); if(typeof self.io === "undefined"){ setTimeout(function(){ self.emit("error", "WebSocketIO and CometIO are not available"); }, 100); return self; }; if(self.io.url.match(/^ws:\/\/.+/)) self.type = "websocket"; else if(self.io.url.match(/cometio/)) self.type = "comet"; else self.type = "unknown"; self.io.on("*", function(event_name, args){ if(event_name === "connect") event_name = "__connect"; self.emit(event_name, args); }); self.on("__connect", function(session_id){ self.session = session_id; io.push("__channel_id", self.channel); self.emit("connect"); }); ws_close_timer = setTimeout(function(){ self.close(); self.type = "comet"; self.connect(); }, 3000); self.once("connect", function(){ if(ws_close_timer) clearTimeout(ws_close_timer); ws_close_timer = null; }); return self; }; this.close = function(){ self.io.close(); }; this.push = function(type, data){ self.io.push(type, data); }; };
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sinatra-rocketio-0.2.0 | lib/js/rocketio.js |