/[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 32 by andrew.betts, Thu Dec 20 21:24:24 2007 UTC revision 62 by andrew.betts, Thu Nov 27 00:33:21 2008 UTC
# Line 7  document.domain = domainparts[domainpart Line 7  document.domain = domainparts[domainpart
7  parent.Meteor.register(this);  parent.Meteor.register(this);
8  var streamreq;  var streamreq;
9  var byteoffset;  var byteoffset;
10    var newdata;
11    
12  function abort() {  function abort() {
13          streamreq.abort();          streamreq.abort();
14  }  }
15    
16  function newXmlHttp() {  function newXmlHttp() {
17      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}          var xhr = null;
18      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}          try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
19      try { return new XMLHttpRequest(); } catch(e) {}                  try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
20      return null;                          try { xhr = new XMLHttpRequest(); } catch(e) { return false }
21                    }
22            }
23            return xhr;
24  }  }
25    
26  function startstream() {  function startstream() {
27          streamreq = newXmlHttp();          streamreq = newXmlHttp();
28          byteoffset = 0;          byteoffset = 0;
29            newdata = "";
30          var url = parent.Meteor.getSubsUrl();          var url = parent.Meteor.getSubsUrl();
31          streamreq.open("GET", url, true);          streamreq.open("GET", url, true);
32          streamreq.onreadystatechange = function() {          streamreq.onreadystatechange = function() {
33                  if (typeof streamreq == "undefined") return;                  if (typeof streamreq == "undefined") return;
34                  if (streamreq.readyState == 3) {                  if (streamreq.readyState == 3) {
35                          var buffer = streamreq.responseText;                          extractEvents(streamreq.responseText);
                         var newdata = buffer.substring(byteoffset);  
                         byteoffset = buffer.length;  
                         while (1) {  
                                 var x = newdata.indexOf("<s"+"cript>p(");  
                                 if (x != -1) {  
                                         y = newdata.indexOf("</"+"script>", x);  
                                         if (y != -1) {  
                                                 eval(newdata.substring((x+8),y));  
                                                 newdata = newdata.substring(y+9);  
                                         } else {  
   
                                                 // Last message is incomplete.  Ignore it and it will be fetched again  
                                                 break;  
                                         }  
                                 } else {  
   
                                         // No more messages  
                                         break;  
                                 }  
                         }  
                         byteoffset = buffer.length-newdata.length;  
36                  } else if (streamreq.readyState == 4) {                  } else if (streamreq.readyState == 4) {
37                            extractEvents(streamreq.responseText);
38                          delete streamreq;                          delete streamreq;
39                          if (typeof(r)=="function") {                          if (typeof(r)=="function") {
40                                  r();                                  r();
# Line 57  function startstream() { Line 42  function startstream() {
42                  }                  }
43          }          }
44          streamreq.send(null);          streamreq.send(null);
45            parent.Meteor.lastrequest = parent.Meteor.time();
46  }  }
47    
48    function extractEvents(responsestr) {
49            newdata += responsestr.substring(byteoffset);
50            byteoffset = responsestr.length;
51            while (1) {
52                    var x = newdata.indexOf("<s"+"cript>");
53                    if (x != -1) {
54                            y = newdata.indexOf("</"+"script>", x);
55                            if (y != -1) {
56                                    eval(newdata.substring((x+8),y));
57                                    if (typeof newdata == 'undefined') break;  // If message was eof() then we're now in a freed script
58                                    newdata = newdata.substring(y+9);
59                            } else {
60    
61                                    // Last message is incomplete.  Ignore it and it will be processed next time
62                                    break;
63                            }
64                    } else {
65    
66                            // No more messages
67                            break;
68                    }
69            }
70    }
71    
72    
73  startstream();  startstream();

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

  ViewVC Help
Powered by ViewVC 1.1.26