/[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 54 by andrew.betts, Wed Feb 27 21:58:56 2008 UTC revision 55 by andrew.betts, Thu Feb 28 00:21:39 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();
# Line 22  function newXmlHttp() { Line 23  function newXmlHttp() {
23  function startstream() {  function startstream() {
24          streamreq = newXmlHttp();          streamreq = newXmlHttp();
25          byteoffset = 0;          byteoffset = 0;
26            newdata = "";
27          var url = parent.Meteor.getSubsUrl();          var url = parent.Meteor.getSubsUrl();
28          streamreq.open("GET", url, true);          streamreq.open("GET", url, true);
29          streamreq.onreadystatechange = function() {          streamreq.onreadystatechange = function() {
30                  if (typeof streamreq == "undefined") return;                  if (typeof streamreq == "undefined") return;
31                  if (streamreq.readyState == 3) {                  if (streamreq.readyState == 3) {
32                          var buffer = streamreq.responseText;                          extractEvents(streamreq.responseText);
                         var newdata = buffer.substring(byteoffset);  
                         byteoffset = buffer.length;  
                         while (1) {  
                                 var x = newdata.indexOf("<s"+"cript>");  
                                 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;  
33                  } else if (streamreq.readyState == 4) {                  } else if (streamreq.readyState == 4) {
34                            extractEvents(streamreq.responseText);
35                          delete streamreq;                          delete streamreq;
36                          if (typeof(r)=="function") {                          if (typeof(r)=="function") {
37                                  r();                                  r();
# Line 59  function startstream() { Line 41  function startstream() {
41          streamreq.send(null);          streamreq.send(null);
42  }  }
43    
44    function extractEvents(responsestr) {
45            newdata += responsestr.substring(byteoffset);
46            byteoffset = responsestr.length;
47            while (1) {
48                    var x = newdata.indexOf("<s"+"cript>");
49                    if (x != -1) {
50                            y = newdata.indexOf("</"+"script>", x);
51                            if (y != -1) {
52                                    eval(newdata.substring((x+8),y));
53                                    newdata = newdata.substring(y+9);
54                            } else {
55    
56                                    // Last message is incomplete.  Ignore it and it will be processed next time
57                                    break;
58                            }
59                    } else {
60    
61                            // No more messages
62                            break;
63                    }
64            }
65    }
66    
67    
68    
69  startstream();  startstream();

Legend:
Removed from v.54  
changed lines
  Added in v.55

  ViewVC Help
Powered by ViewVC 1.1.26