35 |
this.debugmode = false; |
this.debugmode = false; |
36 |
this.subsurl = false; |
this.subsurl = false; |
37 |
this.channels = {}; |
this.channels = {}; |
38 |
|
this.channelcount = 0; |
39 |
|
this.streamreq = false; |
40 |
|
this.byteoffset = 0; |
41 |
|
|
42 |
// Documented public properties |
// Documented public properties |
43 |
this.subdomain = "data"; |
this.subdomain = "data"; |
46 |
this.pollfreq = 2000; |
this.pollfreq = 2000; |
47 |
this.minpollfreq = 2000; |
this.minpollfreq = 2000; |
48 |
this.mode = "poll"; |
this.mode = "poll"; |
49 |
this.polltimeout=30000; |
this.polltimeout = 30000; |
50 |
this.pingtimeout = 10000; |
this.pingtimeout = 10000; |
51 |
this.maxmessages = 0; |
this.maxmessages = 0; |
52 |
this.status = 0; |
this.status = 0; |
96 |
if (this.debugmode) console.log("Joined channel "+channelname+", channel list follows"); |
if (this.debugmode) console.log("Joined channel "+channelname+", channel list follows"); |
97 |
if (this.debugmode) console.log(this.channels); |
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(); |
117 |
this.setstatus(1); |
this.setstatus(1); |
118 |
var surl = "http://" + this.subdomain + "." + location.hostname + "/" + this.dynamicpageaddress + "?id=" + this.MHostId; |
this.updateSubsUrl(); |
|
if (this.maxmessages && !this.persist) surl += "&maxmessages=" + this.maxmessages; |
|
|
for (var c in this.channels) { |
|
|
surl += "&channel="+c; |
|
|
if (this.channels[c].lastmsgreceived >= 0) { |
|
|
surl += "&restartfrom="+this.channels[c].lastmsgreceived; |
|
|
} else if (this.channels[c].backtrack > 0) { |
|
|
surl += "&backtrack="+this.channels[c].backtrack; |
|
|
} else if (this.channels[c].backtrack < 0 || isNaN(this.channels[c].backtrack)) { |
|
|
surl += "&restartfrom="; |
|
|
} |
|
|
} |
|
|
this.subsurl = surl; |
|
119 |
if (this.mode=="stream") { |
if (this.mode=="stream") { |
120 |
this.createIframe(this.subsurl); |
if (document.all) { |
121 |
|
this.createIframe(this.subsurl); |
122 |
|
} else { |
123 |
|
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/stream.html"); |
124 |
|
} |
125 |
var f = this.pollmode.bind(this); |
var f = this.pollmode.bind(this); |
126 |
clearTimeout(this.pingtimer); |
clearTimeout(this.pingtimer); |
127 |
this.pingtimer = setTimeout(f, this.pingtimeout); |
this.pingtimer = setTimeout(f, this.pingtimeout); |
128 |
|
|
129 |
} else { |
} else { |
130 |
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/poll.html"); |
this.createIframe("http://"+this.subdomain+"."+location.hostname+"/poll.html?nc="+t); |
131 |
this.recvtimes[0] = t; |
this.recvtimes[0] = t; |
132 |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer); |
133 |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500); |
135 |
this.lastrequest = t; |
this.lastrequest = t; |
136 |
} |
} |
137 |
|
|
138 |
|
Meteor.prototype.updateSubsUrl = function() { |
139 |
|
var surl = "http://" + this.subdomain + "." + location.hostname + "/" + this.dynamicpageaddress + "?id=" + this.MHostId; |
140 |
|
if (this.maxmessages && this.persist && this.mode != "stream") surl += "&maxmessages=" + this.maxmessages; |
141 |
|
if (this.mode == "poll" && this.maxmessages == 0 && this.persist==1) this.persist=0; |
142 |
|
surl += "&persist="+this.persist; |
143 |
|
for (var c in this.channels) { |
144 |
|
surl += "&channel="+c; |
145 |
|
if (this.channels[c].lastmsgreceived > 0) { |
146 |
|
surl += "&restartfrom="+(this.channels[c].lastmsgreceived+1); |
147 |
|
} else if (this.channels[c].backtrack > 0) { |
148 |
|
surl += "&backtrack="+this.channels[c].backtrack; |
149 |
|
} else if (this.channels[c].backtrack < 0 || isNaN(this.channels[c].backtrack)) { |
150 |
|
surl += "&restartfrom="; |
151 |
|
} |
152 |
|
} |
153 |
|
this.subsurl = surl; |
154 |
|
} |
155 |
|
|
156 |
Meteor.prototype.createIframe = function(url) { |
Meteor.prototype.createIframe = function(url) { |
157 |
if (document.all) { |
if (document.all) { |
158 |
this.transferDoc = new ActiveXObject("htmlfile"); |
this.transferDoc = new ActiveXObject("htmlfile"); |
176 |
ifr.style.zIndex = "-20"; |
ifr.style.zIndex = "-20"; |
177 |
ifr.setAttribute("id", "meteorframe_"+this.instID); |
ifr.setAttribute("id", "meteorframe_"+this.instID); |
178 |
ifr.Meteor = Meteor; |
ifr.Meteor = Meteor; |
179 |
var innerifr = document.createElement("IFRAME"); |
if (document.compatMode=='CSS1Compat') { |
180 |
innerifr.setAttribute("src", url); |
var innerifr = document.createElement("IFRAME"); |
181 |
innerifr.setAttribute("id", "meteorinnerframe_"+this.instID); |
innerifr.setAttribute("src", url); |
182 |
ifr.appendChild(innerifr); |
innerifr.setAttribute("id", "meteorinnerframe_"+this.instID); |
183 |
document.body.appendChild(ifr); |
ifr.appendChild(innerifr); |
184 |
|
document.body.appendChild(ifr); |
185 |
|
} else { |
186 |
|
ifr.setAttribute("src", url); |
187 |
|
document.body.appendChild(ifr); |
188 |
|
} |
189 |
} |
} |
190 |
if (this.debugmode) console.log("Loading URL '"+url+"' into frame..."); |
if (this.debugmode) console.log("Loading URL '"+url+"' into frame..."); |
191 |
var f = this.frameloadtimeout.bind(this); |
var f = this.frameloadtimeout.bind(this); |
200 |
document.getElementById("meteorframe_"+this.instID).src="about:blank"; |
document.getElementById("meteorframe_"+this.instID).src="about:blank"; |
201 |
document.body.removeChild(document.getElementById("meteorframe_"+this.instID)); |
document.body.removeChild(document.getElementById("meteorframe_"+this.instID)); |
202 |
} |
} |
203 |
if (!isNaN(this.pingtimer)) clearTimeout(this.pingtimer); |
clearTimeout(this.pingtimer); |
204 |
if (!isNaN(this.updatepollfreqtimer)) clearTimeout(this.updatepollfreqtimer); |
clearTimeout(this.updatepollfreqtimer); |
205 |
if (!isNaN(this.frameloadtimer)) clearTimeout(this.frameloadtimer); |
clearTimeout(this.frameloadtimer); |
206 |
this.setstatus(0); |
this.setstatus(0); |
207 |
} |
} |
208 |
|
|
229 |
while (this.recvtimes.length > 5) this.recvtimes.shift(); |
while (this.recvtimes.length > 5) this.recvtimes.shift(); |
230 |
} |
} |
231 |
} |
} |
232 |
|
this.updateSubsUrl(); |
233 |
this.setstatus(5); |
this.setstatus(5); |
234 |
} |
} |
235 |
|
|
313 |
} |
} |
314 |
} |
} |
315 |
|
|
316 |
|
|
317 |
Meteor.createCookie = function(name,value,days) { |
Meteor.createCookie = function(name,value,days) { |
318 |
if (days) { |
if (days) { |
319 |
var date = new Date(); |
var date = new Date(); |
337 |
|
|
338 |
Meteor.eraseCookie = function(name) { |
Meteor.eraseCookie = function(name) { |
339 |
createCookie(name,"",-1); |
createCookie(name,"",-1); |
|
} |
|
340 |
|
} |