1 |
// Set domain at highest level |
/* |
2 |
var domainparts = document.domain.split("."); |
stream: xhrinteractive, iframe, serversent |
3 |
document.domain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1]; |
longpoll |
4 |
|
smartpoll |
5 |
Function.prototype.bind = function(obj) { |
simplepoll |
6 |
var method = this, |
*/ |
7 |
temp = function() { |
|
8 |
return method.apply(obj, arguments); |
Meteor = { |
9 |
}; |
|
10 |
return temp; |
callbacks: { |
11 |
} |
process: function() {}, |
12 |
Function.prototype.andThen=function(g) { |
reset: function() {}, |
13 |
var f=this; |
eof: function() {}, |
14 |
var a=this.arguments |
statuschanged: function() {}, |
15 |
return function(args) { |
changemode: function() {} |
16 |
f(a);g(args); |
}, |
17 |
} |
channelcount: 0, |
18 |
}; |
channels: {}, |
19 |
|
debugmode: false, |
20 |
function Meteor(instID) { |
frameref: null, |
21 |
|
host: null, |
22 |
this.transferDoc = false; |
hostid: null, |
23 |
this.pingtimer = false; |
maxpollfreq: 60000, |
24 |
this.updatepollfreqtimer = false; |
minpollfreq: 2000, |
25 |
this.lastrequest = 0; |
mode: "stream", |
26 |
this.recvtimes = []; |
pingtimeout: 20000, |
27 |
this.MHostId = false; |
pingtimer: null, |
28 |
this.callback_process = function() {}; |
pollfreq: 3000, |
29 |
this.callback_reset = function() {}; |
port: 80, |
30 |
this.callback_eof = function() {}; |
pollaborted: false, |
31 |
this.callback_changemode = function() {}; |
pollhost: null, |
32 |
this.callback_statuschanged = function() {}; |
pollnum: 0, |
33 |
this.persist = true; |
polltimeout: 30000, |
34 |
this.frameloadtimer = false; |
polltimer: null, |
35 |
this.debugmode = false; |
recvtimes: [], |
36 |
this.subsurl = false; |
lastrequest: null, |
37 |
this.channels = {}; |
status: 0, |
38 |
this.channelcount = 0; |
updatepollfreqtimer: null, |
39 |
this.streamreq = false; |
|
40 |
this.byteoffset = 0; |
isSupportedBrowser: function() { |
41 |
|
var v; |
42 |
// Documented public properties |
if (v = navigator.userAgent.match(/compatible\; MSIE\ ([0-9\.]+)\;/i)) { |
43 |
this.subdomain = "data"; |
if (parseFloat(v[1]) <= 5.5) return false; |
44 |
this.dynamicpageaddress = "push"; |
} else if (v = navigator.userAgent.match(/Gecko\/([0-9]+)/i)) { |
45 |
this.smartpoll = true; |
if (parseInt(v[1]) <= 20051015) return false; |
46 |
this.pollfreq = 2000; |
} else if (v = navigator.userAgent.match(/WebKit\/([0-9\.]+)/i)) { |
47 |
this.minpollfreq = 2000; |
if (parseFloat(v[1]) < 400) return false; |
48 |
this.mode = "poll"; |
} |
49 |
this.polltimeout = 30000; |
return true; |
50 |
this.pingtimeout = 10000; |
}, |
51 |
this.maxmessages = 0; |
|
52 |
this.status = 0; |
register: function(ifr) { |
53 |
|
ifr.p = Meteor.process; |
54 |
/* Statuses: 0 = Uninitialised, |
ifr.r = Meteor.reset; |
55 |
1 = Loading stream, |
ifr.eof = Meteor.eof; |
56 |
2 = Loading controller frame, |
ifr.ch = Meteor.channelInfo; |
57 |
3 = Controller frame timeout, retrying. |
clearTimeout(Meteor.frameloadtimer); |
58 |
4 = Controller frame loaded and ready |
Meteor.setstatus(4); |
59 |
5 = Receiving data |
Meteor.log("Frame registered"); |
60 |
*/ |
}, |
61 |
|
|
62 |
this.instID = (typeof(instID) != "undefined") ? instID : 0; |
joinChannel: function(channelname, backtrack) { |
63 |
this.MHostId = Math.floor(Math.random()*100000000)+""+this.instID; |
if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
64 |
} |
Meteor.channels[channelname] = {backtrack:backtrack}; |
65 |
|
Meteor.log("Joined channel "+channelname); |
66 |
Meteor.instances = new Array(); |
Meteor.channelcount++; |
67 |
|
if (Meteor.status != 0 && Meteor.status != 6) Meteor.connect(); |
68 |
Meteor.create = function(instID) { |
}, |
69 |
if (!instID) instID = Meteor.instances.length; |
|
70 |
Meteor.instances[instID] = new Meteor(instID); |
leaveChannel: function(channelname) { |
71 |
return Meteor.instances[instID]; |
if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
72 |
} |
delete Meteor.channels[channelname]; |
73 |
|
Meteor.log("Left channel "+channelname); |
74 |
Meteor.register = function(ifr) { |
Meteor.channelcount--; |
75 |
instid = new String(ifr.window.frameElement.id); |
if (Meteor.channelcount && Meteor.status != 0 && Meteor.status != 6) Meteor.connect(); |
76 |
instid = instid.replace(/.*_([0-9]*)$/, "$1"); |
else Meteor.disconnect(); |
77 |
ifr.p = this.instances[instid].process.bind(this.instances[instid]); |
}, |
78 |
ifr.r = this.instances[instid].reset.bind(this.instances[instid]); |
|
79 |
ifr.eof = this.instances[instid].eof.bind(this.instances[instid]); |
connect: function() { |
80 |
ifr.get = this.instances[instid].get.bind(this.instances[instid]); |
Meteor.log("Connecting"); |
81 |
ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]); |
if (!Meteor.host) throw "Meteor host not specified"; |
82 |
clearTimeout(this.instances[instid].frameloadtimer); |
if (isNaN(Meteor.port)) throw "Meteor port not specified"; |
83 |
this.instances[instid].setstatus(4); |
if (!Meteor.channelcount) throw "No channels specified"; |
84 |
if (this.debugmode) console.log("Frame registered"); |
if (Meteor.status) Meteor.disconnect(); |
85 |
} |
Meteor.setstatus(1); |
86 |
|
if (!Meteor.hostid) Meteor.hostid = Meteor.time()+""+Math.floor(Math.random()*1000000) |
87 |
Meteor.reset = function(ifr) { |
document.domain = Meteor.extract_xss_domain(document.domain); |
88 |
instid = new String(ifr.window.frameElement.id); |
if (Meteor.mode=="stream") Meteor.mode = Meteor.selectStreamTransport(); |
89 |
instid = instid.replace(/.*_([0-9]*)$/, "$1"); |
Meteor.log("Selected "+Meteor.mode+" transport"); |
90 |
this.instances[instid].reset(); |
if (Meteor.mode=="xhrinteractive" || Meteor.mode=="iframe" || Meteor.mode=="serversent") { |
91 |
} |
if (Meteor.mode == "iframe") { |
92 |
|
Meteor.loadFrame(Meteor.getSubsUrl()); |
93 |
Meteor.prototype.joinChannel = function(channelname, backtrack) { |
} else { |
94 |
if (typeof(this.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/stream.html"); |
95 |
this.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0}; |
} |
96 |
if (this.debugmode) console.log("Joined channel "+channelname+", channel list follows"); |
clearTimeout(Meteor.pingtimer); |
97 |
if (this.debugmode) console.log(this.channels); |
Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout); |
98 |
if (this.status != 0) this.start(); |
|
99 |
this.channelcount++; |
} else { |
100 |
} |
Meteor.recvtimes[0] = Meteor.time(); |
101 |
|
if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer); |
102 |
Meteor.prototype.leaveChannel = function(channelname) { |
if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 10000); |
103 |
if (typeof(this.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq; |
104 |
delete this.channels[channelname]; |
Meteor.poll(); |
105 |
if (this.status != 0) this.start(); |
} |
106 |
this.channelcount--; |
}, |
107 |
} |
|
108 |
|
disconnect: function() { |
109 |
Meteor.prototype.start = function() { |
if (Meteor.status) { |
110 |
this.persist = (this.maxmessages)?1:0; |
clearTimeout(Meteor.pingtimer); |
111 |
this.smartpoll = (this.smartpoll)?1:0; |
clearTimeout(Meteor.updatepollfreqtimer); |
112 |
this.mode = (this.mode=="stream")?"stream":"poll"; |
clearTimeout(Meteor.frameloadtimer); |
113 |
if (!this.subdomain || !this.channelcount) throw "Channel or Meteor subdomain host not specified"; |
if (typeof CollectGarbage == 'function') CollectGarbage(); |
114 |
this.stop(); |
if (Meteor.status != 6) Meteor.setstatus(0); |
115 |
var now = new Date(); |
Meteor.log("Disconnected"); |
116 |
var t = now.getTime(); |
try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { } |
117 |
this.setstatus(1); |
try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {} |
118 |
this.updateSubsUrl(); |
} |
119 |
if (this.mode=="stream") { |
}, |
120 |
if (document.all) { |
|
121 |
this.createIframe(this.subsurl); |
selectStreamTransport: function() { |
122 |
} else { |
try { |
123 |
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/stream.html"); |
var test = ActiveXObject; |
124 |
} |
return "iframe"; |
125 |
var f = this.pollmode.bind(this); |
} catch (e) {} |
126 |
clearTimeout(this.pingtimer); |
if ((typeof window.addEventStream) == "function") return "iframe"; |
127 |
this.pingtimer = setTimeout(f, this.pingtimeout); |
return "xhrinteractive"; |
128 |
|
}, |
129 |
} else { |
|
130 |
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/poll.html&nc="+t); |
getSubsUrl: function() { |
131 |
this.recvtimes[0] = t; |
var host = ((Meteor.mode=='simplepoll' || Meteor.mode=='smartpoll' || Meteor.mode=='longpoll') && Meteor.pollhost) ? Meteor.pollhost : Meteor.host; |
132 |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
var surl = "http://" + host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode; |
133 |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
for (var c in Meteor.channels) { |
134 |
} |
surl += "/"+c; |
135 |
this.lastrequest = t; |
if (typeof Meteor.channels[c].lastmsgreceived != 'undefined') { |
136 |
} |
surl += ".r"+(Meteor.channels[c].lastmsgreceived+1); |
137 |
|
} else if (Meteor.channels[c].backtrack > 0) { |
138 |
Meteor.prototype.updateSubsUrl = function() { |
surl += ".b"+Meteor.channels[c].backtrack; |
139 |
var surl = "http://" + this.subdomain + "." + location.hostname + "/" + this.dynamicpageaddress + "?id=" + this.MHostId; |
} else if (Meteor.channels[c].backtrack != undefined) { |
140 |
if (this.maxmessages && this.persist && this.mode != "stream") surl += "&maxmessages=" + this.maxmessages; |
surl += ".h"; |
141 |
if (this.mode == "poll" && this.maxmessages == 0 && this.persist==1) this.persist=0; |
} |
142 |
surl += "&persist="+this.persist; |
} |
143 |
for (var c in this.channels) { |
surl += "?nc="+Meteor.time(); |
144 |
surl += "&channel="+c; |
return surl; |
145 |
if (this.channels[c].lastmsgreceived > 0) { |
}, |
146 |
surl += "&restartfrom="+(this.channels[c].lastmsgreceived+1); |
|
147 |
} else if (this.channels[c].backtrack > 0) { |
loadFrame: function(url) { |
148 |
surl += "&backtrack="+this.channels[c].backtrack; |
try { |
149 |
} else if (this.channels[c].backtrack < 0 || isNaN(this.channels[c].backtrack)) { |
if (!Meteor.frameref) { |
150 |
surl += "&restartfrom="; |
var transferDoc = new ActiveXObject("htmlfile"); |
151 |
} |
Meteor.frameref = transferDoc; |
152 |
} |
} |
153 |
this.subsurl = surl; |
Meteor.frameref.open(); |
154 |
} |
Meteor.frameref.write("<html><script>"); |
155 |
|
Meteor.frameref.write("document.domain=\""+(document.domain)+"\";"); |
156 |
Meteor.prototype.createIframe = function(url) { |
Meteor.frameref.write("</"+"script></html>"); |
157 |
if (document.all) { |
Meteor.frameref.parentWindow.Meteor = Meteor; |
158 |
this.transferDoc = new ActiveXObject("htmlfile"); |
Meteor.frameref.close(); |
159 |
this.transferDoc.open(); |
var ifrDiv = Meteor.frameref.createElement("div"); |
160 |
this.transferDoc.write("<html>"); |
Meteor.frameref.appendChild(ifrDiv); |
161 |
this.transferDoc.write("<script>document.domain=\""+(document.domain)+"\";</"+"script>"); |
ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>"; |
162 |
this.transferDoc.write("</html>"); |
} catch (e) { |
163 |
this.transferDoc.parentWindow.Meteor = Meteor; |
if (!Meteor.frameref) { |
164 |
this.transferDoc.close(); |
var ifr = document.createElement("IFRAME"); |
165 |
var ifrDiv = this.transferDoc.createElement("div"); |
ifr.style.width = "10px"; |
166 |
this.transferDoc.appendChild(ifrDiv); |
ifr.style.height = "10px"; |
167 |
ifrDiv.innerHTML = "<iframe id=\"meteorframe_"+this.instID+"\" src=\""+url+"\" style=\"display: none;\"></iframe>"; |
ifr.style.border = "none"; |
168 |
} else { |
ifr.style.position = "absolute"; |
169 |
var ifr = document.createElement("IFRAME"); |
ifr.style.top = "-10px"; |
170 |
ifr.style.width = "10px"; |
ifr.style.marginTop = "-10px"; |
171 |
ifr.style.height = "10px"; |
ifr.style.zIndex = "-20"; |
172 |
ifr.style.border = "none"; |
ifr.Meteor = Meteor; |
173 |
ifr.style.position = "absolute"; |
document.body.appendChild(ifr); |
174 |
ifr.style.top = "-10px"; |
Meteor.frameref = ifr; |
175 |
ifr.style.marginTop = "-10px"; |
} |
176 |
ifr.style.zIndex = "-20"; |
Meteor.frameref.setAttribute("src", url); |
177 |
ifr.setAttribute("id", "meteorframe_"+this.instID); |
} |
178 |
ifr.Meteor = Meteor; |
Meteor.log("Loading URL '"+url+"' into frame..."); |
179 |
if (document.compatMode=='CSS1Compat') { |
Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000); |
180 |
var innerifr = document.createElement("IFRAME"); |
}, |
181 |
innerifr.setAttribute("src", url); |
|
182 |
innerifr.setAttribute("id", "meteorinnerframe_"+this.instID); |
pollmode: function() { |
183 |
ifr.appendChild(innerifr); |
Meteor.log("Ping timeout"); |
184 |
document.body.appendChild(ifr); |
if (Meteor.mode != "smartpoll") { |
185 |
} else { |
Meteor.mode="smartpoll"; |
186 |
ifr.setAttribute("src", url); |
Meteor.callbacks["changemode"]("poll"); |
187 |
document.body.appendChild(ifr); |
clearTimeout(Meteor.pingtimer); |
188 |
} |
Meteor.lastpingtime = false; |
189 |
} |
} |
190 |
if (this.debugmode) console.log("Loading URL '"+url+"' into frame..."); |
Meteor.connect(); |
191 |
var f = this.frameloadtimeout.bind(this); |
}, |
192 |
this.frameloadtimer = setTimeout(f, 5000); |
|
193 |
} |
process: function(id, channel, data) { |
194 |
|
if (id == -1) { |
195 |
Meteor.prototype.stop = function() { |
Meteor.log("Ping"); |
196 |
if (typeof(this.transferDoc)=="object") { |
Meteor.ping(); |
197 |
this.transferDoc = false; |
} else if (typeof(Meteor.channels[channel]) != "undefined") { |
198 |
} |
Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data); |
199 |
if (document.getElementById("meteorframe_"+this.instID)) { |
Meteor.callbacks["process"](data); |
200 |
document.getElementById("meteorframe_"+this.instID).src="about:blank"; |
Meteor.channels[channel].lastmsgreceived = id; |
201 |
document.body.removeChild(document.getElementById("meteorframe_"+this.instID)); |
if (Meteor.mode=="smartpoll") { |
202 |
} |
Meteor.recvtimes[Meteor.recvtimes.length] = Meteor.time(); |
203 |
clearTimeout(this.pingtimer); |
while (Meteor.recvtimes.length > 5) Meteor.recvtimes.shift(); |
204 |
clearTimeout(this.updatepollfreqtimer); |
} |
205 |
clearTimeout(this.frameloadtimer); |
} |
206 |
this.setstatus(0); |
Meteor.setstatus(5); |
207 |
} |
}, |
208 |
|
|
209 |
Meteor.prototype.pollmode = function() { |
ping: function() { |
210 |
if (this.debugmode) console.log("Ping timeout"); |
if (Meteor.pingtimer) { |
211 |
this.mode="poll"; |
clearTimeout(Meteor.pingtimer); |
212 |
this.start(); |
Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout); |
213 |
this.callback_changemode("poll"); |
Meteor.lastpingtime = Meteor.time(); |
214 |
this.lastpingtime = false; |
} |
215 |
} |
Meteor.setstatus(5); |
216 |
|
}, |
217 |
Meteor.prototype.process = function(id, channel, data) { |
|
218 |
if (id == -1) { |
reset: function() { |
219 |
if (this.debugmode) console.log("Ping"); |
if (Meteor.status != 6 && Meteor.status != 0) { |
220 |
this.ping(); |
Meteor.log("Stream reset"); |
221 |
} else if (typeof(this.channels[channel]) != "undefined" && id > this.channels[channel].lastmsgreceived) { |
Meteor.ping(); |
222 |
if (this.debugmode) console.log("Message "+id+" received on channel "+channel+" (last id on channel: "+this.channels[channel].lastmsgreceived+")\n"+data); |
Meteor.callbacks["reset"](); |
223 |
this.callback_process(data); |
var x = Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest); |
224 |
this.channels[channel].lastmsgreceived = id; |
if (x < 10) x = 10; |
225 |
if (this.mode=="poll") { |
setTimeout(Meteor.connect, x); |
226 |
var now = new Date(); |
} |
227 |
var t = now.getTime(); |
}, |
228 |
this.recvtimes[this.recvtimes.length] = t; |
|
229 |
while (this.recvtimes.length > 5) this.recvtimes.shift(); |
eof: function() { |
230 |
} |
Meteor.log("Received end of stream, will not reconnect"); |
231 |
} |
Meteor.callbacks["eof"](); |
232 |
this.updateSubsUrl(); |
Meteor.setstatus(6); |
233 |
this.setstatus(5); |
Meteor.disconnect(); |
234 |
} |
}, |
235 |
|
|
236 |
Meteor.prototype.ping = function() { |
channelInfo: function(channel, id) { |
237 |
if (this.mode=="stream" && this.pingtimer) { |
Meteor.channels[channel].lastmsgreceived = id; |
238 |
clearTimeout(this.pingtimer); |
Meteor.log("Received channel info for channel "+channel+": resume from "+id); |
239 |
var f = this.pollmode.bind(this); |
}, |
240 |
this.pingtimer = setTimeout(f, this.pingtimeout); |
|
241 |
var now = new Date(); |
updatepollfreq: function() { |
242 |
this.lastpingtime = now.getTime(); |
var avg = 0; |
243 |
} |
for (var i=1; i<Meteor.recvtimes.length; i++) { |
244 |
this.setstatus(5); |
avg += (Meteor.recvtimes[i]-Meteor.recvtimes[i-1]); |
245 |
} |
} |
246 |
|
avg += (Meteor.time()-Meteor.recvtimes[Meteor.recvtimes.length-1]); |
247 |
Meteor.prototype.reset = function() { |
avg /= Meteor.recvtimes.length; |
248 |
if (this.debugmode) console.log("Stream reset"); |
var target = avg/2; |
249 |
var now = new Date(); |
if (target < Meteor.pollfreq && Meteor.pollfreq > Meteor.minpollfreq) Meteor.pollfreq = Math.ceil(Meteor.pollfreq*0.9); |
250 |
var t = now.getTime(); |
if (target > Meteor.pollfreq && Meteor.pollfreq < Meteor.maxpollfreq) Meteor.pollfreq = Math.floor(Meteor.pollfreq*1.05); |
251 |
var x = this.pollfreq - (t-this.lastrequest); |
}, |
252 |
if (x < 10) x = 10; |
|
253 |
this.ping(); |
registerEventCallback: function(evt, funcRef) { |
254 |
this.callback_reset(); |
Function.prototype.andThen=function(g) { |
255 |
setTimeout(this.start.bind(this), x); |
var f=this; |
256 |
} |
var a=Meteor.arguments |
257 |
|
return function(args) { |
258 |
Meteor.prototype.eof = function() { |
f(a);g(args); |
259 |
this.callback_eof(); |
} |
260 |
} |
}; |
261 |
|
if (typeof Meteor.callbacks[evt] == "function") { |
262 |
Meteor.prototype.get = function(varname) { |
Meteor.callbacks[evt] = (Meteor.callbacks[evt]).andThen(funcRef); |
263 |
eval("var a = this."+varname+";"); |
} else { |
264 |
if (typeof(a) == "undefined") throw "Cannot get value of "+varname; |
Meteor.callbacks[evt] = funcRef; |
265 |
return a; |
} |
266 |
} |
}, |
267 |
|
|
268 |
Meteor.prototype.increasepolldelay = function() { |
frameloadtimeout: function() { |
269 |
this.pollfreq *= 2; |
Meteor.log("Frame load timeout"); |
270 |
} |
if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer); |
271 |
|
Meteor.setstatus(3); |
272 |
Meteor.prototype.updatepollfreq = function() { |
Meteor.pollmode(); |
273 |
if (this.smartpoll) { |
}, |
274 |
var now = new Date(); |
|
275 |
var t = now.getTime(); |
extract_xss_domain: function(old_domain) { |
276 |
var avg = 0; |
if (old_domain.match(/^(\d{1,3}\.){3}\d{1,3}$/)) return old_domain; |
277 |
for (var i=1; i<this.recvtimes.length; i++) { |
domain_pieces = old_domain.split('.'); |
278 |
var x = (this.recvtimes[i]-this.recvtimes[i-1]); |
return domain_pieces.slice(-2, domain_pieces.length).join("."); |
279 |
avg += (x>60000)? 60000 : x; |
}, |
280 |
} |
|
281 |
x = (t-this.recvtimes[this.recvtimes.length-1]); |
setstatus: function(newstatus) { |
282 |
avg += (x>180000)? 180000 : x; |
// Statuses: 0 = Uninitialised, |
283 |
avg /= this.recvtimes.length; |
// 1 = Loading stream, |
284 |
if ((avg/3) < this.pollfreq && (avg/3) >= this.minpollfreq) this.pollfreq = Math.ceil(this.pollfreq*0.9); |
// 2 = Loading controller frame, |
285 |
if ((avg/3) > this.pollfreq) this.pollfreq = Math.floor(this.pollfreq*1.05); |
// 3 = Controller frame timeout, retrying. |
286 |
} |
// 4 = Controller frame loaded and ready |
287 |
} |
// 5 = Receiving data |
288 |
|
// 6 = End of stream, will not reconnect |
289 |
Meteor.prototype.registerEventCallback = function(evt, funcRef) { |
|
290 |
if (evt=="process") { |
if (Meteor.status != newstatus) { |
291 |
this.callback_process = (this.callback_process).andThen(funcRef); |
Meteor.status = newstatus; |
292 |
} else if (evt=="reset") { |
Meteor.callbacks["statuschanged"](newstatus); |
293 |
this.callback_reset = (this.callback_reset).andThen(funcRef); |
} |
294 |
} else if (evt=="eof") { |
}, |
295 |
this.callback_eof = (this.callback_eof).andThen(funcRef); |
|
296 |
} else if (evt=="changemode") { |
log: function(logstr) { |
297 |
this.callback_changemode = (this.callback_changemode).andThen(funcRef); |
if (Meteor.debugmode) { |
298 |
} else if (evt=="changestatus") { |
if (window.console) { |
299 |
this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef); |
window.console.log(logstr); |
300 |
} |
} else if (document.getElementById("meteorlogoutput")) { |
301 |
} |
document.getElementById("meteorlogoutput").innerHTML += logstr+"<br/>"; |
302 |
|
} |
303 |
Meteor.prototype.frameloadtimeout = function() { |
} |
304 |
if (this.debugmode) console.log("Frame load timeout"); |
}, |
305 |
if (this.frameloadtimer) clearTimeout(this.frameloadtimer); |
|
306 |
this.setstatus(3); |
poll: function() { |
307 |
setTimeout(this.start.bind(this), 5000); |
Meteor.pollaborted = 0; |
308 |
} |
try { |
309 |
Meteor.prototype.setstatus = function(newstatus) { |
clearTimeout(Meteor.polltimer); |
310 |
if (this.status != newstatus) { |
} catch (e) {}; |
311 |
this.status = newstatus; |
Meteor.lastrequest = Meteor.time(); |
312 |
this.callback_statuschanged(newstatus); |
if (Meteor.polltimeout) Meteor.polltimer = setTimeout(Meteor.clearpoll, Meteor.polltimeout); |
313 |
} |
var scripttag = document.createElement("SCRIPT"); |
314 |
} |
scripttag.type = "text/javascript"; |
315 |
|
scripttag.src = Meteor.getSubsUrl(); |
316 |
|
scripttag.id = "meteorpoll"+(++Meteor.pollnum); |
317 |
Meteor.createCookie = function(name,value,days) { |
scripttag.className = "meteorpoll"; |
318 |
if (days) { |
document.getElementsByTagName("HEAD")[0].appendChild(scripttag); |
319 |
var date = new Date(); |
}, |
320 |
date.setTime(date.getTime()+(days*24*60*60*1000)); |
|
321 |
var expires = "; expires="+date.toGMTString(); |
clearpoll: function() { |
322 |
} |
var s = document.getElementById('meteorpoll'+Meteor.pollnum); |
323 |
else var expires = ""; |
if (typeof s != 'undefined') s.parentNode.removeChild(s); |
324 |
document.cookie = name+"="+value+expires+"; path=/"; |
if (Meteor.status) { |
325 |
} |
var x = parent.Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest); |
326 |
|
if (x < 10) x = 10; |
327 |
Meteor.readCookie = function(name) { |
setTimeout(Meteor.poll, x); |
328 |
var nameEQ = name + "="; |
} |
329 |
var ca = document.cookie.split(';'); |
}, |
330 |
for(var i=0;i < ca.length;i++) { |
|
331 |
var c = ca[i]; |
time: function() { |
332 |
while (c.charAt(0)==' ') c = c.substring(1,c.length); |
var now = new Date(); |
333 |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
return now.getTime(); |
334 |
} |
} |
335 |
return null; |
} |
336 |
} |
|
337 |
|
var oldonunload = window.onunload; |
338 |
Meteor.eraseCookie = function(name) { |
if (typeof window.onunload != 'function') { |
339 |
createCookie(name,"",-1); |
window.onunload = Meteor.disconnect; |
340 |
} |
} else { |
341 |
|
window.onunload = function() { |
342 |
|
if (oldonunload) oldonunload(); |
343 |
|
Meteor.disconnect(); |
344 |
|
} |
345 |
|
} |