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