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

Contents of /googlecode.com/svn/trunk/public_html/poll.html

Parent Directory Parent Directory | Revision Log Revision Log


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


1 <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 var url = "http://"+location.hostname+"/push?channel="+get("channel")+"&id="+get("MHostId")+"&persist="+get("persist")+"&template=2";
53 if (get("lastmsgreceived") >= 0) {
54 url += "&restartfrom="+(get("lastmsgreceived")+1);
55 } else if (get("backtrack") > 0) {
56 url += "&backtrack="+get("backtrack");
57 } else if (typeof(get("backtrack")) != "number") {
58 url += "&restartfrom=";
59 }
60 if (get("maxmessages") && get("persist")) url += "&maxmessages="+get("maxmessages");
61 var now = new Date();
62 var t = now.getTime();
63 url += "&nocache="+t;
64 try {
65 document.domain = thisdomain;
66 } catch (e) {}
67 pollreq = newXmlHttp();
68 pollreq.onreadystatechange = handleresponse;
69 pollreq.open("GET", url, true);
70 lastrequesttime = t;
71 if (get("polltimeout")) polltimer = setTimeout(ptimeout, get("polltimeout"));
72 pollreq.send(null);
73 document.domain=topdomain;
74 }
75
76 function handleresponse() {
77 if (typeof(pollreq) == "object" && pollreq.readyState == 4 && !isaborted) {
78 try {
79 clearTimeout(polltimer);
80 } catch (e) {}
81 if (typeof(topdomain) == "undefined") return false;
82 document.domain=topdomain;
83 newdata = pollreq.responseText;
84 var x = newdata.indexOf("parent.Meteor.setServerTime(");
85 if (x != -1) {
86 y = newdata.indexOf(");", x);
87 if (y != -1) eval(newdata.substring(x,y+2));
88 }
89 while (1) {
90 var x = newdata.indexOf("<s"+"cript>p(");
91 if (x != -1) {
92 y = newdata.indexOf("</"+"script>", x);
93 if (y != -1) {
94 eval(newdata.substring((x+8),y));
95 newdata = newdata.substring(y+9);
96 } else {
97 break;
98 }
99 } else {
100 break;
101 }
102 }
103 var now = new Date();
104 var t = now.getTime();
105 var x = get("pollfreq") - (t-lastrequesttime);
106 if (x < 10) x = 10;
107 setTimeout(poll, x);
108 }
109 }
110
111 function ptimeout() {
112 isaborted = 1;
113 pollreq.abort();
114 delete pollreq;
115 clearTimeout(polltimer);
116 var now = new Date();
117 var t = now.getTime();
118 var x = get("pollfreq") - (t-lastrequesttime);
119 if (x < 10) x = 10;
120 setTimeout(poll, x);
121 }
122
123 poll();
124
125 </script>
126 </body>
127 </html>

  ViewVC Help
Powered by ViewVC 1.1.26