From: Matteo Nastasi (mop) Date: Tue, 13 Nov 2012 08:39:13 +0000 (+0100) Subject: new class transport iframe decoupled from xynt_streaming to allow multiple transports X-Git-Tag: v4.0.1 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=f48d5700d29e4dec071f9f49940870266c92d38c;p=brisk.git new class transport iframe decoupled from xynt_streaming to allow multiple transports --- diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index c16d14c..815c8b4 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1412,6 +1412,7 @@ class Bin5 { break; case "index_wr.php": + // FIXME $content can be unset if (isset($table_idx) && isset($table_token)) { if (($bri = $s_a_p->app->match_get($table_idx, $table_token)) != FALSE) { ob_start(); diff --git a/web/briskin5/index.php b/web/briskin5/index.php index 7142f46..00121b8 100644 --- a/web/briskin5/index.php +++ b/web/briskin5/index.php @@ -110,7 +110,7 @@ window.onload = function() { preferences_update(); sess = ""; - xstm = new xynt_streaming(window, null /* console */, gst, 'table_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);}); + xstm = new xynt_streaming(window, 'iframe', null /* console */, gst, 'table_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);}); xstm.hbit_set(heartbit); window.onbeforeunload = onbeforeunload_cb; diff --git a/web/index.php b/web/index.php index 72658ba..b3126e3 100644 --- a/web/index.php +++ b/web/index.php @@ -1057,7 +1057,7 @@ else { ?> sess = ""; -xstm = new xynt_streaming(window, null /* console*/ , gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);}); +xstm = new xynt_streaming(window, 'iframe', null /* console*/ , gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);}); xstm.hbit_set(heartbit); tra = new train($('room_tit')); window.onunload = onunload_cb; diff --git a/web/xynt-streaming.js b/web/xynt-streaming.js index f716d8c..66227d5 100644 --- a/web/xynt-streaming.js +++ b/web/xynt-streaming.js @@ -1,8 +1,80 @@ // old targetpage == page and moved into start method -function xynt_streaming(win, console, gst, from, cookiename, sess, sandbox, page, cmdproc) +function transport_iframe(doc, page) +{ + this.doc = doc; + this.ifra = doc.createElement("iframe"); + this.ifra.style.visibility = "hidden"; + doc.body.appendChild(this.ifra); + this.ifra.contentWindow.location.href = page; +} + +transport_iframe.prototype = { + doc: null, + ifra: null, + + destroy: function () { /* public */ + if (this.ifra != null) { + this.doc.body.removeChild(this.ifra); + delete this.ifra; + this.ifra = null; + } + }, + + xstr_is_init: function () { /* public */ + return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined'); + }, + + /* only after a successfull is_initialized call */ + xstr_is_ready: function () { /* public */ + return (this.ifra.contentWindow.xynt_streaming == "ready"); + }, + + /* only after a successfull is_ready call to be sure the accessibility of the var */ + xstr_set: function (xynt_streaming) { /* public */ + this.ifra.contentWindow.xynt_streaming = xynt_streaming; + }, + + ctx_new_is_set: function () { /* public */ + return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined'); + }, + + ctx_new_curlen_get: function () { /* public */ + return (this.ifra.contentWindow.ctx_new.length); + }, + + ctx_new_getchar: function(idx) { /* public */ + }, + + ctx_old_len_is_set: function () { /* public */ + return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined'); + }, + + ctx_old_len_get: function () { /* public */ + return (this.ifra.contentWindow.ctx_old_len); + }, + + ctx_old_len_set: function (len) { /* public */ + this.ifra.contentWindow.ctx_old_len = len; + }, + + ctx_old_len_add: function (len) { /* public */ + this.ifra.contentWindow.ctx_old_len += len; + }, + + new_part: function () { /* public */ + return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len)); + }, + + scrcls_set: function (step) { /* public */ + this.ifra.contentWindow.script_clean = step; + } +} + +function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc) { this.win = win; + this.transp_type = transp_type; this.console = console; this.gst = gst; this.from = from; @@ -20,6 +92,8 @@ function xynt_streaming(win, console, gst, from, cookiename, sess, sandbox, page xynt_streaming.prototype = { win: null, + transp_type: null, + transp: null, console: null, gst: null, from: null, @@ -30,7 +104,6 @@ xynt_streaming.prototype = { cmdproc: null, doc: null, - ifra: null, cookiepath: "/brisk/", watchdog_hdl: null, hbit: null, @@ -59,19 +132,20 @@ xynt_streaming.prototype = { // alert("start"); this.log("xynt_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); + + // page arrangement this.page = url_complete(this.win.location.href, this.page); // stat, subst, this.gst.st this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from); - // alert(this.page); this.log(this.page); - // this.log(this.ifra); - this.ifra.contentWindow.location.href = this.page; - // this.ifra.src = this.page; + // transport instantiation + if (this.transp_type == "iframe") { + this.transp = new transport_iframe(this.doc, this.page); + } + + // watchdog setting this.watchdog_ct = 0; if (!this.the_end) { this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this); @@ -105,7 +179,8 @@ xynt_streaming.prototype = { if (!this.watchable) { do { try{ - if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined') + // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined') + if (!this.transp.xstr_is_init()) break; } catch(b) { @@ -116,8 +191,10 @@ xynt_streaming.prototype = { 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.xynt_streaming == "ready") { - this.ifra.contentWindow.xynt_streaming = this; + // if (this.ifra.contentWindow.xynt_streaming == "ready") { + if (this.transp.xstr_is_ready()) { + // this.ifra.contentWindow.xynt_streaming = this; + this.transp.xstr_set(this); this.watchable = true; this.watchdog_ct = 0; this.log("hs::watchdog: watchable = yes"); @@ -148,23 +225,27 @@ xynt_streaming.prototype = { // CHECK: maybe again here isn't needed again = 0; try { - if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' || - typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') + /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' || + typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */ + if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set()) break; } catch(b) { break; } - ctx_new_len = this.ifra.contentWindow.ctx_new.length; - if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) { + // ctx_new_len = this.ifra.contentWindow.ctx_new.length; + ctx_new_len = this.transp.ctx_new_curlen_get(); + // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) { + if (ctx_new_len <= this.transp.ctx_old_len_get()) { break; } - this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len); + this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get()); this.keepalive_new++; // alert("pre-loop 1"); - for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) { - if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') { + for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) { + // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') { + if (this.transp.ctx_new_getchar(i) != '_') { // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]"); break; } @@ -172,7 +253,8 @@ xynt_streaming.prototype = { // this.log("ctx_new.charAt(i) == '_'"); // } } - this.ifra.contentWindow.ctx_old_len = i; + // this.ifra.contentWindow.ctx_old_len = i; + this.transp.ctx_old_len_set(i); if (i == ctx_new_len) { this.log("old_len == i"); break; @@ -182,7 +264,7 @@ xynt_streaming.prototype = { } // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]"); - comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len); + comm_newpart = this.transp.new_part(); this.log("COM_NEWPART: ["+comm_newpart+"]"); comm_len = 0; comm_arr = comm_newpart.match(this.comm_match); @@ -197,8 +279,10 @@ xynt_streaming.prototype = { } again = 1; } - this.ifra.contentWindow.ctx_old_len += comm_len; - this.ifra.contentWindow.script_clean = this.gst.st; + // this.ifra.contentWindow.ctx_old_len += comm_len; + this.transp.ctx_old_len_add(comm_len); + // this.ifra.contentWindow.script_clean = this.gst.st; + this.transp.scrcls_set(this.gst.st); // alert("do--while end ["+again+"]"); } while (again); @@ -260,10 +344,10 @@ xynt_streaming.prototype = { 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; + if (this.transp != null) { + this.transp.destroy(); + delete this.transp; + this.transp = null; } },