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 |
|
Meteor.instances[i].stop(); |
37 |
|
delete Meteor.instances[i]; |
38 |
|
} |
39 |
|
} |
40 |
|
|
41 |
function Meteor(instID) { |
function Meteor(instID) { |
42 |
|
|
51 |
this.callback_reset = function() {}; |
this.callback_reset = function() {}; |
52 |
this.callback_eof = function() {}; |
this.callback_eof = function() {}; |
53 |
this.callback_changemode = function() {}; |
this.callback_changemode = function() {}; |
54 |
|
this.callback_statuschanged = function() {}; |
55 |
this.persist = true; |
this.persist = true; |
56 |
|
this.frameloadtimer = false; |
57 |
|
this.frameurl = false; |
58 |
|
|
59 |
// Documented public properties |
// Documented public properties |
60 |
this.channel = false; |
this.channel = false; |
68 |
this.polltimeout=30000; |
this.polltimeout=30000; |
69 |
this.maxmessages=0; |
this.maxmessages=0; |
70 |
this.pingtimeout = 10000; |
this.pingtimeout = 10000; |
71 |
|
this.status = 0; |
72 |
|
|
73 |
|
/* Statuses: 0 = Uninitialised, |
74 |
|
1 = Loading stream, |
75 |
|
2 = Loading controller frame, |
76 |
|
3 = Controller frame timeout, retrying every 5 seconds |
77 |
|
4 = Controller frame loaded and ready |
78 |
|
5 = Receiving data |
79 |
|
*/ |
80 |
|
|
|
// Set or retrieve host id. Cookie takes this form: |
|
|
// MeteorID=123:6356353/124:098320454; |
|
|
var MeteIds = Meteor.readCookie("MeteorID"); |
|
|
var regex1 = new RegExp("^([0-9\:\/M]+\/)*"+instID+"\:([^\/]+)(\/[0-9\:\/M]+)*$"); |
|
|
var regex2 = new RegExp("^([0-9\:\/M]+\/)*M\:([^\/]+)(\/[0-9\:\/M]+)*$"); |
|
|
if (typeof(instID) == "Number" && regex1.exec(MeteIds)) { |
|
|
this.MHostId = ma[2]; |
|
|
} else if (typeof(instID) == "Number") { |
|
|
this.MHostId = Math.floor(Math.random()*1000000); |
|
|
var newcookie = (MeteIds)?MeteIds+"/":""; |
|
|
newcookie += instID+":"+this.MHostId; |
|
|
Meteor.createCookie("MeteorID", newcookie); |
|
|
} else if (ma = regex2.exec(MeteIds)) { |
|
|
this.MHostId = ma[2]; |
|
|
} else { |
|
|
this.MHostId = Math.floor(Math.random()*1000000); |
|
|
var newcookie = (MeteIds)?MeteIds+"/":""; |
|
|
newcookie += "M:"+this.MHostId; |
|
|
Meteor.createCookie("MeteorID", newcookie); |
|
|
} |
|
81 |
this.instID = (typeof(instID) != "undefined") ? instID : 0; |
this.instID = (typeof(instID) != "undefined") ? instID : 0; |
82 |
|
this.MHostId = Math.floor(Math.random()*100000000)+this.instID; |
83 |
} |
} |
84 |
|
|
85 |
Meteor.instances = new Array(); |
Meteor.instances = new Array(); |
86 |
Meteor.servertimeoffset = 0; |
Meteor.servertimeoffset = 0; |
87 |
|
|
88 |
Meteor.create = function(instID) { |
Meteor.create = function(instID) { |
89 |
if (!instID) instID = 0; |
if (!instID) instID = Meteor.instances.length; |
90 |
Meteor.instances[instID] = new Meteor(instID); |
Meteor.instances[instID] = new Meteor(instID); |
91 |
return Meteor.instances[instID]; |
return Meteor.instances[instID]; |
92 |
} |
} |
99 |
ifr.eof = this.instances[instid].eof.bind(this.instances[instid]); |
ifr.eof = this.instances[instid].eof.bind(this.instances[instid]); |
100 |
ifr.get = this.instances[instid].get.bind(this.instances[instid]); |
ifr.get = this.instances[instid].get.bind(this.instances[instid]); |
101 |
ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]); |
ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]); |
102 |
|
clearTimeout(this.instances[instid].frameloadtimer); |
103 |
|
this.instances[instid].setstatus(4); |
104 |
} |
} |
105 |
|
|
106 |
Meteor.setServerTime = function(timestamp) { |
Meteor.setServerTime = function(timestamp) { |
126 |
} |
} |
127 |
if (this.mode=="stream") { |
if (this.mode=="stream") { |
128 |
if (document.all) { |
if (document.all) { |
129 |
|
this.setstatus(1); |
130 |
this.transferDoc = new ActiveXObject("htmlfile"); |
this.transferDoc = new ActiveXObject("htmlfile"); |
131 |
this.transferDoc.open(); |
this.transferDoc.open(); |
132 |
this.transferDoc.write("<html>"); |
this.transferDoc.write("<html>"); |
157 |
ifr.style.zIndex = "-20"; |
ifr.style.zIndex = "-20"; |
158 |
ifr.id = "meteorframe_"+this.instID; |
ifr.id = "meteorframe_"+this.instID; |
159 |
document.body.appendChild(ifr); |
document.body.appendChild(ifr); |
160 |
ifr.src = "http://"+this.subdomain+"."+location.hostname+"/stream.html?nocache="+t; |
this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/stream.html"; |
161 |
|
this.frameload(); |
162 |
} |
} |
163 |
var f = this.pollmode.bind(this); |
var f = this.pollmode.bind(this); |
164 |
clearTimeout(this.pingtimer); |
clearTimeout(this.pingtimer); |
178 |
} |
} |
179 |
ifr.id = "meteorframe_"+this.instID; |
ifr.id = "meteorframe_"+this.instID; |
180 |
document.body.appendChild(ifr); |
document.body.appendChild(ifr); |
181 |
ifr.src = "http://"+this.subdomain+"."+location.hostname+"/poll.html?nocache="+t; |
this.frameurl = "http://"+this.subdomain+"."+location.hostname+"/poll.html"; |
182 |
|
this.frameload(); |
183 |
this.recvtimes[0] = t; |
this.recvtimes[0] = t; |
184 |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
185 |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
187 |
this.lastrequest = t; |
this.lastrequest = t; |
188 |
} |
} |
189 |
|
|
190 |
|
Meteor.prototype.stop = function() { |
191 |
|
if (typeof(this.transferDoc)=="object") { |
192 |
|
this.transferDoc.open(); |
193 |
|
this.transferDoc.close(); |
194 |
|
delete this.transferDoc; |
195 |
|
} |
196 |
|
if (document.getElementById("meteorframe_"+this.instID)) { |
197 |
|
document.getElementById("meteorframe_"+this.instID).src="about:blank"; |
198 |
|
document.body.removeChild(document.getElementById("meteorframe_"+this.instID)); |
199 |
|
} |
200 |
|
if (!isNaN(this.pingtimer)) clearTimeout(this.pingtimer); |
201 |
|
if (!isNaN(this.updatepollfreqtimer)) clearTimeout(this.updatepollfreqtimer); |
202 |
|
if (!isNaN(this.frameloadtimer)) clearTimeout(this.frameloadtimer); |
203 |
|
this.setstatus(0); |
204 |
|
} |
205 |
|
|
206 |
Meteor.prototype.pollmode = function() { |
Meteor.prototype.pollmode = function() { |
207 |
this.mode="poll"; |
this.mode="poll"; |
208 |
this.start(); |
this.start(); |
209 |
this.callback_changemode("poll"); |
this.callback_changemode("poll"); |
210 |
|
this.lastpingtime = false; |
211 |
} |
} |
212 |
|
|
213 |
Meteor.prototype.process = function(id, data) { |
Meteor.prototype.process = function(id, data, timestamp) { |
214 |
if (id > this.lastmsgreceived) { |
if (id > this.lastmsgreceived) { |
215 |
this.callback_process(data); |
this.callback_process(data); |
216 |
if (id != -1) this.lastmsgreceived = id; |
if (id != -1) this.lastmsgreceived = id; |
223 |
} else if (id == -1) { |
} else if (id == -1) { |
224 |
this.ping(); |
this.ping(); |
225 |
} |
} |
226 |
|
this.setstatus(5); |
227 |
|
if (!isNaN(timestamp)) { |
228 |
|
Meteor.setServerTime(timestamp); |
229 |
|
} |
230 |
} |
} |
231 |
|
|
232 |
Meteor.prototype.ping = function() { |
Meteor.prototype.ping = function() { |
237 |
var now = new Date(); |
var now = new Date(); |
238 |
this.lastpingtime = now.getTime(); |
this.lastpingtime = now.getTime(); |
239 |
} |
} |
240 |
|
this.setstatus(5); |
241 |
} |
} |
242 |
|
|
243 |
Meteor.prototype.reset = function() { |
Meteor.prototype.reset = function() { |
290 |
this.callback_eof = (this.callback_eof).andThen(funcRef); |
this.callback_eof = (this.callback_eof).andThen(funcRef); |
291 |
} else if (evt=="changemode") { |
} else if (evt=="changemode") { |
292 |
this.callback_changemode = (this.callback_changemode).andThen(funcRef); |
this.callback_changemode = (this.callback_changemode).andThen(funcRef); |
293 |
|
} else if (evt=="changestatus") { |
294 |
|
this.callback_statuschanged = (this.callback_statuschanged).andThen(funcRef); |
295 |
} |
} |
296 |
} |
} |
297 |
|
|
298 |
|
Meteor.prototype.frameload = function() { |
299 |
|
this.setstatus(2); |
300 |
|
if (document.getElementById("meteorframe_"+this.instID)) { |
301 |
|
var f = this.frameloadtimeout.bind(this); |
302 |
|
this.frameloadtimer = setTimeout(f, 5000); |
303 |
|
document.getElementById("meteorframe_"+this.instID).src = "about:blank"; |
304 |
|
setTimeout(this.doloadurl.bind(this), 100); |
305 |
|
} |
306 |
|
} |
307 |
|
Meteor.prototype.doloadurl = function() { |
308 |
|
var now = new Date(); |
309 |
|
var t = now.getTime(); |
310 |
|
document.getElementById("meteorframe_"+this.instID).src = this.frameurl+"?nocache="+t; |
311 |
|
} |
312 |
|
Meteor.prototype.frameloadtimeout = function() { |
313 |
|
if (this.frameloadtimer) clearTimeout(this.frameloadtimer); |
314 |
|
this.setstatus(3); |
315 |
|
this.frameload(); |
316 |
|
} |
317 |
|
Meteor.prototype.setstatus = function(newstatus) { |
318 |
|
if (this.status != newstatus) { |
319 |
|
this.status = newstatus; |
320 |
|
this.callback_statuschanged(newstatus); |
321 |
|
} |
322 |
|
} |
323 |
|
|
324 |
Meteor.createCookie = function(name,value,days) { |
Meteor.createCookie = function(name,value,days) { |
325 |
if (days) { |
if (days) { |