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