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