/[meteor]/trunk/public_html/meteor.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/public_html/meteor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 27 by andrew.betts, Wed Aug 1 17:38:00 2007 UTC revision 64 by andrew.betts, Mon Jan 19 11:19:41 2009 UTC
# Line 1  Line 1 
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 = 1;          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 = 1;                          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 = "stream";                  }
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]);                  if (!Meteor.host) throw "Meteor host not specified";
81          ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]);                  if (isNaN(Meteor.port)) throw "Meteor port not specified";
82          clearTimeout(this.instances[instid].frameloadtimer);                  if (!Meteor.channelcount) throw "No channels specified";
83          this.instances[instid].setstatus(4);                  if (Meteor.status) Meteor.disconnect();
84          if (this.debugmode) console.log("Frame registered");                  Meteor.log("Connecting");
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.persist)?1:0;                          if (Meteor.status != 6) Meteor.setstatus(0);
111          this.smartpoll = (this.smartpoll)?1:0;                          Meteor.clearpoll();
112          this.mode = (this.mode=="stream")?"stream":"poll";                          clearTimeout(Meteor.pingtimer);
113          if (!this.subdomain || !this.channelcount) throw "Channel or Meteor subdomain host not specified";                          clearTimeout(Meteor.updatepollfreqtimer);
114          this.stop();                          clearTimeout(Meteor.frameloadtimer);
115          var now = new Date();                          if (typeof CollectGarbage == 'function') CollectGarbage();
116          var t = now.getTime();                          Meteor.log("Disconnected");
117          this.setstatus(1);                          try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { }
118          this.updateSubsUrl();                          try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {}                      
119          if (this.mode=="stream") {                  }
120                  if (document.all) {          },
121                          this.createIframe(this.subsurl);          
122                  } else {          selectStreamTransport: function() {
123                          this.createIframe("http://"+this.subdomain+"."+location.hostname+"/stream.html");                  try {
124                  }                          var test = ActiveXObject;
125                  var f = this.pollmode.bind(this);                          return "iframe";
126                  clearTimeout(this.pingtimer);                  } catch (e) {}
127                  this.pingtimer = setTimeout(f, this.pingtimeout);                  if ((typeof window.addEventStream) == "function") return "iframe";
128                    return "xhrinteractive";
129          } else {          },
130                  this.createIframe("http://"+this.subdomain+"."+location.hostname+"/poll.html?nc="+t);  
131                  this.recvtimes[0] = t;          getSubsUrl: function() {
132                  if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer);                  var host = ((Meteor.mode=='simplepoll' || Meteor.mode=='smartpoll' || Meteor.mode=='longpoll') && Meteor.pollhost) ? Meteor.pollhost : Meteor.host;
133                  this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500);                  var surl = "http://" + host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
134          }                  for (var c in Meteor.channels) {
135          this.lastrequest = t;                          surl += "/"+c;
136  }                          if (typeof Meteor.channels[c].lastmsgreceived != 'undefined') {
137                                    surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);
138  Meteor.prototype.updateSubsUrl = function() {                          } else if (Meteor.channels[c].backtrack > 0) {
139                                    surl += ".b"+Meteor.channels[c].backtrack;
140          // If streaming or long polling, connection should persist                          } else if (Meteor.channels[c].backtrack != undefined) {
141          this.persist = (this.mode == "stream" || (this.mode=='poll' && this.maxmessages > 0)) ? 1 : 0;                                  surl += ".h";
142          var surl = "http://" + this.subdomain + "." + location.hostname + "/" + this.dynamicpageaddress + "?id=" + this.MHostId;                          }
143          if (this.persist && this.mode != "stream") surl += "&maxmessages=" + this.maxmessages;                  }
144          surl += "&persist="+this.persist;                  surl += "?nc="+Meteor.time();
145          for (var c in this.channels) {                  return surl;
146                  surl += "&channel="+c;          },
147                  if (this.channels[c].lastmsgreceived > 0) {  
148                          surl += "&restartfrom="+(this.channels[c].lastmsgreceived+1);          loadFrame: function(url) {
149                  } else if (this.channels[c].backtrack > 0) {                  try {
150                          surl += "&backtrack="+this.channels[c].backtrack;                          if (!Meteor.frameref) {
151                  } else if (this.channels[c].backtrack < 0 || isNaN(this.channels[c].backtrack)) {                                  var transferDoc = new ActiveXObject("htmlfile");
152                          surl += "&restartfrom=";                                  Meteor.frameref = transferDoc;
153                  }                          }
154          }                          Meteor.frameref.open();
155          this.subsurl = surl;                          Meteor.frameref.write("<html><script>");
156  }                          Meteor.frameref.write("document.domain=\""+(document.domain)+"\";");
157                            Meteor.frameref.write("</"+"script></html>");
158  Meteor.prototype.createIframe = function(url) {                          Meteor.frameref.parentWindow.Meteor = Meteor;
159          delete this.transferDoc;                          Meteor.frameref.close();
160          if (document.all) try { this.transferDoc = new ActiveXObject("htmlfile") } catch(ex) { this.transferDoc = null }                          var ifrDiv = Meteor.frameref.createElement("div");
161          if (document.all && this.transferDoc) {                          Meteor.frameref.appendChild(ifrDiv);
162                  this.transferDoc = new ActiveXObject("htmlfile");                          ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>";
163                  this.transferDoc.open();                  } catch (e) {
164                  this.transferDoc.write("<html>");                          if (!Meteor.frameref) {
165                  this.transferDoc.write("<script>document.domain=\""+(document.domain)+"\";</"+"script>");                                  var ifr = document.createElement("IFRAME");
166                  this.transferDoc.write("</html>");                                  ifr.style.width = "10px";
167                  this.transferDoc.parentWindow.Meteor = Meteor;                                  ifr.style.height = "10px";
168                  this.transferDoc.close();                                  ifr.style.border = "none";
169                  var ifrDiv = this.transferDoc.createElement("div");                                  ifr.style.position = "absolute";
170                  this.transferDoc.appendChild(ifrDiv);                                  ifr.style.top = "-10px";
171                  ifrDiv.innerHTML = "<iframe id=\"meteorframe_"+this.instID+"\" src=\""+url+"\" style=\"display: none;\"></iframe>";                                  ifr.style.marginTop = "-10px";
172          } else {                                  ifr.style.zIndex = "-20";
173                  var ifr = document.createElement("IFRAME");                                  ifr.Meteor = Meteor;
174                  ifr.style.width = "10px";                                  document.body.appendChild(ifr);
175                  ifr.style.height = "10px";                                  Meteor.frameref = ifr;
176                  ifr.style.border = "none";                          }
177                  ifr.style.position = "absolute";                          Meteor.frameref.setAttribute("src", url);
178                  ifr.style.top = "-10px";                  }
179                  ifr.style.marginTop = "-10px";                  Meteor.log("Loading URL '"+url+"' into frame...");
180                  ifr.style.zIndex = "-20";                  Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000);
181                  ifr.setAttribute("id", "meteorframe_"+this.instID);          },
182                  ifr.Meteor = Meteor;  
183                  if (document.compatMode=='CSS1Compat') {          pollmode: function() {
184                          var innerifr = document.createElement("IFRAME");                  Meteor.log("Ping timeout");
185                          innerifr.setAttribute("src", url);                  if (Meteor.mode != "smartpoll") {
186                          innerifr.setAttribute("id", "meteorinnerframe_"+this.instID);                          Meteor.mode="smartpoll";
187                          ifr.appendChild(innerifr);                          Meteor.callbacks["changemode"]("poll");
188                          document.body.appendChild(ifr);                          clearTimeout(Meteor.pingtimer);
189                  } else {                          Meteor.lastpingtime = false;
190                          ifr.setAttribute("src", url);                  }
191                          document.body.appendChild(ifr);                  Meteor.connect();
192                  }          },
193          }  
194          if (this.debugmode) console.log("Loading URL '"+url+"' into frame...");          process: function(id, channel, data) {
195          var f = this.frameloadtimeout.bind(this);                  if (id == -1) {
196          this.frameloadtimer = setTimeout(f, 5000);                          Meteor.log("Ping");
197  }                          Meteor.ping();
198                    } else if (typeof(Meteor.channels[channel]) != "undefined") {
199  Meteor.prototype.stop = function() {                          Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data);
200          if (typeof(this.transferDoc)=="object") {                          Meteor.callbacks["process"](data);
201                  this.transferDoc = false;                          Meteor.channels[channel].lastmsgreceived = id;
202          }                          if (Meteor.mode=="smartpoll") {
203          if (document.getElementById("meteorframe_"+this.instID)) {                                  Meteor.recvtimes[Meteor.recvtimes.length] = Meteor.time();
204                  document.getElementById("meteorframe_"+this.instID).src="about:blank";                                  while (Meteor.recvtimes.length > 5) Meteor.recvtimes.shift();
205                  document.body.removeChild(document.getElementById("meteorframe_"+this.instID));                          }
206          }                  }
207          clearTimeout(this.pingtimer);                  Meteor.setstatus(5);
208          clearTimeout(this.updatepollfreqtimer);          },
209          clearTimeout(this.frameloadtimer);  
210          this.setstatus(0);          ping: function() {
211  }                  if (Meteor.pingtimer) {
212                            clearTimeout(Meteor.pingtimer);
213  Meteor.prototype.pollmode = function() {                          Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout);
214          if (this.debugmode) console.log("Ping timeout");                          Meteor.lastpingtime = Meteor.time();
215          this.mode="poll";                  }
216          this.start();                  Meteor.setstatus(5);
217          this.callback_changemode("poll");          },
218          this.lastpingtime = false;  
219  }          reset: function() {
220                    if (Meteor.status != 6 && Meteor.status != 0) {
221  Meteor.prototype.process = function(id, channel, data) {                          Meteor.log("Stream reset");
222          if (id == -1) {                          Meteor.ping();
223                  if (this.debugmode) console.log("Ping");                          Meteor.callbacks["reset"]();
224                  this.ping();                          var x = Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
225          } else if (typeof(this.channels[channel]) != "undefined" && id > this.channels[channel].lastmsgreceived) {                          if (x < 10) x = 10;
226                  if (this.debugmode) console.log("Message "+id+" received on channel "+channel+" (last id on channel: "+this.channels[channel].lastmsgreceived+")\n"+data);                          setTimeout(Meteor.connect, x);
227                  this.callback_process(data);                  }
228                  this.channels[channel].lastmsgreceived = id;          },
229                  if (this.mode=="poll") {  
230                          var now = new Date();          eof: function() {
231                          var t = now.getTime();                  Meteor.log("Received end of stream, will not reconnect");
232                          this.recvtimes[this.recvtimes.length] = t;                  Meteor.callbacks["eof"]();
233                          while (this.recvtimes.length > 5) this.recvtimes.shift();                  Meteor.setstatus(6);
234                  }                  Meteor.disconnect();
235          }          },
236          this.updateSubsUrl();  
237          this.setstatus(5);          channelInfo: function(channel, id) {
238  }                  Meteor.channels[channel].lastmsgreceived = id;
239                    Meteor.log("Received channel info for channel "+channel+": resume from "+id);
240  Meteor.prototype.ping = function() {          },
241          if (this.mode=="stream" && this.pingtimer) {  
242                  clearTimeout(this.pingtimer);          updatepollfreq: function() {
243                  var f = this.pollmode.bind(this);                  var avg = 0;
244                  this.pingtimer = setTimeout(f, this.pingtimeout);                  for (var i=1; i<Meteor.recvtimes.length; i++) {
245                  var now = new Date();                          avg += (Meteor.recvtimes[i]-Meteor.recvtimes[i-1]);
246                  this.lastpingtime = now.getTime();                  }
247          }                  avg += (Meteor.time()-Meteor.recvtimes[Meteor.recvtimes.length-1]);
248          this.setstatus(5);                  avg /= Meteor.recvtimes.length;
249  }                  var target = avg/2;
250                    if (target < Meteor.pollfreq && Meteor.pollfreq > Meteor.minpollfreq) Meteor.pollfreq = Math.ceil(Meteor.pollfreq*0.9);
251  Meteor.prototype.reset = function() {                  if (target > Meteor.pollfreq && Meteor.pollfreq < Meteor.maxpollfreq) Meteor.pollfreq = Math.floor(Meteor.pollfreq*1.05);
252          if (this.debugmode) console.log("Stream reset");          },
253          var now = new Date();  
254          var t = now.getTime();          registerEventCallback: function(evt, funcRef) {
255          var x = this.pollfreq - (t-this.lastrequest);                  Function.prototype.andThen=function(g) {
256          if (x < 10) x = 10;                          var f=this;
257          this.ping();                          var a=Meteor.arguments
258          this.callback_reset();                          return function(args) {
259          setTimeout(this.start.bind(this), x);                                  f(a);g(args);
260  }                          }
261                    };
262  Meteor.prototype.eof = function() {                  if (typeof Meteor.callbacks[evt] == "function") {
263          this.callback_eof();                          Meteor.callbacks[evt] = (Meteor.callbacks[evt]).andThen(funcRef);
264  }                  } else {
265                            Meteor.callbacks[evt] = funcRef;
266  Meteor.prototype.get = function(varname) {                  }
267          eval("var a = this."+varname+";");          },
268          if (typeof(a) == "undefined") throw "Cannot get value of "+varname;  
269          return a;          frameloadtimeout: function() {
270  }                  Meteor.log("Frame load timeout");
271                    if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);
272  Meteor.prototype.increasepolldelay = function() {                  Meteor.setstatus(3);
273          this.pollfreq *= 2;                  Meteor.pollmode();
274  }          },
275    
276  Meteor.prototype.updatepollfreq = function() {          extract_xss_domain: function(old_domain) {
277          if (this.smartpoll) {                  if (old_domain.match(/^(\d{1,3}\.){3}\d{1,3}$/)) return old_domain;
278                  var now = new Date();                  domain_pieces = old_domain.split('.');
279                  var t = now.getTime();                  return domain_pieces.slice(-2, domain_pieces.length).join(".");
280                  var avg = 0;          },
281                  for (var i=1; i<this.recvtimes.length; i++) {  
282                          var x = (this.recvtimes[i]-this.recvtimes[i-1]);          setstatus: function(newstatus) {
283                          avg += (x>60000)? 60000 : x;                  // Statuses:    0 = Uninitialised,
284                  }                  //                              1 = Loading stream,
285                  x = (t-this.recvtimes[this.recvtimes.length-1]);                  //                              2 = Loading controller frame,
286                  avg += (x>180000)? 180000 : x;                  //                              3 = Controller frame timeout, retrying.
287                  avg /= this.recvtimes.length;                  //                              4 = Controller frame loaded and ready
288                  if ((avg/3) < this.pollfreq && (avg/3) >= this.minpollfreq) this.pollfreq = Math.ceil(this.pollfreq*0.9);                  //                              5 = Receiving data
289                  if ((avg/3) > this.pollfreq) this.pollfreq = Math.floor(this.pollfreq*1.05);                  //                              6 = End of stream, will not reconnect
290          }  
291  }                  if (Meteor.status != newstatus) {
292                            Meteor.status = newstatus;
293  Meteor.prototype.registerEventCallback = function(evt, funcRef) {                          Meteor.callbacks["statuschanged"](newstatus);
294          if (evt=="process") {                  }
295                  this.callback_process = (this.callback_process).andThen(funcRef);          },
296          } else if (evt=="reset") {  
297                  this.callback_reset = (this.callback_reset).andThen(funcRef);          log: function(logstr) {
298          } else if (evt=="eof") {                  if (Meteor.debugmode) {
299                  this.callback_eof = (this.callback_eof).andThen(funcRef);                          if (window.console) {
300          } else if (evt=="changemode") {                                  window.console.log(logstr);
301                  this.callback_changemode = (this.callback_changemode).andThen(funcRef);                          } else if (document.getElementById("meteorlogoutput")) {
302          } else if (evt=="changestatus") {                                  document.getElementById("meteorlogoutput").innerHTML += logstr+"<br/>";
303                  this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef);                          }
304          }                  }
305  }          },
306    
307  Meteor.prototype.frameloadtimeout = function() {          poll: function() {
308          if (this.debugmode) console.log("Frame load timeout");                  Meteor.pollaborted = 0;
309          if (this.frameloadtimer) clearTimeout(this.frameloadtimer);                  try {
310          this.setstatus(3);                          clearTimeout(Meteor.polltimer);
311          setTimeout(this.start.bind(this), 5000);                  } catch (e) {};
312  }                  Meteor.lastrequest = Meteor.time();
313  Meteor.prototype.setstatus = function(newstatus) {                  if (Meteor.polltimeout) Meteor.polltimer = setTimeout(Meteor.clearpoll, Meteor.polltimeout);
314          if (this.status != newstatus) {                  var scripttag = document.createElement("SCRIPT");
315                  this.status = newstatus;                  scripttag.type = "text/javascript";
316                  this.callback_statuschanged(newstatus);                  scripttag.src = Meteor.getSubsUrl();
317          }                  scripttag.id = "meteorpoll"+(++Meteor.pollnum);
318  }                  scripttag.className = "meteorpoll";
319                    document.getElementsByTagName("HEAD")[0].appendChild(scripttag);
320            },
321  Meteor.createCookie = function(name,value,days) {  
322          if (days) {          clearpoll: function() {
323                  var date = new Date();                  if (document.getElementById('meteorpoll'+Meteor.pollnum)) {
324                  date.setTime(date.getTime()+(days*24*60*60*1000));                          var s = document.getElementById('meteorpoll'+Meteor.pollnum);
325                  var expires = "; expires="+date.toGMTString();                          s.parentNode.removeChild(s);
326          }                  }
327          else var expires = "";                  if (Meteor.status == 5) {
328          document.cookie = name+"="+value+expires+"; path=/";                          var x = parent.Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
329  }                          if (x < 10) x = 10;
330                            setTimeout(Meteor.poll, x);
331  Meteor.readCookie = function(name) {                  }
332          var nameEQ = name + "=";          },
333          var ca = document.cookie.split(';');  
334          for(var i=0;i < ca.length;i++) {          time: function() {
335                  var c = ca[i];                  var now = new Date();
336                  while (c.charAt(0)==' ') c = c.substring(1,c.length);                  return now.getTime();
337                  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);          }
338          }  }
339          return null;  
340  }  var oldonunload = window.onunload;
341    if (typeof window.onunload != 'function') {
342  Meteor.eraseCookie = function(name) {          window.onunload = Meteor.disconnect;
343          createCookie(name,"",-1);  } else {
344  }          window.onunload = function() {
345                    if (oldonunload) oldonunload();
346                    Meteor.disconnect();
347            }
348    }

Legend:
Removed from v.27  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26