/[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 9 by andrew.betts, Fri Dec 8 16:52:58 2006 UTC revision 64 by andrew.betts, Mon Jan 19 11:19:41 2009 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;
 Function.prototype.bind = function(obj) {  
         var method = this,  
         temp = function() {  
                 return method.apply(obj, arguments);  
         };  
         return temp;  
 }  
11    
12  function abort() {  function abort() {
13          streamreq.abort();          streamreq.abort();
14  }  }
15    
16  function newXmlHttp() {  function newXmlHttp() {
17          var xmlhttp;          var xhr = null;
18          /*@cc_on @*/          try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
19          /*@if (@_jscript_version >= 5)                  try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
20          try {                          try { xhr = new XMLHttpRequest(); } catch(e) { return false }
                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
         } catch (e) {  
                 try {  
                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                 } catch (E) {  
                         xmlhttp = false;  
21                  }                  }
22          }          }
23          @end @*/          return xhr;
         if (!xmlhttp && typeof XMLHttpRequest!='undefined') {  
                 xmlhttp = new XMLHttpRequest();  
         }  
         return xmlhttp;  
24  }  }
25    
26  function startstream() {  function startstream() {
27          streamreq = newXmlHttp();          streamreq = newXmlHttp();
28          byteoffset = 0;          byteoffset = 0;
29          var url = "http://"+location.hostname+"/push?channel="+get("channel")+"&id="+get("MHostId")+"&template=2";          newdata = "";
30          if (get("lastmsgreceived") >= 0) {          var url = parent.Meteor.getSubsUrl();
                 url += "&restartfrom="+(get("lastmsgreceived")+1);  
         } else if (get("backtrack") > 0) {  
                 url += "&backtrack="+get("backtrack");  
         } else if (typeof(get("backtrack")) != "number") {  
                 url += "&restartfrom=";  
         }  
         var now = new Date();  
         var t = now.getTime();  
         url += "&nocache="+t;  
31          streamreq.open("GET", url, true);          streamreq.open("GET", url, true);
32          streamreq.onreadystatechange = handleresponse.bind(streamreq);          streamreq.onreadystatechange = function() {
33                    if (typeof streamreq == "undefined") return;
34                    if (streamreq.readyState == 3) {
35                            extractEvents(streamreq.responseText);
36                    } else if (streamreq.readyState == 4) {
37                            extractEvents(streamreq.responseText);
38                            delete streamreq;
39                            if (typeof(r)=="function") {
40                                    r();
41                            }
42                    }
43            }
44          streamreq.send(null);          streamreq.send(null);
45            parent.Meteor.lastrequest = parent.Meteor.time();
46  }  }
47    
48  function handleresponse() {  function extractEvents(responsestr) {
49          if (this.readyState == 3) {          newdata += responsestr.substring(byteoffset);
50                  var buffer = this.responseText;          byteoffset = responsestr.length;
51                  var newdata = buffer.substring(byteoffset);          while (1) {
52                  byteoffset = buffer.length;                  var x = newdata.indexOf("<s"+"cript>");
                 var x = newdata.indexOf("parent.Meteor.setServerTime(");  
53                  if (x != -1) {                  if (x != -1) {
54                          y = newdata.indexOf(");", x);                          y = newdata.indexOf("</"+"script>", x);
55                          if (y != -1) eval(newdata.substring(x,y+2));                          if (y != -1) {
56                  }                                  eval(newdata.substring((x+8),y));
57                  while (1) {                                  if (typeof newdata == 'undefined') break;  // If message was eof() then we're now in a freed script
58                          var x = newdata.indexOf("<s"+"cript>p(");                                  newdata = newdata.substring(y+9);
                         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 corrupt or incomplete.  Ignore it and it will be fetched again  
                                         break;  
                                 }  
59                          } else {                          } else {
60    
61                                  // No more messages                                  // Last message is incomplete.  Ignore it and it will be processed next time
62                                  break;                                  break;
63                          }                          }
64                  }                  } else {
65                  byteoffset = buffer.length-newdata.length;  
66          } else if (this.readyState == 4) {                          // No more messages
67                  delete streamreq;                          break;
                 if (typeof(startstream)=="function") {  
                         startstream();  
                 } else if (typeof(r)=="function") {  
                         r();  
68                  }                  }
69          }          }
70  }  }
71    
72  startstream();  window.onload = function() {
73            if (parent.Meteor.status == 4) startstream();
74    }
75  </script>  </script>
76  </body>  </body>
77  </html>  </html>

Legend:
Removed from v.9  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26