--- googlecode.com/svn/trunk/public_html/meteor.js 2006/11/21 09:49:07 6 +++ googlecode.com/svn/trunk/public_html/meteor.js 2006/12/08 16:52:58 9 @@ -16,6 +16,27 @@ f(a);g(args); } }; +function addUnLoadEvent(func) { + var oldonunload = window.onunload; + if (typeof window.onunload != 'function') { + window.onunload = func; + } else { + window.onunload = function() { + if (oldonunload) { + oldonunload(); + } + func(); + } + } +} +//addUnLoadEvent(meteordestroy); +function meteordestroy() { + var x = Meteor.instances.length; + for(var i=0; i"); @@ -140,7 +157,8 @@ ifr.style.zIndex = "-20"; ifr.id = "meteorframe_"+this.instID; document.body.appendChild(ifr); - ifr.src = "http://"+this.subdomain+"."+location.hostname+"/stream.html?nocache="+t; + this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/stream.html"; + this.frameload(); } var f = this.pollmode.bind(this); clearTimeout(this.pingtimer); @@ -160,7 +178,8 @@ } ifr.id = "meteorframe_"+this.instID; document.body.appendChild(ifr); - ifr.src = "http://"+this.subdomain+"."+location.hostname+"/poll.html?nocache="+t; + this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/poll.html"; + this.frameload(); this.recvtimes[0] = t; if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); @@ -168,13 +187,30 @@ this.lastrequest = t; } +Meteor.prototype.stop = function() { + if (typeof(this.transferDoc)=="object") { + this.transferDoc.open(); + this.transferDoc.close(); + delete this.transferDoc; + } + if (document.getElementById("meteorframe_"+this.instID)) { + document.getElementById("meteorframe_"+this.instID).src="about:blank"; + document.body.removeChild(document.getElementById("meteorframe_"+this.instID)); + } + if (!isNaN(this.pingtimer)) clearTimeout(this.pingtimer); + if (!isNaN(this.updatepollfreqtimer)) clearTimeout(this.updatepollfreqtimer); + if (!isNaN(this.frameloadtimer)) clearTimeout(this.frameloadtimer); + this.setstatus(0); +} + Meteor.prototype.pollmode = function() { this.mode="poll"; this.start(); this.callback_changemode("poll"); + this.lastpingtime = false; } -Meteor.prototype.process = function(id, data) { +Meteor.prototype.process = function(id, data, timestamp) { if (id > this.lastmsgreceived) { this.callback_process(data); if (id != -1) this.lastmsgreceived = id; @@ -187,6 +223,10 @@ } else if (id == -1) { this.ping(); } + this.setstatus(5); + if (!isNaN(timestamp)) { + Meteor.setServerTime(timestamp); + } } Meteor.prototype.ping = function() { @@ -197,6 +237,7 @@ var now = new Date(); this.lastpingtime = now.getTime(); } + this.setstatus(5); } Meteor.prototype.reset = function() { @@ -249,9 +290,36 @@ this.callback_eof = (this.callback_eof).andThen(funcRef); } else if (evt=="changemode") { this.callback_changemode = (this.callback_changemode).andThen(funcRef); + } else if (evt=="changestatus") { + this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef); } } +Meteor.prototype.frameload = function() { + this.setstatus(2); + if (document.getElementById("meteorframe_"+this.instID)) { + var f = this.frameloadtimeout.bind(this); + this.frameloadtimer = setTimeout(f, 5000); + document.getElementById("meteorframe_"+this.instID).src = "about:blank"; + setTimeout(this.doloadurl.bind(this), 100); + } +} +Meteor.prototype.doloadurl = function() { + var now = new Date(); + var t = now.getTime(); + document.getElementById("meteorframe_"+this.instID).src = this.frameurl+"?nocache="+t; +} +Meteor.prototype.frameloadtimeout = function() { + if (this.frameloadtimer) clearTimeout(this.frameloadtimer); + this.setstatus(3); + this.frameload(); +} +Meteor.prototype.setstatus = function(newstatus) { + if (this.status != newstatus) { + this.status = newstatus; + this.callback_statuschanged(newstatus); + } +} Meteor.createCookie = function(name,value,days) { if (days) {