36 |
ifr.p = Meteor.process; |
ifr.p = Meteor.process; |
37 |
ifr.r = Meteor.reset; |
ifr.r = Meteor.reset; |
38 |
ifr.eof = Meteor.eof; |
ifr.eof = Meteor.eof; |
39 |
|
ifr.ch = Meteor.channelInfo; |
40 |
clearTimeout(Meteor.frameloadtimer); |
clearTimeout(Meteor.frameloadtimer); |
41 |
Meteor.setstatus(4); |
Meteor.setstatus(4); |
42 |
Meteor.log("Frame registered"); |
Meteor.log("Frame registered"); |
44 |
|
|
45 |
joinChannel: function(channelname, backtrack) { |
joinChannel: function(channelname, backtrack) { |
46 |
if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
47 |
Meteor.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0}; |
Meteor.channels[channelname] = {backtrack:backtrack}; |
48 |
Meteor.log("Joined channel "+channelname); |
Meteor.log("Joined channel "+channelname); |
49 |
Meteor.channelcount++; |
Meteor.channelcount++; |
50 |
if (Meteor.status != 0) Meteor.connect(); |
if (Meteor.status != 0 && Meteor.status != 6) Meteor.connect(); |
51 |
}, |
}, |
52 |
|
|
53 |
leaveChannel: function(channelname) { |
leaveChannel: function(channelname) { |
54 |
if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
55 |
delete Meteor.channels[channelname]; |
delete Meteor.channels[channelname]; |
56 |
Meteor.log("Left channel "+channelname); |
Meteor.log("Left channel "+channelname); |
|
if (Meteor.status != 0) Meteor.connect(); |
|
57 |
Meteor.channelcount--; |
Meteor.channelcount--; |
58 |
|
if (Meteor.channelcount && Meteor.status != 0 && Meteor.status != 6) Meteor.connect(); |
59 |
|
else Meteor.disconnect(); |
60 |
}, |
}, |
61 |
|
|
62 |
connect: function() { |
connect: function() { |
85 |
Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html"); |
Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/poll.html"); |
86 |
Meteor.recvtimes[0] = t; |
Meteor.recvtimes[0] = t; |
87 |
if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer); |
if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer); |
88 |
if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 2500); |
if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 10000); |
89 |
if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq; |
if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq; |
90 |
} |
} |
91 |
Meteor.lastrequest = t; |
Meteor.lastrequest = t; |
97 |
clearTimeout(Meteor.updatepollfreqtimer); |
clearTimeout(Meteor.updatepollfreqtimer); |
98 |
clearTimeout(Meteor.frameloadtimer); |
clearTimeout(Meteor.frameloadtimer); |
99 |
if (typeof CollectGarbage == 'function') CollectGarbage(); |
if (typeof CollectGarbage == 'function') CollectGarbage(); |
100 |
Meteor.setstatus(0); |
if (Meteor.status != 6) Meteor.setstatus(0); |
101 |
|
Meteor.log("Disconnected"); |
102 |
|
try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { } |
103 |
|
try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {} |
104 |
} |
} |
105 |
}, |
}, |
106 |
|
|
117 |
var surl = "http://" + Meteor.host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode; |
var surl = "http://" + Meteor.host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode; |
118 |
for (var c in Meteor.channels) { |
for (var c in Meteor.channels) { |
119 |
surl += "/"+c; |
surl += "/"+c; |
120 |
if (Meteor.channels[c].lastmsgreceived > 0) { |
if (typeof Meteor.channels[c].lastmsgreceived != 'undefined' && Meteor.channels[c].lastmsgreceived >= 0) { |
121 |
surl += ".r"+(Meteor.channels[c].lastmsgreceived+1); |
surl += ".r"+(Meteor.channels[c].lastmsgreceived+1); |
122 |
} else if (Meteor.channels[c].backtrack > 0) { |
} else if (Meteor.channels[c].backtrack > 0) { |
123 |
surl += ".b"+Meteor.channels[c].backtrack; |
surl += ".b"+Meteor.channels[c].backtrack; |
124 |
} else if (Meteor.channels[c].backtrack < 0 || isNaN(Meteor.channels[c].backtrack)) { |
} else if (Meteor.channels[c].backtrack != undefined) { |
125 |
surl += ".h"; |
surl += ".h"; |
126 |
} |
} |
127 |
} |
} |
128 |
|
var now = new Date(); |
129 |
|
surl += "?nc="+now.getTime(); |
130 |
return surl; |
return surl; |
131 |
}, |
}, |
132 |
|
|
167 |
|
|
168 |
pollmode: function() { |
pollmode: function() { |
169 |
Meteor.log("Ping timeout"); |
Meteor.log("Ping timeout"); |
170 |
Meteor.mode="smartpoll"; |
if (Meteor.mode != "smartpoll") { |
171 |
clearTimeout(Meteor.pingtimer); |
Meteor.mode="smartpoll"; |
172 |
|
Meteor.callbacks["changemode"]("poll"); |
173 |
|
clearTimeout(Meteor.pingtimer); |
174 |
|
Meteor.lastpingtime = false; |
175 |
|
} |
176 |
Meteor.connect(); |
Meteor.connect(); |
|
Meteor.callbacks["changemode"]("poll"); |
|
|
Meteor.lastpingtime = false; |
|
177 |
}, |
}, |
178 |
|
|
179 |
process: function(id, channel, data) { |
process: function(id, channel, data) { |
180 |
if (id == -1) { |
if (id == -1) { |
181 |
Meteor.log("Ping"); |
Meteor.log("Ping"); |
182 |
Meteor.ping(); |
Meteor.ping(); |
183 |
} else if (typeof(Meteor.channels[channel]) != "undefined" && id > Meteor.channels[channel].lastmsgreceived) { |
} else if (typeof(Meteor.channels[channel]) != "undefined") { |
184 |
Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data); |
Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data); |
185 |
Meteor.callbacks["process"](data); |
Meteor.callbacks["process"](data); |
186 |
Meteor.channels[channel].lastmsgreceived = id; |
Meteor.channels[channel].lastmsgreceived = id; |
204 |
}, |
}, |
205 |
|
|
206 |
reset: function() { |
reset: function() { |
207 |
Meteor.log("Stream reset"); |
if (Meteor.status != 6 && Meteor.status != 0) { |
208 |
Meteor.ping(); |
Meteor.log("Stream reset"); |
209 |
Meteor.callbacks["reset"](); |
Meteor.ping(); |
210 |
var now = new Date(); |
Meteor.callbacks["reset"](); |
211 |
var t = now.getTime(); |
var now = new Date(); |
212 |
var x = Meteor.pollfreq - (t-Meteor.lastrequest); |
var t = now.getTime(); |
213 |
if (x < 10) x = 10; |
var x = Meteor.pollfreq - (t-Meteor.lastrequest); |
214 |
setTimeout(Meteor.connect, x); |
if (x < 10) x = 10; |
215 |
|
setTimeout(Meteor.connect, x); |
216 |
|
} |
217 |
}, |
}, |
218 |
|
|
219 |
eof: function() { |
eof: function() { |
220 |
|
Meteor.log("Received end of stream, will not reconnect"); |
221 |
Meteor.callbacks["eof"](); |
Meteor.callbacks["eof"](); |
222 |
|
Meteor.setstatus(6); |
223 |
|
Meteor.disconnect(); |
224 |
|
}, |
225 |
|
|
226 |
|
channelInfo: function(channel, id) { |
227 |
|
Meteor.channels[channel].lastmsgreceived = id; |
228 |
|
Meteor.log("Received channel info for channel "+channel+": resume from "+id); |
229 |
}, |
}, |
230 |
|
|
231 |
updatepollfreq: function() { |
updatepollfreq: function() { |
261 |
Meteor.log("Frame load timeout"); |
Meteor.log("Frame load timeout"); |
262 |
if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer); |
if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer); |
263 |
Meteor.setstatus(3); |
Meteor.setstatus(3); |
264 |
setTimeout(Meteor.connect, 5000); |
Meteor.pollmode(); |
265 |
}, |
}, |
266 |
|
|
267 |
extract_xss_domain: function(old_domain) { |
extract_xss_domain: function(old_domain) { |
277 |
// 3 = Controller frame timeout, retrying. |
// 3 = Controller frame timeout, retrying. |
278 |
// 4 = Controller frame loaded and ready |
// 4 = Controller frame loaded and ready |
279 |
// 5 = Receiving data |
// 5 = Receiving data |
280 |
|
// 6 = End of stream, will not reconnect |
281 |
|
|
282 |
if (Meteor.status != newstatus) { |
if (Meteor.status != newstatus) { |
283 |
Meteor.status = newstatus; |
Meteor.status = newstatus; |