/[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 61 - (hide annotations)
Thu Apr 17 20:03:54 2008 UTC (16 years ago) by andrew.betts
File MIME type: text/html
File size: 1783 byte(s)
Fixed: disconnect() behaviour
Fixed: Stream.html sometimes threw an error in Firefox after the frame had been rmeoved by the parent

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 andrew.betts 55 var newdata;
11 andrew.betts 9
12     function abort() {
13     streamreq.abort();
14     }
15    
16     function newXmlHttp() {
17 andrew.betts 32 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
18     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
19     try { return new XMLHttpRequest(); } catch(e) {}
20     return null;
21 andrew.betts 9 }
22    
23     function startstream() {
24     streamreq = newXmlHttp();
25     byteoffset = 0;
26 andrew.betts 55 newdata = "";
27 andrew.betts 32 var url = parent.Meteor.getSubsUrl();
28 andrew.betts 9 streamreq.open("GET", url, true);
29 andrew.betts 32 streamreq.onreadystatechange = function() {
30     if (typeof streamreq == "undefined") return;
31     if (streamreq.readyState == 3) {
32 andrew.betts 55 extractEvents(streamreq.responseText);
33 andrew.betts 32 } else if (streamreq.readyState == 4) {
34 andrew.betts 55 extractEvents(streamreq.responseText);
35 andrew.betts 32 delete streamreq;
36     if (typeof(r)=="function") {
37     r();
38     }
39 andrew.betts 9 }
40     }
41 andrew.betts 32 streamreq.send(null);
42 andrew.betts 9 }
43    
44 andrew.betts 55 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 andrew.betts 61 if (typeof newdata == 'undefined') break; // If message was eof() then we're now in a freed script
54 andrew.betts 55 newdata = newdata.substring(y+9);
55     } else {
56 andrew.betts 32
57 andrew.betts 55 // Last message is incomplete. Ignore it and it will be processed next time
58     break;
59     }
60     } else {
61 andrew.betts 32
62 andrew.betts 55 // No more messages
63     break;
64     }
65     }
66     }
67    
68    
69    
70 andrew.betts 9 startstream();
71     </script>
72     </body>
73 andrew.betts 3 </html>

  ViewVC Help
Powered by ViewVC 1.1.26