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; |
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {} |
18 |
/*@cc_on @*/ |
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} |
19 |
/*@if (@_jscript_version >= 5) |
try { return new XMLHttpRequest(); } catch(e) {} |
20 |
try { |
return null; |
|
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
|
|
} catch (e) { |
|
|
try { |
|
|
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
|
|
} catch (E) { |
|
|
xmlhttp = false; |
|
|
} |
|
|
} |
|
|
@end @*/ |
|
|
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { |
|
|
xmlhttp = new XMLHttpRequest(); |
|
|
} |
|
|
return xmlhttp; |
|
21 |
} |
} |
22 |
|
|
23 |
function startstream() { |
function startstream() { |
24 |
streamreq = newXmlHttp(); |
streamreq = newXmlHttp(); |
25 |
byteoffset = 0; |
byteoffset = 0; |
26 |
var url = "http://"+location.hostname+"/push?channel="+get("channel")+"&id="+get("MHostId")+"&template=2"; |
newdata = ""; |
27 |
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; |
|
28 |
streamreq.open("GET", url, true); |
streamreq.open("GET", url, true); |
29 |
streamreq.onreadystatechange = handleresponse.bind(streamreq); |
streamreq.onreadystatechange = function() { |
30 |
|
if (typeof streamreq == "undefined") return; |
31 |
|
if (streamreq.readyState == 3) { |
32 |
|
extractEvents(streamreq.responseText); |
33 |
|
} else if (streamreq.readyState == 4) { |
34 |
|
extractEvents(streamreq.responseText); |
35 |
|
delete streamreq; |
36 |
|
if (typeof(r)=="function") { |
37 |
|
r(); |
38 |
|
} |
39 |
|
} |
40 |
|
} |
41 |
streamreq.send(null); |
streamreq.send(null); |
42 |
} |
} |
43 |
|
|
44 |
function handleresponse() { |
function extractEvents(responsestr) { |
45 |
if (this.readyState == 3) { |
newdata += responsestr.substring(byteoffset); |
46 |
var buffer = this.responseText; |
byteoffset = responsestr.length; |
47 |
var newdata = buffer.substring(byteoffset); |
while (1) { |
48 |
byteoffset = buffer.length; |
var x = newdata.indexOf("<s"+"cript>"); |
|
var x = newdata.indexOf("parent.Meteor.setServerTime("); |
|
49 |
if (x != -1) { |
if (x != -1) { |
50 |
y = newdata.indexOf(");", x); |
y = newdata.indexOf("</"+"script>", x); |
51 |
if (y != -1) eval(newdata.substring(x,y+2)); |
if (y != -1) { |
52 |
} |
eval(newdata.substring((x+8),y)); |
53 |
while (1) { |
if (typeof newdata == 'undefined') break; // If message was eof() then we're now in a freed script |
54 |
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; |
|
|
} |
|
55 |
} else { |
} else { |
56 |
|
|
57 |
// No more messages |
// Last message is incomplete. Ignore it and it will be processed next time |
58 |
break; |
break; |
59 |
} |
} |
60 |
} |
} else { |
61 |
byteoffset = buffer.length-newdata.length; |
|
62 |
} else if (this.readyState == 4) { |
// No more messages |
63 |
delete streamreq; |
break; |
|
if (typeof(startstream)=="function") { |
|
|
startstream(); |
|
|
} else if (typeof(r)=="function") { |
|
|
r(); |
|
64 |
} |
} |
65 |
} |
} |
66 |
} |
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
startstream(); |
startstream(); |
71 |
</script> |
</script> |
72 |
</body> |
</body> |