/[meteor]/googlecode.com/svn/trunk/public_html/poll.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/poll.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (hide annotations)
Wed May 2 10:55:26 2007 UTC (12 years, 2 months ago) by andrew.betts
File MIME type: text/html
File size: 2785 byte(s)
updated javascript client

1 andrew.betts 9 <html>
2     <body>
3     <script type="text/javascript">
4     window.onError = null;
5     var domainparts = document.domain.split(".");
6     var thisdomain = document.domain;
7     var topdomain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];
8     document.domain = topdomain;
9     var lastrequesttime = 0;
10     var pollreq = false;
11     var polltimer = false;
12     var i=0;
13     var isaborted = 0;
14     parent.Meteor.register(this);
15    
16     Function.prototype.bind = function(obj) {
17     var method = this,
18     temp = function() {
19     return method.apply(obj, arguments);
20     };
21     return temp;
22     }
23    
24     function newXmlHttp() {
25     var xmlhttp;
26     /*@cc_on @*/
27     /*@if (@_jscript_version >= 5)
28     try {
29     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
30     } catch (e) {
31     try {
32     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
33     } catch (E) {
34     xmlhttp = false;
35     }
36     }
37     @end @*/
38     if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
39     xmlhttp = new XMLHttpRequest();
40     }
41     return xmlhttp;
42     }
43    
44     function poll() {
45     isaborted = 0;
46     try {
47     clearTimeout(polltimer);
48     } catch (e) {}
49     var byteoffset = 0;
50     var newdata;
51     document.domain = topdomain;
52 andrew.betts 18 var url = get("subsurl")+"&persist="+get("persist")+"&template=2";
53 andrew.betts 9 var now = new Date();
54     var t = now.getTime();
55     url += "&nocache="+t;
56     try {
57     document.domain = thisdomain;
58     } catch (e) {}
59     pollreq = newXmlHttp();
60     pollreq.onreadystatechange = handleresponse;
61     pollreq.open("GET", url, true);
62     lastrequesttime = t;
63     if (get("polltimeout")) polltimer = setTimeout(ptimeout, get("polltimeout"));
64     pollreq.send(null);
65     document.domain=topdomain;
66     }
67    
68     function handleresponse() {
69     if (typeof(pollreq) == "object" && pollreq.readyState == 4 && !isaborted) {
70     try {
71     clearTimeout(polltimer);
72     } catch (e) {}
73     if (typeof(topdomain) == "undefined") return false;
74     document.domain=topdomain;
75     newdata = pollreq.responseText;
76     var x = newdata.indexOf("parent.Meteor.setServerTime(");
77     if (x != -1) {
78     y = newdata.indexOf(");", x);
79     if (y != -1) eval(newdata.substring(x,y+2));
80     }
81     while (1) {
82     var x = newdata.indexOf("<s"+"cript>p(");
83     if (x != -1) {
84     y = newdata.indexOf("</"+"script>", x);
85     if (y != -1) {
86     eval(newdata.substring((x+8),y));
87     newdata = newdata.substring(y+9);
88     } else {
89     break;
90     }
91     } else {
92     break;
93     }
94     }
95     var now = new Date();
96     var t = now.getTime();
97     var x = get("pollfreq") - (t-lastrequesttime);
98     if (x < 10) x = 10;
99     setTimeout(poll, x);
100     }
101     }
102    
103     function ptimeout() {
104     isaborted = 1;
105     pollreq.abort();
106     delete pollreq;
107     clearTimeout(polltimer);
108     var now = new Date();
109     var t = now.getTime();
110     var x = get("pollfreq") - (t-lastrequesttime);
111     if (x < 10) x = 10;
112     setTimeout(poll, x);
113     }
114    
115     poll();
116    
117     </script>
118     </body>
119 andrew.betts 3 </html>

  ViewVC Help
Powered by ViewVC 1.1.26