--- googlecode.com/svn/trunk/public_html/meteor.js 2007/12/20 21:24:24 32 +++ googlecode.com/svn/trunk/public_html/meteor.js 2008/03/25 22:34:16 60 @@ -25,7 +25,7 @@ mode: "stream", pingtimeout: 20000, pingtimer: null, - pollfreq: 5000, + pollfreq: 3000, port: 80, polltimeout: 30000, recvtimes: [], @@ -36,6 +36,7 @@ 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,7 +44,7 @@ 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(); @@ -53,8 +54,9 @@ 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.connect(); + else Meteor.disconnect(); }, connect: function() { @@ -83,7 +85,7 @@ Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html"); Meteor.recvtimes[0] = t; 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.lastrequest = t; @@ -91,13 +93,19 @@ disconnect: function() { if (Meteor.status) { - if (typeof(Meteor.frameref)=="iframe") Meteor.frameref.setAttribute("src", "about:blank"); - Meteor.frameref = null; clearTimeout(Meteor.pingtimer); clearTimeout(Meteor.updatepollfreqtimer); clearTimeout(Meteor.frameloadtimer); if (typeof CollectGarbage == 'function') CollectGarbage(); - Meteor.setstatus(0); + if (Meteor.status != 6) Meteor.setstatus(0); + if (Meteor.frameref.tagName=='IFRAME') { + Meteor.frameref.parentNode.removeChild(Meteor.frameref); + } else { + Meteor.frameref.open(); + Meteor.frameref.close(); + } + delete Meteor.frameref; + Meteor.log("Disconnected"); } }, @@ -114,44 +122,49 @@ var surl = "http://" + Meteor.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' && Meteor.channels[c].lastmsgreceived >= 0) { 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"; } } + var now = new Date(); + surl += "?nc="+now.getTime(); return surl; }, loadFrame: function(url) { - Meteor.frameref = null; try { - var transferDoc = new ActiveXObject("htmlfile"); - transferDoc.open(); - transferDoc.write("