X-Git-Url: https://mop.ddnsfree.com/gitweb/?p=xynt.git;a=blobdiff_plain;f=web%2Fxynt%2Fxynt-http-streaming.js;h=f6b0a0bd46ee1c9247ea4d406e440b9d24f77049;hp=cb914e051cce4ae826a95a5081418d54e4b2c9d0;hb=1716e67da8e78da7de463d5224baeaaaca1cf2ff;hpb=d19a7117e6b2e345f5b7932afe1e68ade3ee1cb9 diff --git a/web/xynt/xynt-http-streaming.js b/web/xynt/xynt-http-streaming.js index cb914e0..f6b0a0b 100644 --- a/web/xynt/xynt-http-streaming.js +++ b/web/xynt/xynt-http-streaming.js @@ -1,55 +1,237 @@ -function http_streaming(doc, cons) +function globst() { + this.st = -1; + this.st_loc = -1; + this.st_loc_new = -1; + this.comms = new Array; +} + +globst.prototype = { + st: -1, + st_loc: -1, + st_loc_new: -1, + comms: null, + sleep_hd: null, + + sleep: function(delay) { + st.st_loc_new++; + + this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }}, + delay, this); + }, + + abort: function() { + if (this.sleep_hdl != null) { + clearTimeout(this.sleep_hdl); + this.sleep_hdl = null; + } + } +} + +function http_streaming(win, gst, sess, cons) { this.console = cons; - this.doc = doc; + this.win = win; + this.sess = sess; + this.doc = win.document; this.keepalive_old = -1; this.keepalive_new = -1; - this.keepalives_equal = 0; - this.ifra = 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.gst = gst; + this.cmdproc = function(com){eval(com);} } http_streaming.prototype = { console: null, + win: null, doc: null, + sess: null, ifra: null, + page: null, + watchdog_hdl: null, keepalive_old: -1, keepalive_new: -1, keepalives_equal: 0, keepalives_eq_max: 6, - watchdog_timeout: 2000, + watchdog_timeout: 100, + watchdog_ct: 0, + watchdog_checktm: 20, + watchable: false, + gst: null, + restart_n: 0, + cmdproc: null, + comm_match: /_*@BEGIN@(.*?)@END@/g, + comm_clean: /_*@BEGIN@(.*?)@END@/, + ctx_old_len: 0, + // ctx_new: "", + ctx_new_len: 0, + stream: "", start: function(page) { - this.log("http_streaming:start"); - this.ifra.contentWindow.location.href = page; - setTimeout(function(obj) { obj.watchdog(); }, this.watchdog_timeout, this); + this.log("http_streaming:start restart: "+this.restart_n); + this.keepalives_equal = 0; + this.ifra = this.doc.createElement("iframe"); + this.ifra.style.visibility = "hidden"; + this.doc.body.appendChild(this.ifra); + if (page != null) + this.page = url_complete(this.win.location.href, page); + this.page = url_append_args(this.page, "sess", this.sess, "st", this.gst.st); + this.log(this.page); + + // this.log(this.ifra); + this.ifra.contentWindow.location.href = this.page; + this.watchdog_ct = 0; + this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this); }, watchdog: function () { - /* +this.keepalives_equal */ - this.log("hs::watchdog: start"); - if (this.keepalive_old == this.keepalive_new) { - this.keepalives_equal++; - } - else { - this.keepalives_equal = 0; + var i, again; + var comm_newpart, comm_len, comm_arr; + var ctx_new_len; + + // WATCHDOGING THE CONNECTION + this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal); + if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) { + 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; + this.log("hs::watchdog: watchable = yes"); + } + } 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; + } } + + // PICK COMMANDS FROM STREAM + do { + // CHECK: maybe again here isn't needed + again = 0; + if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined') + break; + + ctx_new_length = this.ifra.contentWindow.ctx_new.length; + if (ctx_new_length == this.ctx_old_len) { + break; + } + this.log("new: "+ ctx_new_length + " old: "+this.ctx_old_len); + this.keepalive_new++; + for (i = this.ctx_old_len ; i < ctx_new_length ; i++) { + if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') { + this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]"); + break; + } + else { + this.log("ctx_new.charAt(i) == '_'"); + } + } + this.ctx_old_len = i; + if (i == ctx_new_length) { + this.log("old_len == i"); + break; + } + else { + this.log("old_len != i: "+i); + } + comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ctx_old_len); + comm_len = 0; + comm_arr = comm_newpart.match(this.comm_match); + + if (comm_arr) { + for (i = 0 ; i < comm_arr.length ; i++) { + var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|"); + + this.gst.comms = this.gst.comms.concat(temp); + // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length); + comm_len += comm_arr[i].length; + } + again = 1; + } + this.ctx_old_len += comm_len; + } while (again); - if (this.keepalives_equal > this.keepalives_eq_max) { - this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal); + + + // EXECUTION OF STREAM COMMANDS + do { + again = 0; + //MOP ?? xhrrestart = 0; + if (this.gst.st_loc < this.gst.st_loc_new) { + // there is some slow actions running + break; + } + else if (this.gst.comms.length > 0) { + var singlecomm; + + singlecomm = this.gst.comms.shift(); + // alert("EXE"+gugu); + // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"
"; + //xx this.hbit("+"); + + this.cmdproc(singlecomm); + again = 1; + } + } while (again); + + + this.watchdog_ct++; + this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this); + return; + }, + + keepalive: function (s) { + this.log("hs::keepalive"); + if (s != null) { + this.log(s); + this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@"; } else { - setTimeout(function(obj) { obj.watchdog() }, this.watchdog_timeout, this); + this.ifra.contentWindow.ctx_new += "_"; } + // this.keepalive_new++; }, - - keepalive: function () { - this.keepalive_new++; + + abort: function () { + // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname); + + this.gst.abort(); + if (this.watchdog_hdl != null) { + clearTimeout(this.watchdog_hdl); + this.watchdog_hdl = null; + } + + this.restart_n++; + this.log("hs::reload"); + this.watchable = false; + if (this.ifra != null) { + this.doc.body.removeChild(this.ifra); + delete this.ifra; + this.ifra = null; + } + this.ctx_old_len = 0; + }, + + reload: function () { + this.abort(); + this.start(null); }, log: function (s) {