/[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 6 by andrew.betts, Tue Nov 21 09:49:07 2006 UTC revision 10 by andrew.betts, Thu Dec 14 10:45:43 2006 UTC
# Line 16  Function.prototype.andThen=function(g) { Line 16  Function.prototype.andThen=function(g) {
16                  f(a);g(args);                  f(a);g(args);
17          }          }
18  };  };
19    function addUnLoadEvent(func) {
20      var oldonunload = window.onunload;
21      if (typeof window.onunload != 'function') {
22        window.onunload = func;
23      } else {
24        window.onunload = function() {
25          if (oldonunload) {
26            oldonunload();
27          }
28          func();
29        }
30      }
31    }
32    //addUnLoadEvent(meteordestroy);
33    function meteordestroy() {
34            var x = Meteor.instances.length;
35            for(var i=0; i<x; i++) {
36                    Meteor.instances[i].stop();
37                    delete Meteor.instances[i];
38            }
39    }
40    
41  function Meteor(instID) {  function Meteor(instID) {
42    
# Line 30  function Meteor(instID) { Line 51  function Meteor(instID) {
51          this.callback_reset = function() {};          this.callback_reset = function() {};
52          this.callback_eof = function() {};          this.callback_eof = function() {};
53          this.callback_changemode = function() {};          this.callback_changemode = function() {};
54            this.callback_statuschanged = function() {};
55          this.persist = true;          this.persist = true;
56            this.frameloadtimer = false;
57            this.frameurl = false;
58    
59          // Documented public properties          // Documented public properties
60          this.channel = false;          this.channel = false;
# Line 44  function Meteor(instID) { Line 68  function Meteor(instID) {
68          this.polltimeout=30000;          this.polltimeout=30000;
69          this.maxmessages=0;          this.maxmessages=0;
70          this.pingtimeout = 10000;          this.pingtimeout = 10000;
71            this.status = 0;
72    
73            /* Statuses:    0 = Uninitialised,
74                                            1 = Loading stream,
75                                            2 = Loading controller frame,
76                                            3 = Controller frame timeout, retrying every 5 seconds
77                                            4 = Controller frame loaded and ready
78                                            5 = Receiving data
79            */
80    
         // Set or retrieve host id.  Cookie takes this form:  
         // MeteorID=123:6356353/124:098320454;  
         var MeteIds = Meteor.readCookie("MeteorID");  
         var regex1 = new RegExp("^([0-9\:\/M]+\/)*"+instID+"\:([^\/]+)(\/[0-9\:\/M]+)*$");  
         var regex2 = new RegExp("^([0-9\:\/M]+\/)*M\:([^\/]+)(\/[0-9\:\/M]+)*$");  
         if (typeof(instID) == "Number" && regex1.exec(MeteIds)) {  
                 this.MHostId = ma[2];  
         } else if (typeof(instID) == "Number") {  
                 this.MHostId = Math.floor(Math.random()*1000000);  
                 var newcookie = (MeteIds)?MeteIds+"/":"";  
                 newcookie += instID+":"+this.MHostId;  
                 Meteor.createCookie("MeteorID", newcookie);  
         } else if (ma = regex2.exec(MeteIds)) {  
                 this.MHostId = ma[2];  
         } else {  
                 this.MHostId = Math.floor(Math.random()*1000000);  
                 var newcookie = (MeteIds)?MeteIds+"/":"";  
                 newcookie += "M:"+this.MHostId;  
                 Meteor.createCookie("MeteorID", newcookie);  
         }  
81          this.instID = (typeof(instID) != "undefined") ? instID : 0;          this.instID = (typeof(instID) != "undefined") ? instID : 0;
82            this.MHostId = Math.floor(Math.random()*100000000)+this.instID;
83  }  }
84    
85  Meteor.instances = new Array();  Meteor.instances = new Array();
86  Meteor.servertimeoffset = 0;  Meteor.servertimeoffset = 0;
87    
88  Meteor.create = function(instID) {  Meteor.create = function(instID) {
89          if (!instID) instID = 0;          if (!instID) instID = Meteor.instances.length;
90          Meteor.instances[instID] = new Meteor(instID);          Meteor.instances[instID] = new Meteor(instID);
91          return Meteor.instances[instID];          return Meteor.instances[instID];
92  }  }
# Line 85  Meteor.register = function(ifr) { Line 99  Meteor.register = function(ifr) {
99          ifr.eof = this.instances[instid].eof.bind(this.instances[instid]);          ifr.eof = this.instances[instid].eof.bind(this.instances[instid]);
100          ifr.get = this.instances[instid].get.bind(this.instances[instid]);          ifr.get = this.instances[instid].get.bind(this.instances[instid]);
101          ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]);          ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]);
102            clearTimeout(this.instances[instid].frameloadtimer);
103            this.instances[instid].setstatus(4);
104  }  }
105    
106  Meteor.setServerTime = function(timestamp) {  Meteor.setServerTime = function(timestamp) {
# Line 110  Meteor.prototype.start = function() { Line 126  Meteor.prototype.start = function() {
126          }          }
127          if (this.mode=="stream") {          if (this.mode=="stream") {
128                  if (document.all) {                  if (document.all) {
129                            this.setstatus(1);
130                          this.transferDoc = new ActiveXObject("htmlfile");                          this.transferDoc = new ActiveXObject("htmlfile");
131                          this.transferDoc.open();                          this.transferDoc.open();
132                          this.transferDoc.write("<html>");                          this.transferDoc.write("<html>");
# Line 140  Meteor.prototype.start = function() { Line 157  Meteor.prototype.start = function() {
157                          ifr.style.zIndex = "-20";                          ifr.style.zIndex = "-20";
158                          ifr.id = "meteorframe_"+this.instID;                          ifr.id = "meteorframe_"+this.instID;
159                          document.body.appendChild(ifr);                          document.body.appendChild(ifr);
160                          ifr.src = "http://"+this.subdomain+"."+location.hostname+"/stream.html?nocache="+t;                          this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/stream.html";
161                            this.frameload();
162                  }                  }
163                  var f = this.pollmode.bind(this);                  var f = this.pollmode.bind(this);
164                  clearTimeout(this.pingtimer);                  clearTimeout(this.pingtimer);
# Line 160  Meteor.prototype.start = function() { Line 178  Meteor.prototype.start = function() {
178                  }                  }
179                  ifr.id = "meteorframe_"+this.instID;                  ifr.id = "meteorframe_"+this.instID;
180                  document.body.appendChild(ifr);                  document.body.appendChild(ifr);
181                  ifr.src = "http://"+this.subdomain+"."+location.hostname+"/poll.html?nocache="+t;                  this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/poll.html";
182                    this.frameload();
183                  this.recvtimes[0] = t;                  this.recvtimes[0] = t;
184                  if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer);                  if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer);
185                  this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500);                  this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500);
# Line 168  Meteor.prototype.start = function() { Line 187  Meteor.prototype.start = function() {
187          this.lastrequest = t;          this.lastrequest = t;
188  }  }
189    
190    Meteor.prototype.stop = function() {
191            if (typeof(this.transferDoc)=="object") {
192                    this.transferDoc.open();
193                    this.transferDoc.close();
194                    delete this.transferDoc;
195            }
196            if (document.getElementById("meteorframe_"+this.instID)) {
197                    document.getElementById("meteorframe_"+this.instID).src="about:blank";
198                    document.body.removeChild(document.getElementById("meteorframe_"+this.instID));
199            }
200            if (!isNaN(this.pingtimer)) clearTimeout(this.pingtimer);
201            if (!isNaN(this.updatepollfreqtimer)) clearTimeout(this.updatepollfreqtimer);
202            if (!isNaN(this.frameloadtimer)) clearTimeout(this.frameloadtimer);
203            this.setstatus(0);
204    }
205    
206  Meteor.prototype.pollmode = function() {  Meteor.prototype.pollmode = function() {
207          this.mode="poll";          this.mode="poll";
208          this.start();          this.start();
209          this.callback_changemode("poll");          this.callback_changemode("poll");
210            this.lastpingtime = false;
211  }  }
212    
213  Meteor.prototype.process = function(id, data) {  Meteor.prototype.process = function(id, data) {
# Line 187  Meteor.prototype.process = function(id, Line 223  Meteor.prototype.process = function(id,
223          } else if (id == -1) {          } else if (id == -1) {
224                  this.ping();                  this.ping();
225          }          }
226            this.setstatus(5);
227  }  }
228    
229  Meteor.prototype.ping = function() {  Meteor.prototype.ping = function() {
# Line 197  Meteor.prototype.ping = function() { Line 234  Meteor.prototype.ping = function() {
234                  var now = new Date();                  var now = new Date();
235                  this.lastpingtime = now.getTime();                  this.lastpingtime = now.getTime();
236          }          }
237            this.setstatus(5);
238  }  }
239    
240  Meteor.prototype.reset = function() {  Meteor.prototype.reset = function() {
# Line 249  Meteor.prototype.registerEventCallback = Line 287  Meteor.prototype.registerEventCallback =
287                  this.callback_eof = (this.callback_eof).andThen(funcRef);                  this.callback_eof = (this.callback_eof).andThen(funcRef);
288          } else if (evt=="changemode") {          } else if (evt=="changemode") {
289                  this.callback_changemode = (this.callback_changemode).andThen(funcRef);                  this.callback_changemode = (this.callback_changemode).andThen(funcRef);
290            } else if (evt=="changestatus") {
291                    this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef);
292          }          }
293  }  }
294    
295    Meteor.prototype.frameload = function() {
296            this.setstatus(2);
297            if (document.getElementById("meteorframe_"+this.instID)) {
298                    var f = this.frameloadtimeout.bind(this);
299                    this.frameloadtimer = setTimeout(f, 5000);
300                    document.getElementById("meteorframe_"+this.instID).src = "about:blank";
301                    setTimeout(this.doloadurl.bind(this), 100);
302            }
303    }
304    Meteor.prototype.doloadurl = function() {
305            var now = new Date();
306            var t = now.getTime();
307            document.getElementById("meteorframe_"+this.instID).src = this.frameurl+"?nocache="+t;
308    }
309    Meteor.prototype.frameloadtimeout = function() {
310            if (this.frameloadtimer) clearTimeout(this.frameloadtimer);
311            this.setstatus(3);
312            this.frameload();
313    }
314    Meteor.prototype.setstatus = function(newstatus) {
315            if (this.status != newstatus) {
316                    this.status = newstatus;
317                    this.callback_statuschanged(newstatus);
318            }
319    }
320    
321  Meteor.createCookie = function(name,value,days) {  Meteor.createCookie = function(name,value,days) {
322          if (days) {          if (days) {

Legend:
Removed from v.6  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26