From: Matteo Nastasi (mop) Date: Sat, 17 Dec 2011 16:34:59 +0000 (+0100) Subject: xhr refactoring: renaming xhr_rd to xhr, remove all xhr_rd_ prefixies from http_strea... X-Git-Tag: pre-sac~4 X-Git-Url: https://mop.ddnsfree.com/gitweb/?p=brisk.git;a=commitdiff_plain;h=5b549f2fc0c370d91ce2ea2d6719a85ea1489b9c xhr refactoring: renaming xhr_rd to xhr, remove all xhr_rd_ prefixies from http_streaming methods and attributes, start and stop new methods added --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 2465f79..d88eede 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -1416,7 +1416,7 @@ class Room { $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : ""); if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) { - $ret .= 'gst.st_loc++; hstm.the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|'; + $ret .= 'gst.st_loc++; hstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|'; // $ret .= 'gst.st_loc++; document.location.assign("index.php");|'; log_main("DOCUMENT.index.php: from table"); } diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 115f279..d298928 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1153,7 +1153,7 @@ class Bin5 { $user_cur->laccwr = $curtime; $ret = "gst.st = ".($user_cur->step+1)."; "; - $ret .= 'gst.st_loc++; hstm.the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|'; + $ret .= 'gst.st_loc++; hstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|'; log_wr($user_cur->sess." BIN5_WAKEUP: ".$ret); $user_cur->comm[$user_cur->step % COMM_N] = $ret; diff --git a/web/briskin5/index.php b/web/briskin5/index.php index 4010c9a..6a0b9e1 100644 --- a/web/briskin5/index.php +++ b/web/briskin5/index.php @@ -65,7 +65,7 @@ header('Content-type: text/html; charset="utf-8"',true); diff --git a/web/briskin5/index_rd.php b/web/briskin5/index_rd.php index defa83c..dae16ac 100644 --- a/web/briskin5/index_rd.php +++ b/web/briskin5/index_rd.php @@ -64,7 +64,7 @@ function blocking_error($is_unrecoverable) $is_page_streaming = TRUE; log_rd2("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE")); - return (sprintf(($is_unrecoverable ? 'hstm.the_end=true; ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");')); + return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");')); } function page_sync($sess, $page) @@ -73,7 +73,7 @@ function page_sync($sess, $page) $is_page_streaming = TRUE; log_rd2("PAGE_SYNC"); - return (sprintf('hstm.the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page)); + return (sprintf('hstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page)); } function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx, $table_token) @@ -100,7 +100,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if (($sem = Bin5::lock_data(FALSE, $table_idx)) == FALSE) { // wait 20 secs, then restart the xhr ignore_user_abort(FALSE); - return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); + return ("sleep(gst,20000);|hstm.xhr_abort();"); } if (($user = Bin5_user::load_data($table_idx, $proxy_step['i'], $sess)) == FALSE) { @@ -119,7 +119,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if (($sem = Bin5::lock_data(TRUE, $table_idx)) == FALSE) { // wait 20 secs, then restart the xhr ignore_user_abort(FALSE); - return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); + return ("sleep(gst,20000);|hstm.xhr_abort();"); } $S_load_stat['lL_laccgarb']++; @@ -196,7 +196,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su // else { // ignore_user_abort(FALSE); -// return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); +// return ("sleep(gst,20000);|hstm.xhr_abort();"); // } // $first_loop = FALSE; diff --git a/web/index.php b/web/index.php index 916f11e..170bb75 100644 --- a/web/index.php +++ b/web/index.php @@ -1066,7 +1066,7 @@ else { ?> sess = ""; - hstm = new http_streaming(); + hstm = new http_streaming("sess"); hstm.hbit_set(hbit); // xhr_rd.setRequestHeader("Content-type", "text/html; charset=utf-8"); tra = new train($('room_tit')); @@ -1080,7 +1080,7 @@ else { $("proflashext").innerHTML = ""; // console.log("session from main: "+sess); - hstm.xhr_rd_poll(sess); + hstm.start(sess); // alert("ARR LENGTH "+g_preload_img_arr.length); setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); $("txt_in").focus(); diff --git a/web/index_rd.php b/web/index_rd.php index 70dc3b0..4a30371 100644 --- a/web/index_rd.php +++ b/web/index_rd.php @@ -70,7 +70,7 @@ function blocking_error($is_unrecoverable) $is_page_streaming = TRUE; log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE")); - return (sprintf(($is_unrecoverable ? 'hstm.the_end=true; ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");')); + return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");')); } function page_sync($sess, $page, $table_idx, $table_token) @@ -82,7 +82,7 @@ function page_sync($sess, $page, $table_idx, $table_token) $is_page_streaming = TRUE; log_rd2("PAGE_SYNC"); - return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); hstm.the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("%s");', $table_idx, $table_token, $page)); + return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); hstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("%s");', $table_idx, $table_token, $page)); } @@ -123,7 +123,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if (($sem = Room::lock_data(FALSE)) == FALSE) { // wait 20 secs, then restart the xhr ignore_user_abort(FALSE); - return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); + return ("sleep(gst,20000);|hstm.xhr_abort();"); } // Verifica l'expire time lato server @@ -140,7 +140,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if (($sem = Room::lock_data(TRUE)) == FALSE) { // wait 20 secs, then restart the xhr ignore_user_abort(FALSE); - return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); + return ("sleep(gst,20000);|hstm.xhr_abort();"); } $S_load_stat['lL_laccgarb']++; @@ -216,7 +216,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su // // wait 20 secs, then restart the xhr // ignore_user_abort(FALSE); -// return ("sleep(gst,20000);|hstm.xhr_rd_abort();"); +// return ("sleep(gst,20000);|hstm.xhr_abort();"); // } // $first_loop = FALSE; // } // if ($first_loop == TRUE) { diff --git a/web/index_wr.php b/web/index_wr.php index 3dae210..6dfeea6 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -622,7 +622,7 @@ else if ($user->stat == 'room') { while (array_pop($user_cur->comm) != NULL); $ret = ""; - $ret .= sprintf('gst.st_loc++; gst.st=%d; createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); createCookie("lang", "%s", 24*365, cookiepath); hstm.the_end=true; window.onunload = null ; window.onbeforeunload = null ; document.location.assign("briskin5/index.php");|', $user_cur->step+1, $table_idx, $table_token, $G_lang); + $ret .= sprintf('gst.st_loc++; gst.st=%d; createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); createCookie("lang", "%s", 24*365, cookiepath); hstm.stop(); window.onunload = null ; window.onbeforeunload = null ; document.location.assign("briskin5/index.php");|', $user_cur->step+1, $table_idx, $table_token, $G_lang); $user_cur->comm[$user_cur->step % COMM_N] = $ret; $user_cur->trans_step = $user_cur->step + 1; diff --git a/web/xhr.js b/web/xhr.js index a72599c..16a3495 100644 --- a/web/xhr.js +++ b/web/xhr.js @@ -24,15 +24,17 @@ * MANDATORY * * NOT MANDATORY + * - remove hbit imple * - gst management * - sandbox management * - myfrom into the constructor * - target page into the constructor * - type of streaming into the constructor * - all iframe related streaming add - * - xhr_rd prefix remove from inner class attrs * - substitute fixed "eval" with a generic command hunks processor * + * DONE - xhr_rd prefix remove from inner class attrs + * */ function hbit(symb) @@ -44,31 +46,29 @@ function hbit(symb) else { $("heartbit").innerHTML += symb; } - // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!! - // console.log($("heartbit").innerHTML); - } -function http_streaming() +function http_streaming(cookiename) { - this.xhr_rd = createXMLHttpRequest(); + this.xhr = createXMLHttpRequest(); + this.cookiename = cookiename; } http_streaming.prototype = { - xhr_rd_cookiepath: "/brisk/", - - xhr_rd: null, - xhr_rd_watchdog: null, - xhr_rd_delay: 0, - xhr_rd_delayed: null, - xhr_rd_stopped: true, + cookiename: null, + cookiepath: "/brisk/", + xhr: null, + watchdog: null, + delay: 0, + delayed: null, + stopped: true, the_end: false, - xhr_rd_oldctx: "", - xhr_rd_newctx: "", - xhr_rd_cur_n: -1, - xhr_rd_old_n: -1, - xhr_rd_checkedlen: 0, - watchdog: 0, + oldctx: "", + newctx: "", + cur_n: -1, + old_n: -1, + checkedlen: 0, + /* watchdog_old: 0, */ ct: 0, hbit: function () { @@ -78,80 +78,90 @@ http_streaming.prototype = { this.hbit = hbit; }, - xhr_rd_cb: function () { + xhr_cb: function () { var ret; - if (this.xhr_rd.readyState == 4) { - if (this.xhr_rd_watchdog != null) { + if (this.xhr.readyState == 4) { + if (this.watchdog != null) { this.hbit('C'); - clearTimeout(this.xhr_rd_watchdog); - this.xhr_rd_watchdog = null; + clearTimeout(this.watchdog); + this.watchdog = null; } - // console.log("SS: "+safestatus(xhr_rd)); + // console.log("SS: "+safestatus(xhr)); try { - if ((ret = safestatus(this.xhr_rd)) == 200) { - this.xhr_rd_delay = 0; - // console.log("del a null "+this.xhr_rd_delayed); + if ((ret = safestatus(this.xhr)) == 200) { + this.delay = 0; + // console.log("del a null "+this.delayed); } else if (ret != -1) { - this.xhr_rd_delay = 5000; + this.delay = 5000; this.hbit('X'); // alert('There was a problem with the request.' + ret); } } catch(b) {}; - this.xhr_rd_delayed = null; - this.xhr_rd_stopped = true; + this.delayed = null; + this.stopped = true; } }, - xhr_rd_abort: function() + xhr_abort: function() { this.hbit('A'); - if (this.xhr_rd != null) - this.xhr_rd.abort(); + if (this.xhr != null) + this.xhr.abort(); // alert("de che"); }, - xhr_rd_start: function(sess, stat, subst, step) + run: function(sess, stat, subst, step) { if (this.the_end) { //x alert("the_end1"); - if (this.xhr_rd_watchdog != null) { + if (this.watchdog != null) { this.hbit('C'); - clearTimeout(this.xhr_rd_watchdog); - this.xhr_rd_watchdog = null; + clearTimeout(this.watchdog); + this.watchdog = null; } return; } - createCookie("sess", sess, 24*365, this.xhr_rd_cookiepath); + createCookie(this.cookie_name, sess, 24*365, this.cookiepath); // NOTE: *ctx = "" to prevent konqueror stream commands duplication. - this.xhr_rd_oldctx = ""; - this.xhr_rd_newctx = ""; + this.oldctx = ""; + this.newctx = ""; /* NOTE document.uniqueID exists only under IE */ // if (g_is_spawn == 1) // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : "")); - this.xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true); + this.xhr.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true); // try { var self = this; - this.xhr_rd.onreadystatechange = function () { self.xhr_rd_cb(); }; - this.xhr_rd.send(null); + this.xhr.onreadystatechange = function () { self.xhr_cb(); }; + this.xhr.send(null); // // TODO: qui avvio del timer per riavviare xhr // - this.xhr_rd_watchdog = setTimeout(function(obj){ obj.xhr_rd_abort(); }, 60000, this); - this.xhr_rd_cur_n++; - this.xhr_rd_stopped = false; + this.watchdog = setTimeout(function(obj){ obj.xhr_abort(); }, 60000, this); + this.cur_n++; + this.stopped = false; // } catch (e) {} }, /* WORK HERE TO RUN WIN OR LIN STREAM */ - xhr_rd_poll: function(sess) + start: function(sess) + { + this.poll(sess); + }, + + stop: function() + { + this.the_end = true; + }, + + poll: function(sess) { var tout = 100; var again; @@ -160,14 +170,14 @@ http_streaming.prototype = { this.ct++; /* - if (this.watchdog >= 50) { - this.watchdog = 0; - // alert("ABORT XHR_RD"); - this.xhr_rd_stopped = true; - this.xhr_rd.abort(); + if (this.watchdog_old >= 50) { + this.watchdog_old = 0; + // alert("ABORT XHR"); + this.stopped = true; + this.xhr.abort(); } */ - var zug = "XHR_RD_POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+this.xhr_rd_stopped; + var zug = "POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+this.stopped; if (zug != $("sandbox").innerHTML) $("sandbox").innerHTML = zug; @@ -195,45 +205,45 @@ http_streaming.prototype = { else { xhrrestart = 1; try { - if (this.xhr_rd == null) + if (this.xhr == null) throw "restart"; - if (this.xhr_rd.responseText != null) - this.xhr_rd_newctx = this.xhr_rd.responseText; + if (this.xhr.responseText != null) + this.newctx = this.xhr.responseText; } catch (e) { - if (this.xhr_rd_stopped == true) { - this.xhr_rd_stopped = false; + if (this.stopped == true) { + this.stopped = false; // XX $("xhrstart").innerHTML += "XHRSTART: da catch
"; - if (this.xhr_rd_delay > 0) { - if (this.xhr_rd_delayed == null) { - // console.log("XXX DI QUI "+this.xhr_rd_delay); + if (this.delay > 0) { + if (this.delayed == null) { + // console.log("XXX DI QUI "+this.delay); - this.xhr_rd_delayed = setTimeout( - function(f_obj, f_sess, f_stat, f_subst, f_step){ f_obj.xhr_rd_start(f_sess, f_stat, f_subst, f_step); }, - this.xhr_rd_delay, this, sess, stat, subst, gst.st); - // console.log("XXX DI QUI post"+this.xhr_rd_delayed); + this.delayed = setTimeout( + function(f_obj, f_sess, f_stat, f_subst, f_step){ f_obj.run(f_sess, f_stat, f_subst, f_step); }, + this.delay, this, sess, stat, subst, gst.st); + // console.log("XXX DI QUI post"+this.delayed); } } else { - // console.log("yyy DI QUI "+this.xhr_rd_delay); - this.xhr_rd_start(sess, stat, subst, gst.st); + // console.log("yyy DI QUI "+this.delay); + this.run(sess, stat, subst, gst.st); } } // $("sandbox").innerHTML += "return 1
"; if (this.the_end != true) { - this.watchdog = 0; - setTimeout(function(obj, sess){ obj.xhr_rd_poll(sess); }, tout, this, sess); + /* this.watchdog_old = 0; */ + setTimeout(function(obj, sess){ obj.poll(sess); }, tout, this, sess); // this.hbit("."); } else { //x alert("the_end2"); - if (this.xhr_rd_watchdog != null) { - clearTimeout(this.xhr_rd_watchdog); - this.xhr_rd_watchdog = null; + if (this.watchdog != null) { + clearTimeout(this.watchdog); + this.watchdog = null; } } return; @@ -241,9 +251,9 @@ http_streaming.prototype = { // no new char from the last loop, break - if (this.xhr_rd_old_n == this.xhr_rd_cur_n && - this.xhr_rd_newctx.length == this.xhr_rd_checkedlen) { - this.watchdog++; + if (this.old_n == this.cur_n && + this.newctx.length == this.checkedlen) { + /* this.watchdog++; */ break; } else { @@ -257,33 +267,33 @@ http_streaming.prototype = { var delta = 0; var match_lines = /^_*$/; - this.watchdog = 0; + /* this.watchdog = 0; */ this.hbit("/\\"); // check for the same command group - if (this.xhr_rd_old_n != this.xhr_rd_cur_n) { - this.xhr_rd_old_n = this.xhr_rd_cur_n; - this.xhr_rd_checkedlen = 0; - this.xhr_rd_oldctx = ""; + if (this.old_n != this.cur_n) { + this.old_n = this.cur_n; + this.checkedlen = 0; + this.oldctx = ""; } else - delta = this.xhr_rd_oldctx.length; + delta = this.oldctx.length; // $("xhrlog").innerHTML += "EVERY SEC
"; - for (i = delta ; i < this.xhr_rd_newctx.length ; i++) { - if (this.xhr_rd_newctx[i] != '_') + for (i = delta ; i < this.newctx.length ; i++) { + if (this.newctx[i] != '_') break; } - if (i == this.xhr_rd_newctx.length) { - this.xhr_rd_checkedlen = i; + if (i == this.newctx.length) { + this.checkedlen = i; break; } // $("xhrlog").innerHTML += "CHECK COM
"; // extracts the new part of the command string - comm_newpart = this.xhr_rd_newctx.substr(delta); + comm_newpart = this.newctx.substr(delta); - // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g"); + // XX $("xhrlog").innerHTML = newctx.replace("<", "<", "g"); // $("response").innerHTML = comm_newpart; comm_match = /_*@BEGIN@(.*?)@END@/g; @@ -294,7 +304,7 @@ http_streaming.prototype = { // $("sandbox").innerHTML += "PRE COMMARR
"; if (comm_arr) { // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"
"; - // XX alert("xhr_rd_newctx: "+this.xhr_rd_newctx); + // XX alert("newctx: "+this.newctx); // $("sandbox").innerHTML += "POST COMMARR
"; for (i = 0 ; i < comm_arr.length ; i++) { var temp = comm_arr[i].replace(comm_clean,"$1").split("|"); @@ -303,44 +313,44 @@ http_streaming.prototype = { comm_len += comm_arr[i].length; } tout = 0; - this.xhr_rd_oldctx += comm_newpart.substr(0,comm_len); - // XX alert("XHR_RD_OLDCTX: "+this.xhr_rd_oldctx); + this.oldctx += comm_newpart.substr(0,comm_len); + // XX alert("OLDCTX: "+this.oldctx); again = 1; } - this.xhr_rd_checkedlen = this.xhr_rd_oldctx.length; + this.checkedlen = this.oldctx.length; } } } while (again); - if (xhrrestart == 1 && this.xhr_rd_stopped == true) { + if (xhrrestart == 1 && this.stopped == true) { // $("sandbox").innerHTML += "LITTLE IF
"; // alert("di qui"); // XX $("xhrstart").innerHTML += "XHRSTART: da end poll
"; - if (this.xhr_rd_delay > 0) { - if (this.xhr_rd_delayed == null) { - // console.log("XXX DI QUO "+this.xhr_rd_delay); + if (this.delay > 0) { + if (this.delayed == null) { + // console.log("XXX DI QUO "+this.delay); - this.xhr_rd_delayed = setTimeout( - function(obj, sess, stat, subst, step){ obj.xhr_rd_start(sess, stat, subst, step); }, - this.xhr_rd_delay, this, sess, stat, subst, gst.st); - // console.log("XXX DI QUO post"+this.xhr_rd_delayed); + this.delayed = setTimeout( + function(obj, sess, stat, subst, step){ obj.run(sess, stat, subst, step); }, + this.delay, this, sess, stat, subst, gst.st); + // console.log("XXX DI QUO post"+this.delayed); } } else { - // console.log("yyy DI QUO "+this.xhr_rd_delay); - this.xhr_rd_start(sess, stat, subst, gst.st); + // console.log("yyy DI QUO "+this.delay); + this.run(sess, stat, subst, gst.st); } } if (this.the_end != true) { - setTimeout(function(obj, sess){ obj.xhr_rd_poll(sess); }, tout, this, sess); + setTimeout(function(obj, sess){ obj.poll(sess); }, tout, this, sess); } else { //x alert("the_end3"); - if (this.xhr_rd_watchdog != null) { - clearTimeout(this.xhr_rd_watchdog); - this.xhr_rd_watchdog = null; + if (this.watchdog != null) { + clearTimeout(this.watchdog); + this.watchdog = null; } } return; @@ -349,9 +359,9 @@ http_streaming.prototype = { /* window.onload = function () { - xhr_rd = createXMLHttpRequest(); + xhr = createXMLHttpRequest(); sess = $("user").value; - window.setTimeout(xhr_rd_poll, 0, sess); + window.setTimeout(poll, 0, sess); }; */