--- googlecode.com/svn/trunk/public_html/meteor.js 2008/02/02 16:53:19 40 +++ googlecode.com/svn/trunk/public_html/meteor.js 2008/03/25 00:38:17 59 @@ -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() { @@ -95,7 +97,15 @@ clearTimeout(Meteor.updatepollfreqtimer); clearTimeout(Meteor.frameloadtimer); if (typeof CollectGarbage == 'function') CollectGarbage(); - Meteor.setstatus(0); + if (Meteor.status != 6) Meteor.setstatus(0); + try { + Meteor.frameref.open(); + Meteor.frameref.close(); + } catch (e) { + Meteor.frameref.parentNode.removeChild(Meteor.frameref); + } + delete Meteor.frameref; + Meteor.log("Disconnected"); } }, @@ -112,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; }, @@ -162,16 +174,16 @@ Meteor.log("Ping timeout"); Meteor.mode="smartpoll"; clearTimeout(Meteor.pingtimer); - Meteor.connect(); Meteor.callbacks["changemode"]("poll"); Meteor.lastpingtime = false; + Meteor.connect(); }, process: function(id, channel, data) { if (id == -1) { Meteor.log("Ping"); Meteor.ping(); - } else if (typeof(Meteor.channels[channel]) != "undefined" && id > Meteor.channels[channel].lastmsgreceived) { + } else if (typeof(Meteor.channels[channel]) != "undefined") { Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data); Meteor.callbacks["process"](data); Meteor.channels[channel].lastmsgreceived = id; @@ -195,18 +207,28 @@ }, 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(); + }, + + channelInfo: function(channel, id) { + Meteor.channels[channel].lastmsgreceived = id; + Meteor.log("Received channel info for channel "+channel+": resume from "+id); }, updatepollfreq: function() { @@ -242,7 +264,7 @@ Meteor.log("Frame load timeout"); if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer); Meteor.setstatus(3); - setTimeout(Meteor.connect, 5000); + Meteor.pollmode(); }, extract_xss_domain: function(old_domain) { @@ -258,6 +280,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;