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

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

revision 31 by andrew.betts, Mon May 14 13:42:45 2007 UTC revision 32 by andrew.betts, Thu Dec 20 21:24:24 2007 UTC
# Line 8  parent.Meteor.register(this); Line 8  parent.Meteor.register(this);
8  var streamreq;  var streamreq;
9  var byteoffset;  var byteoffset;
10    
 Function.prototype.bind = function(obj) {  
         var method = this,  
         temp = function() {  
                 return method.apply(obj, arguments);  
         };  
         return temp;  
 }  
   
11  function abort() {  function abort() {
12          streamreq.abort();          streamreq.abort();
13  }  }
14    
15  function newXmlHttp() {  function newXmlHttp() {
16          var xmlhttp;      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
17          /*@cc_on @*/      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
18          /*@if (@_jscript_version >= 5)      try { return new XMLHttpRequest(); } catch(e) {}
19          try {      return null;
                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
         } catch (e) {  
                 try {  
                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                 } catch (E) {  
                         xmlhttp = false;  
                 }  
         }  
         @end @*/  
         if (!xmlhttp && typeof XMLHttpRequest!='undefined') {  
                 xmlhttp = new XMLHttpRequest();  
         }  
         return xmlhttp;  
20  }  }
21    
22  function startstream() {  function startstream() {
23          streamreq = newXmlHttp();          streamreq = newXmlHttp();
24          byteoffset = 0;          byteoffset = 0;
25          var url = get("subsurl")+"&template=2";          var url = parent.Meteor.getSubsUrl();
         var now = new Date();  
         var t = now.getTime();  
         url += "&nocache="+t;  
26          streamreq.open("GET", url, true);          streamreq.open("GET", url, true);
27          streamreq.onreadystatechange = handleresponse.bind(streamreq);          streamreq.onreadystatechange = function() {
28          streamreq.send(null);                  if (typeof streamreq == "undefined") return;
29  }                  if (streamreq.readyState == 3) {
30                            var buffer = streamreq.responseText;
31  function handleresponse() {                          var newdata = buffer.substring(byteoffset);
32          if (this.readyState == 3) {                          byteoffset = buffer.length;
33                  var buffer = this.responseText;                          while (1) {
34                  var newdata = buffer.substring(byteoffset);                                  var x = newdata.indexOf("<s"+"cript>p(");
35                  byteoffset = buffer.length;                                  if (x != -1) {
36                  var x = newdata.indexOf("parent.Meteor.setServerTime(");                                          y = newdata.indexOf("</"+"script>", x);
37                  if (x != -1) {                                          if (y != -1) {
38                          y = newdata.indexOf(");", x);                                                  eval(newdata.substring((x+8),y));
39                          if (y != -1) eval(newdata.substring(x,y+2));                                                  newdata = newdata.substring(y+9);
40                  }                                          } else {
41                  while (1) {  
42                          var x = newdata.indexOf("<s"+"cript>p(");                                                  // Last message is incomplete.  Ignore it and it will be fetched again
43                          if (x != -1) {                                                  break;
44                                  y = newdata.indexOf("</"+"script>", x);                                          }
                                 if (y != -1) {  
                                         eval(newdata.substring((x+8),y));  
                                         newdata = newdata.substring(y+9);  
45                                  } else {                                  } else {
46    
47                                          // Last message is corrupt or incomplete.  Ignore it and it will be fetched again                                          // No more messages
48                                          break;                                          break;
49                                  }                                  }
                         } else {  
   
                                 // No more messages  
                                 break;  
50                          }                          }
51                  }                          byteoffset = buffer.length-newdata.length;
52                  byteoffset = buffer.length-newdata.length;                  } else if (streamreq.readyState == 4) {
53          } else if (this.readyState == 4) {                          delete streamreq;
54                  delete streamreq;                          if (typeof(r)=="function") {
55                  if (typeof(startstream)=="function") {                                  r();
56                          startstream();                          }
                 } else if (typeof(r)=="function") {  
                         r();  
57                  }                  }
58          }          }
59            streamreq.send(null);
60  }  }
61    
62    
63    
64  startstream();  startstream();
65  </script>  </script>
66  </body>  </body>

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

  ViewVC Help
Powered by ViewVC 1.1.26