23 |
this.pingtimer = false; |
this.pingtimer = false; |
24 |
this.updatepollfreqtimer = false; |
this.updatepollfreqtimer = false; |
25 |
this.lastrequest = 0; |
this.lastrequest = 0; |
26 |
this.recvtimes = new Array(); |
this.recvtimes = []; |
27 |
this.MHostId = false; |
this.MHostId = false; |
28 |
this.callback_process = function() {}; |
this.callback_process = function() {}; |
29 |
this.callback_reset = function() {}; |
this.callback_reset = function() {}; |
34 |
this.frameloadtimer = false; |
this.frameloadtimer = false; |
35 |
this.debugmode = false; |
this.debugmode = false; |
36 |
this.subsurl = false; |
this.subsurl = false; |
37 |
|
this.channels = {}; |
38 |
|
this.channelcount = 0; |
39 |
|
this.streamreq = false; |
40 |
|
this.byteoffset = 0; |
41 |
|
|
42 |
// Documented public properties |
// Documented public properties |
|
this.channels = new Array(); |
|
43 |
this.subdomain = "data"; |
this.subdomain = "data"; |
44 |
this.dynamicpageaddress = "push"; |
this.dynamicpageaddress = "push"; |
45 |
this.smartpoll = true; |
this.smartpoll = true; |
93 |
Meteor.prototype.joinChannel = function(channelname, backtrack) { |
Meteor.prototype.joinChannel = function(channelname, backtrack) { |
94 |
if (typeof(this.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
if (typeof(this.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed"; |
95 |
this.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0}; |
this.channels[channelname] = {backtrack:backtrack, lastmsgreceived:0}; |
96 |
|
if (this.debugmode) console.log("Joined channel "+channelname+", channel list follows"); |
97 |
|
if (this.debugmode) console.log(this.channels); |
98 |
if (this.status != 0) this.start(); |
if (this.status != 0) this.start(); |
99 |
|
this.channelcount++; |
100 |
} |
} |
101 |
|
|
102 |
Meteor.prototype.leaveChannel = function(channelname) { |
Meteor.prototype.leaveChannel = function(channelname) { |
103 |
if (typeof(this.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
if (typeof(this.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed"; |
104 |
delete this.channels[channelname]; |
delete this.channels[channelname]; |
105 |
if (this.status != 0) this.start(); |
if (this.status != 0) this.start(); |
106 |
|
this.channelcount--; |
107 |
} |
} |
108 |
|
|
109 |
Meteor.prototype.start = function() { |
Meteor.prototype.start = function() { |
110 |
this.persist = (this.maxmessages)?1:0; |
this.persist = (this.maxmessages)?1:0; |
111 |
this.smartpoll = (this.smartpoll)?1:0; |
this.smartpoll = (this.smartpoll)?1:0; |
112 |
this.mode = (this.mode=="stream")?"stream":"poll"; |
this.mode = (this.mode=="stream")?"stream":"poll"; |
113 |
if (!this.subdomain || this.channels.length) throw "Channel or Meteor subdomain host not specified"; |
if (!this.subdomain || !this.channelcount) throw "Channel or Meteor subdomain host not specified"; |
114 |
this.stop(); |
this.stop(); |
115 |
var now = new Date(); |
var now = new Date(); |
116 |
var t = now.getTime(); |
var t = now.getTime(); |
119 |
if (this.maxmessages && !this.persist) surl += "&maxmessages=" + this.maxmessages; |
if (this.maxmessages && !this.persist) surl += "&maxmessages=" + this.maxmessages; |
120 |
for (var c in this.channels) { |
for (var c in this.channels) { |
121 |
surl += "&channel="+c; |
surl += "&channel="+c; |
122 |
if (this.channels[c].lastmsgreceived >= 0) { |
if (this.channels[c].lastmsgreceived > 0) { |
123 |
surl += "&restartfrom="+this.channels[c].lastmsgreceived; |
surl += "&restartfrom="+this.channels[c].lastmsgreceived; |
124 |
} else if (this.channels[c].backtrack > 0) { |
} else if (this.channels[c].backtrack > 0) { |
125 |
surl += "&backtrack="+this.channels[c].backtrack; |
surl += "&backtrack="+this.channels[c].backtrack; |
129 |
} |
} |
130 |
this.subsurl = surl; |
this.subsurl = surl; |
131 |
if (this.mode=="stream") { |
if (this.mode=="stream") { |
132 |
this.createIframe(this.subsurl); |
if (document.all) { |
133 |
|
this.createIframe(this.subsurl); |
134 |
|
} else { |
135 |
|
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/stream.html"); |
136 |
|
} |
137 |
var f = this.pollmode.bind(this); |
var f = this.pollmode.bind(this); |
138 |
clearTimeout(this.pingtimer); |
clearTimeout(this.pingtimer); |
139 |
this.pingtimer = setTimeout(f, this.pingtimeout); |
this.pingtimer = setTimeout(f, this.pingtimeout); |
154 |
this.transferDoc.write("<html>"); |
this.transferDoc.write("<html>"); |
155 |
this.transferDoc.write("<script>document.domain=\""+(document.domain)+"\";</"+"script>"); |
this.transferDoc.write("<script>document.domain=\""+(document.domain)+"\";</"+"script>"); |
156 |
this.transferDoc.write("</html>"); |
this.transferDoc.write("</html>"); |
|
var selfref = this; |
|
157 |
this.transferDoc.parentWindow.Meteor = Meteor; |
this.transferDoc.parentWindow.Meteor = Meteor; |
158 |
this.transferDoc.close(); |
this.transferDoc.close(); |
159 |
var ifrDiv = this.transferDoc.createElement("div"); |
var ifrDiv = this.transferDoc.createElement("div"); |
170 |
ifr.style.zIndex = "-20"; |
ifr.style.zIndex = "-20"; |
171 |
ifr.setAttribute("id", "meteorframe_"+this.instID); |
ifr.setAttribute("id", "meteorframe_"+this.instID); |
172 |
ifr.Meteor = Meteor; |
ifr.Meteor = Meteor; |
173 |
var innerifr = document.createElement("IFRAME"); |
if (document.compatMode=='CSS1Compat') { |
174 |
innerifr.setAttribute("src", url); |
var innerifr = document.createElement("IFRAME"); |
175 |
innerifr.setAttribute("id", "meteorinnerframe_"+this.instID); |
innerifr.setAttribute("src", url); |
176 |
ifr.appendChild(innerifr); |
innerifr.setAttribute("id", "meteorinnerframe_"+this.instID); |
177 |
document.body.appendChild(ifr); |
ifr.appendChild(innerifr); |
178 |
|
document.body.appendChild(ifr); |
179 |
|
} else { |
180 |
|
ifr.setAttribute("src", url); |
181 |
|
document.body.appendChild(ifr); |
182 |
|
} |
183 |
} |
} |
184 |
if (this.debugmode) console.log("Loading URL '"+url+"' into frame..."); |
if (this.debugmode) console.log("Loading URL '"+url+"' into frame..."); |
185 |
var f = this.frameloadtimeout.bind(this); |
var f = this.frameloadtimeout.bind(this); |
209 |
} |
} |
210 |
|
|
211 |
Meteor.prototype.process = function(id, channel, data) { |
Meteor.prototype.process = function(id, channel, data) { |
212 |
if (id > this.channels[channel].lastmsgreceived) { |
if (id == -1) { |
213 |
if (this.debugmode) console.log("Message "+id+" received on channel "+channel+": "+data); |
if (this.debugmode) console.log("Ping"); |
214 |
|
this.ping(); |
215 |
|
} else if (typeof(this.channels[channel]) != "undefined" && id > this.channels[channel].lastmsgreceived) { |
216 |
|
if (this.debugmode) console.log("Message "+id+" received on channel "+channel+" (last id on channel: "+this.channels[channel].lastmsgreceived+")\n"+data); |
217 |
this.callback_process(data); |
this.callback_process(data); |
218 |
this.channels[channel].lastmsgreceived = id; |
this.channels[channel].lastmsgreceived = id; |
219 |
if (this.mode=="poll") { |
if (this.mode=="poll") { |
222 |
this.recvtimes[this.recvtimes.length] = t; |
this.recvtimes[this.recvtimes.length] = t; |
223 |
while (this.recvtimes.length > 5) this.recvtimes.shift(); |
while (this.recvtimes.length > 5) this.recvtimes.shift(); |
224 |
} |
} |
|
} else if (id == -1) { |
|
|
if (this.debugmode) console.log("Ping"); |
|
|
this.ping(); |
|
225 |
} |
} |
226 |
this.setstatus(5); |
this.setstatus(5); |
227 |
} |
} |
306 |
} |
} |
307 |
} |
} |
308 |
|
|
309 |
|
|
310 |
Meteor.createCookie = function(name,value,days) { |
Meteor.createCookie = function(name,value,days) { |
311 |
if (days) { |
if (days) { |
312 |
var date = new Date(); |
var date = new Date(); |
330 |
|
|
331 |
Meteor.eraseCookie = function(name) { |
Meteor.eraseCookie = function(name) { |
332 |
createCookie(name,"",-1); |
createCookie(name,"",-1); |
|
} |
|
333 |
|
} |