X-Git-Url: http://mop.ddnsfree.com/gitweb/?p=xynt.git;a=blobdiff_plain;f=web%2Fxynt%2Fxynt-http-streaming.js;fp=web%2Fxynt%2Fxynt-http-streaming.js;h=3988d1d199be282fb5c6dda6abb16220be668100;hp=cb914e051cce4ae826a95a5081418d54e4b2c9d0;hb=08d4ed7dda698da0d092bbd8a31c15bd2c447927;hpb=890e11d4b957d634f64c3a1fd4d4c9689b5fab9b diff --git a/web/xynt/xynt-http-streaming.js b/web/xynt/xynt-http-streaming.js index cb914e0..3988d1d 100644 --- a/web/xynt/xynt-http-streaming.js +++ b/web/xynt/xynt-http-streaming.js @@ -1,57 +1,94 @@ -function http_streaming(doc, cons) +function http_streaming(win, cons) { this.console = cons; - this.doc = doc; + this.doc = win.document; this.keepalive_old = -1; this.keepalive_new = -1; this.keepalives_equal = 0; - this.ifra = doc.createElement("iframe"); + this.ifra = this.doc.createElement("iframe"); this.ifra.style.visibility = "hidden"; - doc.body.appendChild(this.ifra); - // this.ifra.contentWindow.onload = function () { - // this.ifra.contentWindow.location.href = 'winstream_rdxxx.php'; - // } - + this.doc.body.appendChild(this.ifra); } http_streaming.prototype = { console: null, doc: null, ifra: null, + page: null, + wd_handle: null, keepalive_old: -1, keepalive_new: -1, keepalives_equal: 0, keepalives_eq_max: 6, watchdog_timeout: 2000, + watchable: false, + restart_n: 0, start: function(page) { - this.log("http_streaming:start"); + this.log("http_streaming:start restart: "+this.restart_n); + this.page = page; this.ifra.contentWindow.location.href = page; - setTimeout(function(obj) { obj.watchdog(); }, this.watchdog_timeout, this); + this.wd_handle = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this); }, watchdog: function () { /* +this.keepalives_equal */ - this.log("hs::watchdog: start"); + this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal); + if (!this.watchable) { + do { + if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined') + break; + /* + on IE7 the the window frame scope is cleaned after the href is set, so we wait + for a well know variable value before assign this object value to it (OO is a passion) + */ + if (this.ifra.contentWindow.http_streaming == "ready") { + this.ifra.contentWindow.http_streaming = this; + this.watchable = true; + } + } while (false); + } + this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new); if (this.keepalive_old == this.keepalive_new) { this.keepalives_equal++; } else { + this.keepalive_old = this.keepalive_new; this.keepalives_equal = 0; } if (this.keepalives_equal > this.keepalives_eq_max) { this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal); + this.reload(); + return; } else { - setTimeout(function(obj) { obj.watchdog() }, this.watchdog_timeout, this); + this.wd_handle = setTimeout(function(obj) { obj.log("tout2"); obj.watchdog(); }, this.watchdog_timeout, this); } }, keepalive: function () { + this.log("hs::keepalive"); this.keepalive_new++; }, + abort: function () { + clearTimeout(this.wd_handle); + this.restart_n++; + this.log("hs::reload"); + this.watchable = false; + delete this.ifra; + }, + + reload: function () { + this.abort(); + this.keepalives_equal = 0; + this.ifra = this.doc.createElement("iframe"); + this.ifra.style.visibility = "hidden"; + this.doc.body.appendChild(this.ifra); + this.start(this.page); + }, + log: function (s) { if (this.console != null) { return (this.console.log(s));