/[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 32 by andrew.betts, Thu Dec 20 21:24:24 2007 UTC revision 60 by andrew.betts, Tue Mar 25 22:34:16 2008 UTC
# Line 25  Meteor = { Line 25  Meteor = {
25          mode: "stream",          mode: "stream",
26          pingtimeout: 20000,          pingtimeout: 20000,
27          pingtimer: null,          pingtimer: null,
28          pollfreq: 5000,          pollfreq: 3000,
29          port: 80,          port: 80,
30          polltimeout: 30000,          polltimeout: 30000,
31          recvtimes: [],          recvtimes: [],
# Line 36  Meteor = { Line 36  Meteor = {
36                  ifr.p = Meteor.process;                  ifr.p = Meteor.process;
37                  ifr.r = Meteor.reset;                  ifr.r = Meteor.reset;
38                  ifr.eof = Meteor.eof;                  ifr.eof = Meteor.eof;
39                    ifr.ch = Meteor.channelInfo;
40                  clearTimeout(Meteor.frameloadtimer);                  clearTimeout(Meteor.frameloadtimer);
41                  Meteor.setstatus(4);                  Meteor.setstatus(4);
42                  Meteor.log("Frame registered");                  Meteor.log("Frame registered");
# Line 43  Meteor = { Line 44  Meteor = {
44    
45          joinChannel: function(channelname, backtrack) {          joinChannel: function(channelname, backtrack) {
46                  if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed";                  if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed";
47                  Meteor.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0};                  Meteor.channels[channelname] = {backtrack:backtrack};
48                  Meteor.log("Joined channel "+channelname);                  Meteor.log("Joined channel "+channelname);
49                  Meteor.channelcount++;                  Meteor.channelcount++;
50                  if (Meteor.status != 0) Meteor.connect();                  if (Meteor.status != 0) Meteor.connect();
# Line 53  Meteor = { Line 54  Meteor = {
54                  if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed";                  if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed";
55                  delete Meteor.channels[channelname];                  delete Meteor.channels[channelname];
56                  Meteor.log("Left channel "+channelname);                  Meteor.log("Left channel "+channelname);
                 if (Meteor.status != 0) Meteor.connect();  
57                  Meteor.channelcount--;                  Meteor.channelcount--;
58                    if (Meteor.channelcount && Meteor.status != 0) Meteor.connect();
59                    else Meteor.disconnect();
60          },          },
61    
62          connect: function() {          connect: function() {
# Line 83  Meteor = { Line 85  Meteor = {
85                          Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html");                          Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html");
86                          Meteor.recvtimes[0] = t;                          Meteor.recvtimes[0] = t;
87                          if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer);                          if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer);
88                          if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 2500);                          if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 10000);
89                          if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq;                          if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq;
90                  }                  }
91                  Meteor.lastrequest = t;                  Meteor.lastrequest = t;
# Line 91  Meteor = { Line 93  Meteor = {
93    
94          disconnect: function() {          disconnect: function() {
95                  if (Meteor.status) {                  if (Meteor.status) {
                         if (typeof(Meteor.frameref)=="iframe") Meteor.frameref.setAttribute("src", "about:blank");  
                         Meteor.frameref = null;  
96                          clearTimeout(Meteor.pingtimer);                          clearTimeout(Meteor.pingtimer);
97                          clearTimeout(Meteor.updatepollfreqtimer);                          clearTimeout(Meteor.updatepollfreqtimer);
98                          clearTimeout(Meteor.frameloadtimer);                          clearTimeout(Meteor.frameloadtimer);
99                          if (typeof CollectGarbage == 'function') CollectGarbage();                          if (typeof CollectGarbage == 'function') CollectGarbage();
100                          Meteor.setstatus(0);                          if (Meteor.status != 6) Meteor.setstatus(0);
101                            if (Meteor.frameref.tagName=='IFRAME') {
102                                    Meteor.frameref.parentNode.removeChild(Meteor.frameref);
103                            } else {
104                                    Meteor.frameref.open();
105                                    Meteor.frameref.close();
106                            }
107                            delete Meteor.frameref;
108                            Meteor.log("Disconnected");
109                  }                  }
110          },          },
111                    
# Line 114  Meteor = { Line 122  Meteor = {
122                  var surl = "http://" + Meteor.host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;                  var surl = "http://" + Meteor.host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
123                  for (var c in Meteor.channels) {                  for (var c in Meteor.channels) {
124                          surl += "/"+c;                          surl += "/"+c;
125                          if (Meteor.channels[c].lastmsgreceived > 0) {                          if (typeof Meteor.channels[c].lastmsgreceived != 'undefined' && Meteor.channels[c].lastmsgreceived >= 0) {
126                                  surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);                                  surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);
127                          } else if (Meteor.channels[c].backtrack > 0) {                          } else if (Meteor.channels[c].backtrack > 0) {
128                                  surl += ".b"+Meteor.channels[c].backtrack;                                  surl += ".b"+Meteor.channels[c].backtrack;
129                          } else if (Meteor.channels[c].backtrack < 0 || isNaN(Meteor.channels[c].backtrack)) {                          } else if (Meteor.channels[c].backtrack != undefined) {
130                                  surl += ".h";                                  surl += ".h";
131                          }                          }
132                  }                  }
133                    var now = new Date();
134                    surl += "?nc="+now.getTime();
135                  return surl;                  return surl;
136          },          },
137    
138          loadFrame: function(url) {          loadFrame: function(url) {
                 Meteor.frameref = null;  
139                  try {                  try {
140                          var transferDoc = new ActiveXObject("htmlfile");                          if (!Meteor.frameref) {
141                          transferDoc.open();                                  var transferDoc = new ActiveXObject("htmlfile");
142                          transferDoc.write("<html><script>");                                  Meteor.frameref = transferDoc;
143                          transferDoc.write("document.domain=\""+(document.domain)+"\";");                          }
144                          transferDoc.write("</"+"script></html>");                          Meteor.frameref.open();
145                          transferDoc.parentWindow.Meteor = Meteor;                          Meteor.frameref.write("<html><script>");
146                          transferDoc.close();                          Meteor.frameref.write("document.domain=\""+(document.domain)+"\";");
147                          var ifrDiv = transferDoc.createElement("div");                          Meteor.frameref.write("</"+"script></html>");
148                          transferDoc.appendChild(ifrDiv);                          Meteor.frameref.parentWindow.Meteor = Meteor;
149                            Meteor.frameref.close();
150                            var ifrDiv = Meteor.frameref.createElement("div");
151                            Meteor.frameref.appendChild(ifrDiv);
152                          ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>";                          ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>";
                         Meteor.frameref = transferDoc;  
153                  } catch (e) {                  } catch (e) {
154                          var ifr = document.createElement("IFRAME");                          if (!Meteor.frameref) {
155                          ifr.style.width = "10px";                                  var ifr = document.createElement("IFRAME");
156                          ifr.style.height = "10px";                                  ifr.style.width = "10px";
157                          ifr.style.border = "none";                                  ifr.style.height = "10px";
158                          ifr.style.position = "absolute";                                  ifr.style.border = "none";
159                          ifr.style.top = "-10px";                                  ifr.style.position = "absolute";
160                          ifr.style.marginTop = "-10px";                                  ifr.style.top = "-10px";
161                          ifr.style.zIndex = "-20";                                  ifr.style.marginTop = "-10px";
162                          ifr.Meteor = Meteor;                                  ifr.style.zIndex = "-20";
163                          ifr.setAttribute("src", url);                                  ifr.Meteor = Meteor;
164                          document.body.appendChild(ifr);                                  document.body.appendChild(ifr);
165                          Meteor.frameref = ifr;                                  Meteor.frameref = ifr;
166                            }
167                            Meteor.frameref.setAttribute("src", url);
168                  }                  }
169                  Meteor.log("Loading URL '"+url+"' into frame...");                  Meteor.log("Loading URL '"+url+"' into frame...");
170                  Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000);                  Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000);
# Line 159  Meteor = { Line 172  Meteor = {
172    
173          pollmode: function() {          pollmode: function() {
174                  Meteor.log("Ping timeout");                  Meteor.log("Ping timeout");
175                  Meteor.mode="smartpoll";                  if (Meteor.mode != "smartpoll") {
176                  clearTimeout(Meteor.pingtimer);                          Meteor.mode="smartpoll";
177                            Meteor.callbacks["changemode"]("poll");
178                            clearTimeout(Meteor.pingtimer);
179                            Meteor.lastpingtime = false;
180                    }
181                  Meteor.connect();                  Meteor.connect();
                 Meteor.callbacks["changemode"]("poll");  
                 Meteor.lastpingtime = false;  
182          },          },
183    
184          process: function(id, channel, data) {          process: function(id, channel, data) {
185                  if (id == -1) {                  if (id == -1) {
186                          Meteor.log("Ping");                          Meteor.log("Ping");
187                          Meteor.ping();                          Meteor.ping();
188                  } else if (typeof(Meteor.channels[channel]) != "undefined" && id > Meteor.channels[channel].lastmsgreceived) {                  } else if (typeof(Meteor.channels[channel]) != "undefined") {
189                          Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data);                          Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data);
190                          Meteor.callbacks["process"](data);                          Meteor.callbacks["process"](data);
191                          Meteor.channels[channel].lastmsgreceived = id;                          Meteor.channels[channel].lastmsgreceived = id;
# Line 194  Meteor = { Line 209  Meteor = {
209          },          },
210    
211          reset: function() {          reset: function() {
212                  Meteor.log("Stream reset");                  if (Meteor.status != 6) {
213                  Meteor.ping();                          Meteor.log("Stream reset");
214                  Meteor.callbacks["reset"]();                          Meteor.ping();
215                  var now = new Date();                          Meteor.callbacks["reset"]();
216                  var t = now.getTime();                          var now = new Date();
217                  var x = Meteor.pollfreq - (t-Meteor.lastrequest);                          var t = now.getTime();
218                  if (x < 10) x = 10;                          var x = Meteor.pollfreq - (t-Meteor.lastrequest);
219                  setTimeout(Meteor.connect, x);                          if (x < 10) x = 10;
220                            setTimeout(Meteor.connect, x);
221                    }
222          },          },
223    
224          eof: function() {          eof: function() {
225                    Meteor.log("Received end of stream, will not reconnect");
226                  Meteor.callbacks["eof"]();                  Meteor.callbacks["eof"]();
227                    Meteor.setstatus(6);
228                    Meteor.disconnect();
229            },
230    
231            channelInfo: function(channel, id) {
232                    Meteor.channels[channel].lastmsgreceived = id;
233                    Meteor.log("Received channel info for channel "+channel+": resume from "+id);
234          },          },
235    
236          updatepollfreq: function() {          updatepollfreq: function() {
# Line 241  Meteor = { Line 266  Meteor = {
266                  Meteor.log("Frame load timeout");                  Meteor.log("Frame load timeout");
267                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);
268                  Meteor.setstatus(3);                  Meteor.setstatus(3);
269                  setTimeout(Meteor.connect, 5000);                  Meteor.pollmode();
270          },          },
271    
272          extract_xss_domain: function(old_domain) {          extract_xss_domain: function(old_domain) {
# Line 257  Meteor = { Line 282  Meteor = {
282                  //                              3 = Controller frame timeout, retrying.                  //                              3 = Controller frame timeout, retrying.
283                  //                              4 = Controller frame loaded and ready                  //                              4 = Controller frame loaded and ready
284                  //                              5 = Receiving data                  //                              5 = Receiving data
285                    //                              6 = End of stream, will not reconnect
286    
287                  if (Meteor.status != newstatus) {                  if (Meteor.status != newstatus) {
288                          Meteor.status = newstatus;                          Meteor.status = newstatus;

Legend:
Removed from v.32  
changed lines
  Added in v.60

  ViewVC Help
Powered by ViewVC 1.1.26