/[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 40 by andrew.betts, Sat Feb 2 16:53:19 2008 UTC revision 59 by andrew.betts, Tue Mar 25 00:38:17 2008 UTC
# 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 95  Meteor = { Line 97  Meteor = {
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                            try {
102                                    Meteor.frameref.open();
103                                    Meteor.frameref.close();
104                            } catch (e) {
105                                    Meteor.frameref.parentNode.removeChild(Meteor.frameref);
106                            }
107                            delete Meteor.frameref;
108                            Meteor.log("Disconnected");
109                  }                  }
110          },          },
111                    
# Line 112  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    
# Line 162  Meteor = { Line 174  Meteor = {
174                  Meteor.log("Ping timeout");                  Meteor.log("Ping timeout");
175                  Meteor.mode="smartpoll";                  Meteor.mode="smartpoll";
176                  clearTimeout(Meteor.pingtimer);                  clearTimeout(Meteor.pingtimer);
                 Meteor.connect();  
177                  Meteor.callbacks["changemode"]("poll");                  Meteor.callbacks["changemode"]("poll");
178                  Meteor.lastpingtime = false;                  Meteor.lastpingtime = false;
179                    Meteor.connect();
180          },          },
181    
182          process: function(id, channel, data) {          process: function(id, channel, data) {
183                  if (id == -1) {                  if (id == -1) {
184                          Meteor.log("Ping");                          Meteor.log("Ping");
185                          Meteor.ping();                          Meteor.ping();
186                  } else if (typeof(Meteor.channels[channel]) != "undefined" && id > Meteor.channels[channel].lastmsgreceived) {                  } else if (typeof(Meteor.channels[channel]) != "undefined") {
187                          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);
188                          Meteor.callbacks["process"](data);                          Meteor.callbacks["process"](data);
189                          Meteor.channels[channel].lastmsgreceived = id;                          Meteor.channels[channel].lastmsgreceived = id;
# Line 195  Meteor = { Line 207  Meteor = {
207          },          },
208    
209          reset: function() {          reset: function() {
210                  Meteor.log("Stream reset");                  if (Meteor.status != 6) {
211                  Meteor.ping();                          Meteor.log("Stream reset");
212                  Meteor.callbacks["reset"]();                          Meteor.ping();
213                  var now = new Date();                          Meteor.callbacks["reset"]();
214                  var t = now.getTime();                          var now = new Date();
215                  var x = Meteor.pollfreq - (t-Meteor.lastrequest);                          var t = now.getTime();
216                  if (x < 10) x = 10;                          var x = Meteor.pollfreq - (t-Meteor.lastrequest);
217                  setTimeout(Meteor.connect, x);                          if (x < 10) x = 10;
218                            setTimeout(Meteor.connect, x);
219                    }
220          },          },
221    
222          eof: function() {          eof: function() {
223                    Meteor.log("Received end of stream, will not reconnect");
224                  Meteor.callbacks["eof"]();                  Meteor.callbacks["eof"]();
225                    Meteor.setstatus(6);
226                    Meteor.disconnect();
227            },
228    
229            channelInfo: function(channel, id) {
230                    Meteor.channels[channel].lastmsgreceived = id;
231                    Meteor.log("Received channel info for channel "+channel+": resume from "+id);
232          },          },
233    
234          updatepollfreq: function() {          updatepollfreq: function() {
# Line 242  Meteor = { Line 264  Meteor = {
264                  Meteor.log("Frame load timeout");                  Meteor.log("Frame load timeout");
265                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);
266                  Meteor.setstatus(3);                  Meteor.setstatus(3);
267                  setTimeout(Meteor.connect, 5000);                  Meteor.pollmode();
268          },          },
269    
270          extract_xss_domain: function(old_domain) {          extract_xss_domain: function(old_domain) {
# Line 258  Meteor = { Line 280  Meteor = {
280                  //                              3 = Controller frame timeout, retrying.                  //                              3 = Controller frame timeout, retrying.
281                  //                              4 = Controller frame loaded and ready                  //                              4 = Controller frame loaded and ready
282                  //                              5 = Receiving data                  //                              5 = Receiving data
283                    //                              6 = End of stream, will not reconnect
284    
285                  if (Meteor.status != newstatus) {                  if (Meteor.status != newstatus) {
286                          Meteor.status = newstatus;                          Meteor.status = newstatus;

Legend:
Removed from v.40  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26