/[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

Annotation of /googlecode.com/svn/trunk/public_html/stream.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (hide annotations)
Fri Dec 8 16:52:58 2006 UTC (13 years, 11 months ago) by andrew.betts
File MIME type: text/html
File size: 2534 byte(s)


1 andrew.betts 9 <html>
2     <body>
3     <script type="text/javascript">
4     window.onError = null;
5     var domainparts = document.domain.split(".");
6     document.domain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];
7     parent.Meteor.register(this);
8     var streamreq;
9     var byteoffset;
10    
11     Function.prototype.bind = function(obj) {
12     var method = this,
13     temp = function() {
14     return method.apply(obj, arguments);
15     };
16     return temp;
17     }
18    
19     function abort() {
20     streamreq.abort();
21     }
22    
23     function newXmlHttp() {
24     var xmlhttp;
25     /*@cc_on @*/
26     /*@if (@_jscript_version >= 5)
27     try {
28     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
29     } catch (e) {
30     try {
31     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
32     } catch (E) {
33     xmlhttp = false;
34     }
35     }
36     @end @*/
37     if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
38     xmlhttp = new XMLHttpRequest();
39     }
40     return xmlhttp;
41     }
42    
43     function startstream() {
44     streamreq = newXmlHttp();
45     byteoffset = 0;
46     var url = "http://"+location.hostname+"/push?channel="+get("channel")+"&id="+get("MHostId")+"&template=2";
47     if (get("lastmsgreceived") >= 0) {
48     url += "&restartfrom="+(get("lastmsgreceived")+1);
49     } else if (get("backtrack") > 0) {
50     url += "&backtrack="+get("backtrack");
51     } else if (typeof(get("backtrack")) != "number") {
52     url += "&restartfrom=";
53     }
54     var now = new Date();
55     var t = now.getTime();
56     url += "&nocache="+t;
57     streamreq.open("GET", url, true);
58     streamreq.onreadystatechange = handleresponse.bind(streamreq);
59     streamreq.send(null);
60     }
61    
62     function handleresponse() {
63     if (this.readyState == 3) {
64     var buffer = this.responseText;
65     var newdata = buffer.substring(byteoffset);
66     byteoffset = buffer.length;
67     var x = newdata.indexOf("parent.Meteor.setServerTime(");
68     if (x != -1) {
69     y = newdata.indexOf(");", x);
70     if (y != -1) eval(newdata.substring(x,y+2));
71     }
72     while (1) {
73     var x = newdata.indexOf("<s"+"cript>p(");
74     if (x != -1) {
75     y = newdata.indexOf("</"+"script>", x);
76     if (y != -1) {
77     eval(newdata.substring((x+8),y));
78     newdata = newdata.substring(y+9);
79     } else {
80    
81     // Last message is corrupt or incomplete. Ignore it and it will be fetched again
82     break;
83     }
84     } else {
85    
86     // No more messages
87     break;
88     }
89     }
90     byteoffset = buffer.length-newdata.length;
91     } else if (this.readyState == 4) {
92     delete streamreq;
93     if (typeof(startstream)=="function") {
94     startstream();
95     } else if (typeof(r)=="function") {
96     r();
97     }
98     }
99     }
100    
101     startstream();
102     </script>
103     </body>
104 andrew.betts 3 </html>

  ViewVC Help
Powered by ViewVC 1.1.26