16 |
f(a);g(args); |
f(a);g(args); |
17 |
} |
} |
18 |
}; |
}; |
19 |
|
function addUnLoadEvent(func) { |
20 |
|
var oldonunload = window.onunload; |
21 |
|
if (typeof window.onunload != 'function') { |
22 |
|
window.onunload = func; |
23 |
|
} else { |
24 |
|
window.onunload = function() { |
25 |
|
if (oldonunload) { |
26 |
|
oldonunload(); |
27 |
|
} |
28 |
|
func(); |
29 |
|
} |
30 |
|
} |
31 |
|
} |
32 |
|
addUnLoadEvent(meteordestroy); |
33 |
|
function meteordestroy() { |
34 |
|
var x = Meteor.instances.length; |
35 |
|
for(var i=0; i<x; i++) { |
36 |
|
if (typeof(Meteor.instances[i].transferDoc)=="object") { |
37 |
|
Meteor.instances[i].transferDoc.open(); |
38 |
|
Meteor.instances[i].transferDoc.close(); |
39 |
|
delete Meteor.instances[i].transferDoc; |
40 |
|
} |
41 |
|
if (document.getElementById("meteorframe_"+Meteor.instances[i].instID)) { |
42 |
|
document.body.removeChild(document.getElementById("meteorframe_"+Meteor.instances[i].instID)); |
43 |
|
} |
44 |
|
delete Meteor.instances[i]; |
45 |
|
} |
46 |
|
} |
47 |
|
|
48 |
function Meteor(instID) { |
function Meteor(instID) { |
49 |
|
|
58 |
this.callback_reset = function() {}; |
this.callback_reset = function() {}; |
59 |
this.callback_eof = function() {}; |
this.callback_eof = function() {}; |
60 |
this.callback_changemode = function() {}; |
this.callback_changemode = function() {}; |
61 |
|
this.callback_statuschanged = function() {}; |
62 |
this.persist = true; |
this.persist = true; |
63 |
|
this.frameloadtimer = false; |
64 |
|
this.frameurl = false; |
65 |
|
|
66 |
// Documented public properties |
// Documented public properties |
67 |
this.channel = false; |
this.channel = false; |
75 |
this.polltimeout=30000; |
this.polltimeout=30000; |
76 |
this.maxmessages=0; |
this.maxmessages=0; |
77 |
this.pingtimeout = 10000; |
this.pingtimeout = 10000; |
78 |
|
this.status = 0; |
79 |
|
|
80 |
|
/* Statuses: 0 = Uninitialised, |
81 |
|
1 = Loading stream, |
82 |
|
2 = Loading controller frame, |
83 |
|
3 = Controller frame timeout, retrying every 5 seconds |
84 |
|
4 = Controller frame loaded and ready |
85 |
|
5 = Receiving data |
86 |
|
*/ |
87 |
|
|
88 |
// Set or retrieve host id. Cookie takes this form: |
// Set or retrieve host id. Cookie takes this form: |
89 |
// MeteorID=123:6356353/124:098320454; |
// MeteorID=123:6356353/124:098320454; |
125 |
ifr.eof = this.instances[instid].eof.bind(this.instances[instid]); |
ifr.eof = this.instances[instid].eof.bind(this.instances[instid]); |
126 |
ifr.get = this.instances[instid].get.bind(this.instances[instid]); |
ifr.get = this.instances[instid].get.bind(this.instances[instid]); |
127 |
ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]); |
ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]); |
128 |
|
clearTimeout(this.instances[instid].frameloadtimer); |
129 |
|
this.instances[instid].setstatus(4); |
130 |
} |
} |
131 |
|
|
132 |
Meteor.setServerTime = function(timestamp) { |
Meteor.setServerTime = function(timestamp) { |
152 |
} |
} |
153 |
if (this.mode=="stream") { |
if (this.mode=="stream") { |
154 |
if (document.all) { |
if (document.all) { |
155 |
|
this.setstatus(1); |
156 |
this.transferDoc = new ActiveXObject("htmlfile"); |
this.transferDoc = new ActiveXObject("htmlfile"); |
157 |
this.transferDoc.open(); |
this.transferDoc.open(); |
158 |
this.transferDoc.write("<html>"); |
this.transferDoc.write("<html>"); |
183 |
ifr.style.zIndex = "-20"; |
ifr.style.zIndex = "-20"; |
184 |
ifr.id = "meteorframe_"+this.instID; |
ifr.id = "meteorframe_"+this.instID; |
185 |
document.body.appendChild(ifr); |
document.body.appendChild(ifr); |
186 |
ifr.src = "http://"+this.subdomain+"."+location.hostname+"/stream.html?nocache="+t; |
this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/stream.html"; |
187 |
|
this.frameload(); |
188 |
} |
} |
189 |
var f = this.pollmode.bind(this); |
var f = this.pollmode.bind(this); |
190 |
clearTimeout(this.pingtimer); |
clearTimeout(this.pingtimer); |
204 |
} |
} |
205 |
ifr.id = "meteorframe_"+this.instID; |
ifr.id = "meteorframe_"+this.instID; |
206 |
document.body.appendChild(ifr); |
document.body.appendChild(ifr); |
207 |
ifr.src = "http://"+this.subdomain+"."+location.hostname+"/poll.html?nocache="+t; |
this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/poll.html"; |
208 |
|
this.frameload(); |
209 |
this.recvtimes[0] = t; |
this.recvtimes[0] = t; |
210 |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
211 |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
217 |
this.mode="poll"; |
this.mode="poll"; |
218 |
this.start(); |
this.start(); |
219 |
this.callback_changemode("poll"); |
this.callback_changemode("poll"); |
220 |
|
this.lastpingtime = false; |
221 |
} |
} |
222 |
|
|
223 |
Meteor.prototype.process = function(id, data) { |
Meteor.prototype.process = function(id, data) { |
233 |
} else if (id == -1) { |
} else if (id == -1) { |
234 |
this.ping(); |
this.ping(); |
235 |
} |
} |
236 |
|
this.setstatus(5); |
237 |
} |
} |
238 |
|
|
239 |
Meteor.prototype.ping = function() { |
Meteor.prototype.ping = function() { |
244 |
var now = new Date(); |
var now = new Date(); |
245 |
this.lastpingtime = now.getTime(); |
this.lastpingtime = now.getTime(); |
246 |
} |
} |
247 |
|
this.setstatus(5); |
248 |
} |
} |
249 |
|
|
250 |
Meteor.prototype.reset = function() { |
Meteor.prototype.reset = function() { |
297 |
this.callback_eof = (this.callback_eof).andThen(funcRef); |
this.callback_eof = (this.callback_eof).andThen(funcRef); |
298 |
} else if (evt=="changemode") { |
} else if (evt=="changemode") { |
299 |
this.callback_changemode = (this.callback_changemode).andThen(funcRef); |
this.callback_changemode = (this.callback_changemode).andThen(funcRef); |
300 |
|
} else if (evt=="changestatus") { |
301 |
|
this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef); |
302 |
} |
} |
303 |
} |
} |
304 |
|
|
305 |
|
Meteor.prototype.frameload = function() { |
306 |
|
this.setstatus(2); |
307 |
|
if (document.getElementById("meteorframe_"+this.instID)) { |
308 |
|
var f = this.frameloadtimeout.bind(this); |
309 |
|
this.frameloadtimer = setTimeout(f, 5000); |
310 |
|
document.getElementById("meteorframe_"+this.instID).src = "about:blank"; |
311 |
|
setTimeout(this.doloadurl.bind(this), 100); |
312 |
|
} |
313 |
|
} |
314 |
|
Meteor.prototype.doloadurl = function() { |
315 |
|
var now = new Date(); |
316 |
|
var t = now.getTime(); |
317 |
|
document.getElementById("meteorframe_"+this.instID).src = this.frameurl+"?nocache="+t; |
318 |
|
} |
319 |
|
Meteor.prototype.frameloadtimeout = function() { |
320 |
|
if (this.frameloadtimer) clearTimeout(this.frameloadtimer); |
321 |
|
this.setstatus(3); |
322 |
|
this.frameload(); |
323 |
|
} |
324 |
|
Meteor.prototype.setstatus = function(newstatus) { |
325 |
|
if (this.status != newstatus) { |
326 |
|
this.status = newstatus; |
327 |
|
this.callback_statuschanged(newstatus); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
Meteor.createCookie = function(name,value,days) { |
Meteor.createCookie = function(name,value,days) { |
332 |
if (days) { |
if (days) { |