--- googlecode.com/svn/trunk/public_html/meteor.js 2008/02/27 21:58:56 53 +++ googlecode.com/svn/trunk/public_html/meteor.js 2008/03/25 22:34:16 60 @@ -44,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(); @@ -54,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() { @@ -84,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; @@ -96,7 +97,15 @@ 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"); } }, @@ -113,14 +122,16 @@ 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; }, @@ -161,10 +172,12 @@ pollmode: function() { Meteor.log("Ping timeout"); - Meteor.mode="smartpoll"; - clearTimeout(Meteor.pingtimer); - Meteor.callbacks["changemode"]("poll"); - Meteor.lastpingtime = false; + if (Meteor.mode != "smartpoll") { + Meteor.mode="smartpoll"; + Meteor.callbacks["changemode"]("poll"); + clearTimeout(Meteor.pingtimer); + Meteor.lastpingtime = false; + } Meteor.connect(); }, @@ -196,18 +209,22 @@ }, reset: function() { - Meteor.log("Stream reset"); - Meteor.ping(); - Meteor.callbacks["reset"](); - var now = new Date(); - var t = now.getTime(); - var x = Meteor.pollfreq - (t-Meteor.lastrequest); - if (x < 10) x = 10; - setTimeout(Meteor.connect, x); + if (Meteor.status != 6) { + Meteor.log("Stream reset"); + Meteor.ping(); + Meteor.callbacks["reset"](); + var now = new Date(); + var t = now.getTime(); + var x = Meteor.pollfreq - (t-Meteor.lastrequest); + if (x < 10) x = 10; + setTimeout(Meteor.connect, x); + } }, eof: function() { + Meteor.log("Received end of stream, will not reconnect"); Meteor.callbacks["eof"](); + Meteor.setstatus(6); Meteor.disconnect(); }, @@ -265,6 +282,7 @@ // 3 = Controller frame timeout, retrying. // 4 = Controller frame loaded and ready // 5 = Receiving data + // 6 = End of stream, will not reconnect if (Meteor.status != newstatus) { Meteor.status = newstatus;