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

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

  ViewVC Help
Powered by ViewVC 1.1.26