/[meteor]/googlecode.com/svn/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 /googlecode.com/svn/trunk/public_html/meteor.js

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

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

Legend:
Removed from v.20  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26