-function http_streaming(doc)
+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.doc = doc;
+ this.console = cons;
+ 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: 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: "",
+ ctx_old_len: 0,
+ // ctx_new: "",
+ ctx_new_len: 0,
+ stream: "",
start: function(page) {
- this.ifra.contentWindow.location.href = page;
+ 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 = page;
+ this.page = url_append_args(this.page, "sess", this.sess, "st", gst.st);
+ this.log(this.page);
+ 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 */
- console.log("watchdog ");
- 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;
+
+ // WATCHDOGING THE CONNECTION
+ if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
+ 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;
+ 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;
+ if (this.ifra.contentWindow.ctx_new.length == this.ctx_old_len) {
+ // this.ctx_new = this.ctx_old = "";
+ // FIXME find a more robust clean method
+ break;
+ }
+ this.log("new: "+ this.ifra.contentWindow.ctx_new.length + " old: "+this.ctx_old_len);
+ this.keepalive_new++;
+ for (i = this.ctx_old_len ; i < this.ifra.contentWindow.ctx_new.length ; i++) {
+ if (this.ifra.contentWindow.ctx_new[i] != '_')
+ break;
+ }
+ if (i == this.ifra.contentWindow.ctx_new.length) {
+ this.ctx_old_len = i;
+ break;
+ }
+ 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;
+ }
+ this.ctx_old += comm_newpart.substr(0,comm_len);
+ again = 1;
+ }
+ this.ctx_old_len = this.ctx_old.length;
+ } while (again);
- if (this.keepalives_equal > this.keepalives_eq_max) {
- console.log("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"); +"<br>";
+ //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() }, 2000, 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 = "";
+ this.ctx_old_len = 0;
+ },
+
+ reload: function () {
+ this.abort();
+ this.start(null);
+ },
+
+ log: function (s) {
+ if (this.console != null) {
+ return (this.console.log(s));
+ }
}
-
}
\ No newline at end of file