--- googlecode.com/svn/trunk/public_html/meteor.js 2007/12/20 21:24:24 32
+++ googlecode.com/svn/trunk/public_html/meteor.js 2009/01/19 11:19:41 64
@@ -25,17 +25,35 @@
mode: "stream",
pingtimeout: 20000,
pingtimer: null,
- pollfreq: 5000,
+ pollfreq: 3000,
port: 80,
+ pollaborted: false,
+ pollhost: null,
+ pollnum: 0,
polltimeout: 30000,
+ polltimer: null,
recvtimes: [],
+ lastrequest: null,
status: 0,
updatepollfreqtimer: null,
+ isSupportedBrowser: function() {
+ var v;
+ if (v = navigator.userAgent.match(/compatible\; MSIE\ ([0-9\.]+)\;/i)) {
+ if (parseFloat(v[1]) <= 5.5) return false;
+ } else if (v = navigator.userAgent.match(/Gecko\/([0-9]+)/i)) {
+ if (parseInt(v[1]) <= 20051015) return false;
+ } else if (v = navigator.userAgent.match(/WebKit\/([0-9\.]+)/i)) {
+ if (parseFloat(v[1]) < 400) return false;
+ }
+ return true;
+ },
+
register: function(ifr) {
ifr.p = Meteor.process;
ifr.r = Meteor.reset;
ifr.eof = Meteor.eof;
+ ifr.ch = Meteor.channelInfo;
clearTimeout(Meteor.frameloadtimer);
Meteor.setstatus(4);
Meteor.log("Frame registered");
@@ -43,30 +61,29 @@
joinChannel: function(channelname, backtrack) {
if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed";
- Meteor.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0};
+ Meteor.channels[channelname] = {backtrack:backtrack};
Meteor.log("Joined channel "+channelname);
Meteor.channelcount++;
- if (Meteor.status != 0) Meteor.connect();
+ if (Meteor.status != 0 && Meteor.status != 6) Meteor.connect();
},
leaveChannel: function(channelname) {
if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed";
delete Meteor.channels[channelname];
Meteor.log("Left channel "+channelname);
- if (Meteor.status != 0) Meteor.connect();
Meteor.channelcount--;
+ if (Meteor.channelcount && Meteor.status != 0 && Meteor.status != 6) Meteor.connect();
+ else Meteor.disconnect();
},
connect: function() {
- Meteor.log("Connecting");
if (!Meteor.host) throw "Meteor host not specified";
if (isNaN(Meteor.port)) throw "Meteor port not specified";
if (!Meteor.channelcount) throw "No channels specified";
if (Meteor.status) Meteor.disconnect();
+ Meteor.log("Connecting");
Meteor.setstatus(1);
- var now = new Date();
- var t = now.getTime();
- if (!Meteor.hostid) Meteor.hostid = t+""+Math.floor(Math.random()*1000000)
+ if (!Meteor.hostid) Meteor.hostid = Meteor.time()+""+Math.floor(Math.random()*1000000)
document.domain = Meteor.extract_xss_domain(document.domain);
if (Meteor.mode=="stream") Meteor.mode = Meteor.selectStreamTransport();
Meteor.log("Selected "+Meteor.mode+" transport");
@@ -80,24 +97,25 @@
Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout);
} else {
- Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html");
- Meteor.recvtimes[0] = t;
+ Meteor.recvtimes[0] = Meteor.time();
if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer);
- if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 2500);
+ if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 10000);
if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq;
+ Meteor.poll();
}
- Meteor.lastrequest = t;
},
disconnect: function() {
if (Meteor.status) {
- if (typeof(Meteor.frameref)=="iframe") Meteor.frameref.setAttribute("src", "about:blank");
- Meteor.frameref = null;
+ if (Meteor.status != 6) Meteor.setstatus(0);
+ Meteor.clearpoll();
clearTimeout(Meteor.pingtimer);
clearTimeout(Meteor.updatepollfreqtimer);
clearTimeout(Meteor.frameloadtimer);
if (typeof CollectGarbage == 'function') CollectGarbage();
- Meteor.setstatus(0);
+ Meteor.log("Disconnected");
+ try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { }
+ try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {}
}
},
@@ -111,47 +129,52 @@
},
getSubsUrl: function() {
- var surl = "http://" + Meteor.host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
+ var host = ((Meteor.mode=='simplepoll' || Meteor.mode=='smartpoll' || Meteor.mode=='longpoll') && Meteor.pollhost) ? Meteor.pollhost : Meteor.host;
+ var surl = "http://" + host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
for (var c in Meteor.channels) {
surl += "/"+c;
- if (Meteor.channels[c].lastmsgreceived > 0) {
+ if (typeof Meteor.channels[c].lastmsgreceived != 'undefined') {
surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);
} else if (Meteor.channels[c].backtrack > 0) {
surl += ".b"+Meteor.channels[c].backtrack;
- } else if (Meteor.channels[c].backtrack < 0 || isNaN(Meteor.channels[c].backtrack)) {
+ } else if (Meteor.channels[c].backtrack != undefined) {
surl += ".h";
}
}
+ surl += "?nc="+Meteor.time();
return surl;
},
loadFrame: function(url) {
- Meteor.frameref = null;
try {
- var transferDoc = new ActiveXObject("htmlfile");
- transferDoc.open();
- transferDoc.write("