milestone 1 to move to an http_streaming object
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sat, 17 Dec 2011 15:54:01 +0000 (16:54 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sat, 17 Dec 2011 15:54:01 +0000 (16:54 +0100)
INSTALL.sh
web/Obj/brisk.phh
web/briskin5/Obj/briskin5.phh
web/briskin5/index.php
web/briskin5/index_rd.php
web/commons.js
web/index.php
web/index_rd.php
web/index_wr.php
web/room.js
web/xhr.js

index 70ba680..134d2fb 100755 (executable)
@@ -313,7 +313,7 @@ sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${
 
 sed -i "s@define *( *BRISK_AUTH_CONF,[^)]*)@define(BRISK_AUTH_CONF, \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
 
-sed -i "s@var \+xhr_rd_cookiepath \+= \+\"[^\"]*\";@var xhr_rd_cookiepath = \"$cookie_path\";@g" ${web_path}__/xhr.js
+sed -i "s@\( \+xhr_rd_cookiepath *: *\)\"[^\"]*\" *,@\1 \"$cookie_path\",@g" ${web_path}__/xhr.js
 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
 
 if [ -d ${web_path} ]; then
index 1aac984..2465f79 100644 (file)
@@ -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++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
+       $ret .= 'gst.st_loc++; hstm.the_end=true; 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");
       }
index 41cacfd..115f279 100644 (file)
@@ -1153,7 +1153,7 @@ class Bin5 {
       $user_cur->laccwr = $curtime;
 
       $ret = "gst.st = ".($user_cur->step+1)."; ";
-      $ret .= 'gst.st_loc++; the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
+      $ret .= 'gst.st_loc++; hstm.the_end=true; 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;
index 3d7f2ec..4010c9a 100644 (file)
@@ -64,7 +64,8 @@ header('Content-type: text/html; charset="utf-8"',true);
 </head>
 <body>
 <SCRIPT type="text/javascript">
-   var sess;
+   var sess = "not_connected";
+   var hstm;
    var g_lang = "<?php echo "$G_lang"; ?>";
    var stat = "table";
    var subst = "none";
@@ -72,12 +73,11 @@ header('Content-type: text/html; charset="utf-8"',true);
    var myfrom = "table_php";
    var g_withflash = false;
 
-var asta_ptr;
-var area_ptr;
-
-var gst  = new globst();
-gst.st = <?php 
+   var asta_ptr;
+   var area_ptr;
 
+   var gst  = new globst();
+   gst.st = <?php 
 log_load("bin5/index.php");
 
 if (isset($laststate) == false) {
@@ -99,13 +99,14 @@ window.onload = function() {
   preferences_init();
   preferences_update();
 
-  xhr_rd = createXMLHttpRequest();
   sess = "<?php echo "$sess"; ?>";
+  hstm = new http_streaming();
+  hstm.hbit_set(hbit);
   
   window.onbeforeunload = onbeforeunload_cb;  
   window.onunload = onunload_cb;  
 
-  setTimeout(xhr_rd_poll, 0, sess); 
+  hstm.xhr_rd_poll(sess); 
   setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
 }
 </SCRIPT>
index a571704..defa83c 100644 (file)
@@ -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 ? 'the_end=true; ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");'));
+  return (sprintf(($is_unrecoverable ? 'hstm.the_end=true; ' : '').'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('the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page));
+  return (sprintf('hstm.the_end=true; 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);|xhr_rd_abort(xhr_rd);");
+        return ("sleep(gst,20000);|hstm.xhr_rd_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);|xhr_rd_abort(xhr_rd);");
+            return ("sleep(gst,20000);|hstm.xhr_rd_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);|xhr_rd_abort(xhr_rd);");
+//             return ("sleep(gst,20000);|hstm.xhr_rd_abort();");
 //         }
         
 //         $first_loop = FALSE;
index 77be887..70859fe 100644 (file)
@@ -425,7 +425,7 @@ function postact_logout()
 {
     // alert("postact_logout");
     try { 
-       xhr_rd.abort();
+       hstm.abort();
     } catch (e) {}
 
     // eraseCookie("sess");
@@ -854,54 +854,20 @@ function eraseCookie(name) {
        createCookie(name,"",-1);
 }
 
-var onunload_times = 0;
-
-
 function onbeforeunload_cb () {
     return("");
 }
 
-function onunload_cb_old () {
-    var u = 0;
-    
-    //    if (nonunload == true)
-    //     return true;
-    
-    if (onunload_times == 0) {
-        // MLANG "    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
-       var res = window.confirm(mlang_commons['brileav'][g_lang]);
-       if (res == true) {
-           the_end = true; 
-           act_shutdown();
-           // while (1) 
-           //  u++;
-       }
-       else {
-           try {
-               document.location.href = self.location; //  = self.location;
-                // alert ("passiamo di qui"+self.location);
-                return (false);
-           } catch (e) {
-                // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
-               alert(mlang_commons['brireco'][g_lang]);
-           }
-       }
-       onunload_times++;
-    }
-    
-    return(false);
-}
-
 function onunload_cb () {
     
-    the_end = true; 
+    if (typeof(hstm) != "undefined")
+        hstm.the_end = true; 
 
     act_shutdown();
     
     return(false);
 }
 
-
 function room_checkspace(emme,tables,inpe)
 {
     nome = "<b>";
index ee5942e..916f11e 100644 (file)
@@ -870,17 +870,17 @@ supported by:<br>
 <title>Brisk</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <link rel="shortcut icon" href="img/brisk_ico.png">
+<script type="text/javascript" src="commons.js"></script> 
+<script type="text/javascript" src="myconsole.js"></script>
 <script type="text/javascript" src="menu.js"></script>
 <!-- <script type="text/javascript" src="dnd.js"></script>
 <script type="text/javascript" src="dom-drag.js"></script> -->
-<script type="text/javascript" src="commons.js"></script> 
 <script type="text/javascript" src="xhr.js"></script>
 <script type="text/javascript" src="preload_img<?php echo langtolng($G_lang); ?>.js"></script>
 <script type="text/javascript" src="AC_OETags.js"></script>
 <script type="text/javascript" src="room.js"></script>
 <script type="text/javascript" src="md5.js"></script>
 <script type="text/javascript" src="probrowser.js"></script>
-<!-- <script type="text/javascript" src="myconsole.js"></script>  -->
 <link rel="stylesheet" type="text/css" href="brisk.css">
 <link rel="stylesheet" type="text/css" href="room.css">
 
@@ -895,6 +895,7 @@ supported by:<br>
    var gst  = new globst();
    var topbanner_sfx, topbanner_dx;
    var g_brow = null;
+   var hstm = null;
    var sess = "not_connected";
    var spo_slide, sup_slide;
 
@@ -1003,21 +1004,21 @@ echo "$body"; ?>
 <head>
 <title>Brisk</title>
 <link rel="shortcut icon" href="img/brisk_ico.png">
+<script type="text/javascript" src="commons.js"></script>
+<script type="text/javascript" src="myconsole.js"></script>
 <script type="text/javascript" src="menu.js"></script>
 <!-- <script type="text/javascript" src="dnd.js"></script>
 <script type="text/javascript" src="dom-drag.js"></script> -->
-<script type="text/javascript" src="commons.js"></script> 
 <script type="text/javascript" src="ticker.js"></script>
 <script type="text/javascript" src="xhr.js"></script>
 <script type="text/javascript" src="room.js"></script>
 <script type="text/javascript" src="preload_img<?php echo langtolng($G_lang); ?>.js"></script>
 <script type="text/javascript" src="AC_OETags.js"></script>
 <script type="text/javascript" src="probrowser.js"></script>
-<!-- <script type="text/javascript" src="myconsole.js"></script>  -->
 <link rel="stylesheet" type="text/css" href="brisk.css">
 <link rel="stylesheet" type="text/css" href="room.css">
 <SCRIPT type="text/javascript"><!--
-   var sess;
+   var sess = "not_connected";
    var g_lang = "<? echo $G_lang; ?>";
    var g_lng = "<? echo $G_lng; ?>";
    var g_tables_n = <? echo TABLES_N; ?>;
@@ -1064,9 +1065,10 @@ else {
     }
 
 ?>
-     xhr_rd = createXMLHttpRequest();
-     // xhr_rd.setRequestHeader("Content-type", "text/html; charset=utf-8");
      sess = "<?php echo "$sess"; ?>";
+     hstm = new http_streaming();
+     hstm.hbit_set(hbit);
+     // xhr_rd.setRequestHeader("Content-type", "text/html; charset=utf-8");
      tra = new train($('room_tit'));
      window.onunload = onunload_cb;
      window.onbeforeunload = onbeforeunload_cb;
@@ -1077,7 +1079,8 @@ else {
      else
        $("proflashext").innerHTML = "";
 
-     setTimeout(xhr_rd_poll, 0, sess); 
+     // console.log("session from main: "+sess);
+     hstm.xhr_rd_poll(sess); 
      // alert("ARR LENGTH "+g_preload_img_arr.length);
      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
      $("txt_in").focus();
index 6e3e19d..70dc3b0 100644 (file)
@@ -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 ? 'the_end=true; ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
+  return (sprintf(($is_unrecoverable ? 'hstm.the_end=true; ' : '').'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); 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.the_end=true; 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);|xhr_rd_abort(xhr_rd);");
+        return ("sleep(gst,20000);|hstm.xhr_rd_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);|xhr_rd_abort(xhr_rd);");
+            return ("sleep(gst,20000);|hstm.xhr_rd_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);|xhr_rd_abort(xhr_rd);");
+//             return ("sleep(gst,20000);|hstm.xhr_rd_abort();");
 //         }
 //         $first_loop = FALSE;
 //     } // if  ($first_loop == TRUE) {
index 3c97733..3dae210 100644 (file)
@@ -497,7 +497,7 @@ else if ($user->stat == 'room') {
         log_wr("SITDOWN command");
 
       if ($user->the_end == TRUE) {
-       log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
+       log_wr("INFO:SKIP:argz == sitdown && ->the_end == TRUE => ignore request.");
        Room::unlock_data($sem);
        exit;
       }
@@ -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); 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.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);
           
           $user_cur->comm[$user_cur->step % COMM_N] = $ret;
           $user_cur->trans_step = $user_cur->step + 1;
index 4a53d50..43d282e 100644 (file)
@@ -123,7 +123,7 @@ var standup_data_old = null;
 
 function table_add(curtag, td)
 {
-    var tbody  = null, tr;
+    var tbody  = null, tr, ct;
 
     do {
         // console.log("wt: "+curtag.tagName);
index d023eb3..a72599c 100644 (file)
  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
  * Suite 330, Boston, MA 02111-1307, USA.
  *
+ * TODO:
+ *
+ *   MANDATORY
+ *
+ *   NOT MANDATORY
+ *   - 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
+ *
  */
 
-var xhr_rd_cookiepath = "/brisk/";
-var xhr_rd = null;
-var xhr_rd_stopped = true;
-var xhr_rd_oldctx = "";
-var xhr_rd_newctx = "";
-var xhr_rd_delay = 0;
-var xhr_rd_delayed = null;
-var xhr_rd_cur_n = -1;
-var xhr_rd_old_n = -1;
-var xhr_rd_checkedlen = 0;
-var xhr_rd_watchdog = null;
-var the_end = false;
-var ct = 0;
-var watchdog = 0;
-
 function hbit(symb)
 {
     if ($("heartbit").innerHTML.length >= 120) {
@@ -46,273 +45,308 @@ function hbit(symb)
         $("heartbit").innerHTML += symb;
     }
     // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!!
+    // console.log($("heartbit").innerHTML);
         
 }
 
-function xhr_rd_cb(xhr_rd) 
+function http_streaming()
 {
-    var ret;
-
-    // console.log(xhr_rd.readyState);
+    this.xhr_rd = createXMLHttpRequest();
+}
 
-    if (xhr_rd.readyState == 4) {
-        if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
-            hbit('C');
-            clearTimeout(xhr_rd_watchdog);
-            xhr_rd_watchdog = null;
-        }
+http_streaming.prototype = {
+    xhr_rd_cookiepath: "/brisk/",
 
-        // console.log("SS: "+safestatus(xhr_rd));
+    xhr_rd: null,
+    xhr_rd_watchdog: null,
+    xhr_rd_delay: 0,
+    xhr_rd_delayed: null,
+    xhr_rd_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,
+    ct: 0,
 
-       try {
-           if ((ret = safestatus(xhr_rd)) == 200) {
-                xhr_rd_delay = 0;
-                // console.log("del a null "+xhr_rd_delayed);
-           } else if (ret != -1) {
-                xhr_rd_delay = 5000;
-                hbit('X');
-               // alert('There was a problem with the request.' + ret);
-           }
-       } catch(b) {};
+    hbit: function () {
+    },
 
-        xhr_rd_delayed = null;
-       xhr_rd_stopped = true;
-    }
-};
+    hbit_set: function (hbit) {
+        this.hbit = hbit;
+    },
 
-function xhr_rd_abort(xhr)
-{
-    hbit('A');
-    if (xhr != null)
-        xhr.abort();
-    // alert("de che");
-}
-
-function xhr_rd_start(sess,stat,subst,step) 
-{
-    if (the_end) {
-        //x alert("the_end1");
-        if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
-            hbit('C');
-            clearTimeout(xhr_rd_watchdog);
-            xhr_rd_watchdog = null;
+    xhr_rd_cb: function () {
+        var ret;
+        
+        if (this.xhr_rd.readyState == 4) {
+            if (this.xhr_rd_watchdog != null) {
+                this.hbit('C');
+                clearTimeout(this.xhr_rd_watchdog);
+                this.xhr_rd_watchdog = null;
+            }
+            
+            // console.log("SS: "+safestatus(xhr_rd));
+            
+           try {
+               if ((ret = safestatus(this.xhr_rd)) == 200) {
+                    this.xhr_rd_delay = 0;
+                    // console.log("del a null "+this.xhr_rd_delayed);
+               } else if (ret != -1) {
+                    this.xhr_rd_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;
         }
-       return;
-    }
-    createCookie("sess", sess, 24*365, xhr_rd_cookiepath);
+    },
 
-    // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
-    xhr_rd_oldctx = "";
-    xhr_rd_newctx = "";
+    xhr_rd_abort: function()
+    {
+        this.hbit('A');
+        if (this.xhr_rd != null)
+            this.xhr_rd.abort();
+        // alert("de che");
+    },
 
-    /* NOTE document.uniqueID exists only under IE  */
-    // if (g_is_spawn == 1)
-    // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
-    xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
-    //    try { 
-    xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
-    xhr_rd.send(null);
-    // 
-    // TODO: qui avvio del timer per riavviare xhr
-    // 
-    xhr_rd_watchdog = setTimeout(xhr_rd_abort, 60000, xhr_rd);
-    xhr_rd_cur_n++;
-    xhr_rd_stopped = false;
-    // } catch (e) {}
-};
-
-function xhr_rd_poll(sess)
-{
-    var tout = 100;
-    var again;
-    var xhrrestart;
-    ct++;
-
-    /*
-    if (watchdog >= 50) {
-       watchdog = 0;
-       // alert("ABORT XHR_RD");
-       xhr_rd_stopped = true;
-       xhr_rd.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: "+xhr_rd_stopped;
-
-    if (zug != $("sandbox").innerHTML)
-       $("sandbox").innerHTML = zug;
+    xhr_rd_start: function(sess, stat, subst, step) 
+    {
+        if (this.the_end) {
+            //x alert("the_end1");
+            if (this.xhr_rd_watchdog != null) {
+                this.hbit('C');
+                clearTimeout(this.xhr_rd_watchdog);
+                this.xhr_rd_watchdog = null;
+            }
+           return;
+        }
+        createCookie("sess", sess, 24*365, this.xhr_rd_cookiepath);
+        
+        // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
+        this.xhr_rd_oldctx = "";
+        this.xhr_rd_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);
+        //    try { 
 
-    /* heartbit log */
-    hbit("_");
+        var self = this;
+        this.xhr_rd.onreadystatechange = function () { self.xhr_rd_cb(); };
+        this.xhr_rd.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;
+        // } catch (e) {}
+    },
     
-    do {
-       again = 0;
-       xhrrestart = 0;
-       if (gst.st_loc < gst.st_loc_new) {
-           // there is some slow actions running
-           break;
-       }
-       else if (gst.comms.length > 0) {
-           var singlecomm;
-
-           singlecomm = gst.comms.shift();
-           // alert("EXE"+gugu);
-           // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "&lt;", "g"); +"<br>";
-           hbit("+");
-
-           eval(singlecomm);
-           again = 1;
-       }
-       else {
-           xhrrestart = 1;
-           try { 
-               if (xhr_rd == null)
-                    throw "restart";
-               if (xhr_rd.responseText != null)
-                    xhr_rd_newctx = xhr_rd.responseText;
+    /* WORK HERE TO RUN WIN OR LIN STREAM */
+    
+    xhr_rd_poll: function(sess)
+    {
+        var tout = 100;
+        var again;
+        var xhrrestart;
+        
+        this.ct++;
+        
+        /*
+          if (this.watchdog >= 50) {
+         this.watchdog = 0;
+         // alert("ABORT XHR_RD");
+         this.xhr_rd_stopped = true;
+         this.xhr_rd.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;
+        
+        if (zug != $("sandbox").innerHTML)
+           $("sandbox").innerHTML = zug;
+        
+        /* heartbit log */
+        this.hbit("_");
+        do {
+           again = 0;
+           xhrrestart = 0;
+           if (gst.st_loc < gst.st_loc_new) {
+               // there is some slow actions running
+               break;
+           }
+           else if (gst.comms.length > 0) {
+               var singlecomm;
+                
+               singlecomm = gst.comms.shift();
+               // alert("EXE"+gugu);
+               // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "&lt;", "g"); +"<br>";
+               this.hbit("+");
+                
+               eval(singlecomm);
+               again = 1;
            }
-           catch (e) {
-               if (xhr_rd_stopped == true) {
-                   xhr_rd_stopped = false;
-                   // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
-                    if (xhr_rd_delay > 0) {
-                        if (xhr_rd_delayed == null) {
-                            // console.log("XXX DI QUI "+xhr_rd_delay);
-                            xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
-                            // console.log("XXX DI QUI post"+xhr_rd_delayed);
+           else {
+               xhrrestart = 1;
+               try { 
+                   if (this.xhr_rd == null)
+                        throw "restart";
+                   if (this.xhr_rd.responseText != null)
+                        this.xhr_rd_newctx = this.xhr_rd.responseText;
+               }
+               catch (e) {
+                   if (this.xhr_rd_stopped == true) {
+                       this.xhr_rd_stopped = false;
+                       // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
+                        if (this.xhr_rd_delay > 0) {
+                            if (this.xhr_rd_delayed == null) {
+                                // console.log("XXX DI QUI "+this.xhr_rd_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);
+                            }
+                        }
+                        else {
+                            // console.log("yyy DI QUI "+this.xhr_rd_delay);
+                            this.xhr_rd_start(sess, stat, subst, gst.st);
                         }
-                    }
+                   }
+                    
+                   
+                   // $("sandbox").innerHTML += "return 1<br>";
+                   if (this.the_end != true) {
+                       this.watchdog = 0;
+                        setTimeout(function(obj, sess){ obj.xhr_rd_poll(sess); }, tout, this, sess);
+                       
+                       // this.hbit(".");
+                       
+                   }
                     else {
-                        // console.log("yyy DI QUI "+xhr_rd_delay);
-                        xhr_rd_start(sess, stat, subst, gst.st);
-                    }
-               }
+                        //x alert("the_end2");
+                        if (this.xhr_rd_watchdog != null) {
+                            clearTimeout(this.xhr_rd_watchdog);
+                            this.xhr_rd_watchdog = null;
+                        }
+                    }    
+                    return;
+                }
+                
                 
-               
-               // $("sandbox").innerHTML += "return 1<br>";
-               if (the_end != true) {
-                   watchdog = 0;
-                   setTimeout(xhr_rd_poll, tout, sess);
+                // 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++;
+                    break;
+                }
+                else {
+                   // $("sandbox").innerHTML += "BIG IF<br>";
+                   var comm_match;
+                   var comm_clean;
+                   var comm_len;
+                   var comm_newpart;
+                   var comm_arr;
+                   var i;
+                   var delta = 0;
+                   var match_lines = /^_*$/;
+                    
+                   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 = "";
+                   }
+                   else
+                       delta = this.xhr_rd_oldctx.length;
+                    
+                   // $("xhrlog").innerHTML += "EVERY SEC<br>";                
+                   for (i = delta ; i < this.xhr_rd_newctx.length ; i++) {
+                       if (this.xhr_rd_newctx[i] != '_') 
+                           break;
+                   }
+                   if (i == this.xhr_rd_newctx.length) {
+                       this.xhr_rd_checkedlen = i;
+                       break;
+                   }
+                    
+                   // $("xhrlog").innerHTML += "CHECK COM<br>";                
+                   // extracts the new part of the command string
+                   comm_newpart = this.xhr_rd_newctx.substr(delta);
                    
-                   // hbit(".");
+                   // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "&lt;", "g");
+                    
+                   // $("response").innerHTML = comm_newpart;
+                   comm_match = /_*@BEGIN@(.*?)@END@/g;
+                   comm_clean = /_*@BEGIN@(.*?)@END@/;
+                   comm_len = 0;
+                   comm_arr = comm_newpart.match(comm_match);
                    
-               }
-                else {
-                    //x alert("the_end2");
-                    if (typeof xhr_rd_watchdog != 'undefined' && xhr_rd_watchdog != null) {
-                        clearTimeout(xhr_rd_watchdog);
-                        xhr_rd_watchdog = null;
-                    }
-                }    
-                return;
-            }
-                
-            
-            // no new char from the last loop, break
-            if (xhr_rd_old_n == xhr_rd_cur_n && 
-                xhr_rd_newctx.length == xhr_rd_checkedlen) {
-                watchdog++;
-                break;
-            }
-            else {
-               watchdog = 0;
-               // $("sandbox").innerHTML += "BIG IF<br>";
-               var comm_match;
-               var comm_clean;
-               var comm_len;
-               var comm_newpart;
-               var comm_arr;
-               var i;
-               var delta = 0;
-               var match_lines = /^_*$/;
-
-               hbit("/\\");
-
-               // check for the same command group
-               if (xhr_rd_old_n != xhr_rd_cur_n) {
-                   xhr_rd_old_n = xhr_rd_cur_n;
-                   xhr_rd_checkedlen = 0;
-                   xhr_rd_oldctx = "";
-               }
-               else
-                   delta = xhr_rd_oldctx.length;
-
-               // $("xhrlog").innerHTML += "EVERY SEC<br>";            
-               for (i = delta ; i < xhr_rd_newctx.length ; i++) {
-                   if (xhr_rd_newctx[i] != '_') 
-                       break;
-               }
-               if (i == xhr_rd_newctx.length) {
-                   xhr_rd_checkedlen = i;
-                   break;
-               }
-
-               // $("xhrlog").innerHTML += "CHECK COM<br>";            
-               // extracts the new part of the command string
-               comm_newpart = xhr_rd_newctx.substr(delta);
-               
-               // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "&lt;", "g");
-
-               // $("response").innerHTML = comm_newpart;
-               comm_match = /_*@BEGIN@(.*?)@END@/g;
-               comm_clean = /_*@BEGIN@(.*?)@END@/;
-               comm_len = 0;
-               comm_arr = comm_newpart.match(comm_match);
-               
-               // $("sandbox").innerHTML += "PRE COMMARR<br>";
-               if (comm_arr) {
-                   // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
-                   // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
-                   // $("sandbox").innerHTML += "POST COMMARR<br>";
-                   for (i = 0 ; i < comm_arr.length ; i++) {
-                       var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
-                       gst.comms = gst.comms.concat(temp);
-                       // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+"  LEN:"+comm_arr[i].length);
-                       comm_len += comm_arr[i].length;
+                   // $("sandbox").innerHTML += "PRE COMMARR<br>";
+                   if (comm_arr) {
+                       // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
+                       // XX alert("xhr_rd_newctx: "+this.xhr_rd_newctx);
+                       // $("sandbox").innerHTML += "POST COMMARR<br>";
+                       for (i = 0 ; i < comm_arr.length ; i++) {
+                           var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
+                           gst.comms = gst.comms.concat(temp);
+                           // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+"  LEN:"+comm_arr[i].length);
+                           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);
+                       again = 1;
                    }
-                   tout = 0;
-                   xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
-                   // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
-                   again = 1;
-               }
-               xhr_rd_checkedlen = xhr_rd_oldctx.length;
+                   this.xhr_rd_checkedlen = this.xhr_rd_oldctx.length;
+               }
            }
-       }
-    } while (again);
+        } while (again);
 
-    if (xhrrestart == 1 && xhr_rd_stopped == true) {
-       // $("sandbox").innerHTML += "LITTLE IF<br>";
-       // alert("di qui");
-       // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
-
-        if (xhr_rd_delay > 0) {
-            if (xhr_rd_delayed == null) {
-                // console.log("XXX DI QUO "+xhr_rd_delay);
-                xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
-                // console.log("XXX DI QUO post"+xhr_rd_delayed);
+        if (xhrrestart == 1 && this.xhr_rd_stopped == true) {
+           // $("sandbox").innerHTML += "LITTLE IF<br>";
+           // alert("di qui");
+           // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
+            if (this.xhr_rd_delay > 0) {
+                if (this.xhr_rd_delayed == null) {
+                    // console.log("XXX DI QUO "+this.xhr_rd_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);
+                }
             }
-        }
-        else {
-            // console.log("yyy DI QUO "+xhr_rd_delay);
-            xhr_rd_start(sess, stat, subst, gst.st);
+            else {
+                // console.log("yyy DI QUO "+this.xhr_rd_delay);
+                this.xhr_rd_start(sess, stat, subst, gst.st);
+            }
+            
         }
         
-    }
-    
-    if (the_end != true) {
-       setTimeout(xhr_rd_poll, tout, sess);
-    }
-    else {
-        //x alert("the_end3");
-        if (typeof(xhr_rd_watchdog) != 'undefined') {
-            if (xhr_rd_watchdog != null) {
-                clearTimeout(xhr_rd_watchdog);
-                xhr_rd_watchdog = null;
+        if (this.the_end != true) {
+           setTimeout(function(obj, sess){ obj.xhr_rd_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;
             }
         }
+        return;
     }
-    return;
-};
-
+}
+    
 /*
   window.onload = function () {
   xhr_rd = createXMLHttpRequest();