ctx_old attribute removed (we will use ctx_old_len only), url_complete js function... iframe-check
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Wed, 25 Apr 2012 14:39:44 +0000 (16:39 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Wed, 25 Apr 2012 14:39:44 +0000 (16:39 +0200)
TODO.stream_iframe [new file with mode: 0644]
web/test-hs-rd.php
web/test-hs.php
web/xynt/xynt-commons.js
web/xynt/xynt-http-streaming.js

diff --git a/TODO.stream_iframe b/TODO.stream_iframe
new file mode 100644 (file)
index 0000000..e93ec9e
--- /dev/null
@@ -0,0 +1,14 @@
+- resize the ctx_new var
+
+ABRT - stop js into iframe when the page is stopped
+
+DONE - fix "full path problem"
+
+DONE - clean the DOM at each reload
+    
+DONE - iframe + index_rd that: push forever commands AND watchdog system 
+
+DONE - use watchdog to prevent hang of the stream (reload and full reset of objects)
+
+DONE - executed commands
+
index 78baf48..95aa3df 100644 (file)
-<html>
+<?php
+function mop_flush()
+{
+    ob_flush();
+    flush();
+}
+
+    $s = 
+"GGZDGDRBXDWFXHGPYAAVDXEKFDUWSTEDTDVXBXQPMZAIFPNLRPTWMJAZRHXTIRNZ"
+."HTZXAUVJDCLXENDCLIZXSSEQQGUADYEKNNANJWEGRUFHPLUNSEROZQJSLMUYNUVG"
+."FPLQAGCMTTGIRRXZFBFQFTRBYPHTWFSXFKHKYBRDAOSOURCMEVGPVXJVUQAOCFPV"
+."OQSUBOYWOZLDGRPQQIBNOTHFUHTCRRZOBCUONAXIYUYCJBFTVNWIITVHBYLNMPWR"
+."LPMMIROZVRUNYXSJSMJINSXGACXDMJAEPNFFAERHVDJELXSPPJWKMNFGVGAPTIMR"
+."VMVMVCLWKMPOAJWZGPSPFEXVNQANXGLZIQSCBIYVFSTXZOODZYCXUVUZFCLFGHUJ"
+."TXZWFHSMFJQAZOQRANKZJAUJHFJIKHIIEQUSDXUBRPQBKMIAVTWYQEOIMYKKDTEV"
+."EYERPXKFJXWNIMJPOFFM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IXNXETTKL"
+."PYIFTUDCMWRQBZDROXTTVTAOOIQHIWOZESRHKPNGNCSHNAVEWUSGOTZCRNFSIXGF"
+."QJUMUFPEZBFPOVGZZDCGDKEODSWAPNDNHVJUQDYLCXWNXSCDFFFPBTDOIZIZLBBP"
+."ZXZYWTTPEUUCKXGBTXAJBAXYLMUVWWGWZYTXTKYVRXSOXOBHERLZJPRDXIQZRQLU"
+."TXCLIJNKIRWMVQEJTLHZIDTNGBOYSULGWUTSYTKGNMGZFWKXCCZXGOQGZNQFZJUK"
+."JMBQPQPZOPYTQMPEFTZUDLIIBZAZSZAPNILMIKMPKXJIRHRQMFSTJKAPIIQWOFYQ"
+."HGANJGJSUGDIENDVEQFEMUJBGMZBPHLOARCVGMUUCHLCDDNKSJSCKYSALUAGUZFN"
+."YVURVLREBESGXPANIDKGLPJZGXLKFKTPEQBQEINOYYZTBMPFBLBKIKVPAPFDKKRZ"
+."YMVUBYCYTRXCIICUPTXKGQOIJSVSWPYVALIROWGVXDXGNSRVZOLEJHNRSUKHNTRJ"
+."LQZQKBEFXYKIPXJRZMQMJKUGCNUKBZBWABPLHMAJJZVBCWOQYCLSGDUKJSTHTVXV"
+."OUGJVADGJWGVNBNXYRZDSNLOZDIQRKOQAKJJDKXRMMTXRVTLOMTETNROPDYNXAGR";
+?><html>
 <head>
 <script type="text/javascript" src="xynt/xynt-console.js"></script>
 <script type="text/javascript" src="xynt/xynt-http-streaming-ifra.js"></script>
 <script type="text/javascript">
 var http_streaming = "ready";
 
-window.onload = function () { if (http_streaming != "ready") http_streaming.reload(); };
+window.onload = function () { if (http_streaming != "ready") { http_streaming.reload(); } };
 </script> 
 </head>
 <body onabort = "console.log('rd abort');" onunload = "console.log('rd unload');" onerror = "console.log('rd error');" onkeypress = "console.log('rd keypress');">
 </body>
 <?php
-function mop_flush()
-{
-    ob_flush();
-    flush();
-}
-
 function main()
 {
-    GLOBAL $st;
+    GLOBAL $st, $s;
 
-    if (!isset($st)) {
-        $st = 0;
-    }
+    $fp = fopen("/tmp/test-hs-rd.log", "a"); 
+    fwrite($fp, "START [$s] $st\n"); 
+    fclose($fp); 
 
-    $fp = fopen("/tmp/test-hs-rd.log", "a");
-    fwrite($fp, "START\n");
-    fclose($fp);
-
-    $s = "";
-    for ($i = 0 ; $i < 4096 ; $i++) {
-        $s .= rand(65,90);
-    }
+    echo("<!-- ");
+    echo($s);
+    echo(" -->\n");
+    mop_flush();
 
     $to = rand(10,20);
     for ($first = true, $i = $st+1 ; $i < $st+$to ; $i++, $first = false) {
-        // if ($i == 0)
-        //    sleep(1);
-     
-        if ($i == $st+8) {
+        if ($i == 8 /*+$st*/) {
             // exit();
-            sleep(30);
-        }
+            if ($first == true) {
+                sleep(5);
+            }
+            else {
+                // exit();
+                sleep(30);
+            }
+         }
 
-printf("<script id='hs%d' type='text/javascript'>
+        if ($i > 10 && $i < 20) {
+            printf("<script id='hs%d' type='text/javascript'>
+push(null);
+</script>", $i, $i);
+        }
+        else {
+            printf("<script id='hs%d' type='text/javascript'>
 push(\"$('cont').innerHTML += '%s %d'; gst.st = %d;\");
 </script>", $i, ($first ? "<br/>" : ""), $i, $i);
+        }
 
-        if ($first)
-            printf("<!-- %s -->", $s);
         mop_flush();
         usleep(1000000);
     }
index c09c75c..8711ef9 100644 (file)
@@ -23,9 +23,7 @@ window.onload = function () {
     createCookie('sess', sess, 24*365,cookiepath);
     gst = new globst();
     hs = new http_streaming(window, gst, sess, console);
-    // FIXME: with relative path not work!
-    hs.start('http://dodo.birds.lan/xynt/test-hs-rd.php');
-    // hs.start('test-hs-rd.php');
+    hs.start('test-hs-rd.php');
 };
 <?php
     }
index 45b5c85..550cc28 100644 (file)
@@ -169,4 +169,45 @@ function url_append_args(url)
     }
 
     return (ret);
-}
\ No newline at end of file
+}
+
+function url_complete(parent, url)
+{
+    var p, p2, rest;
+    var host = "", path = "";
+
+    // host extraction
+    p = parent.indexOf("://");
+    if (p > -1) {
+        rest = parent.substring(p+3);
+        p2 = rest.indexOf("/");
+        if (p2 > -1) {
+            host = parent.substring(0, p+3+p2);
+            rest = parent.substring(p+3+p2);
+        }
+        else {
+            host = rest;
+            rest = "";
+        }
+    }
+    else {
+        rest = parent;
+    }
+
+    // path extraction
+    p = rest.lastIndexOf("/");
+    if (p > -1) {
+        path = rest.substring(0, p+1);
+    }
+
+    // alert("host: ["+host+"]  path: ["+path+"]");
+    if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/') {
+        return (url);
+    }
+    else if (url.substring(0,1) == '/') {
+        return (host+url);
+    }
+    else {
+        return (host+path+url);
+    }
+}
index 5a0c615..f6b0a0b 100644 (file)
@@ -60,7 +60,6 @@ http_streaming.prototype = {
     cmdproc:           null,
     comm_match:        /_*@BEGIN@(.*?)@END@/g, 
     comm_clean:        /_*@BEGIN@(.*?)@END@/,
-    ctx_old:           "",
     ctx_old_len:       0,
     // ctx_new:           "",
     ctx_new_len:       0,
@@ -73,7 +72,7 @@ http_streaming.prototype = {
         this.ifra.style.visibility = "hidden";
         this.doc.body.appendChild(this.ifra);
         if (page != null)
-            this.page = page;
+            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);
 
@@ -86,10 +85,11 @@ http_streaming.prototype = {
     watchdog: function () {
         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) {
-            this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
             if (!this.watchable) {
                 do {
                     if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
@@ -127,21 +127,30 @@ http_streaming.prototype = {
             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
+            
+            ctx_new_length = this.ifra.contentWindow.ctx_new.length;
+            if (ctx_new_length == this.ctx_old_len) {
                 break;
             }
-            this.log("new: "+ this.ifra.contentWindow.ctx_new.length + "  old: "+this.ctx_old_len);
+            this.log("new: "+ 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] != '_') 
+            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) == '_'");
+                }
            }
-           if (i == this.ifra.contentWindow.ctx_new.length) {
-               this.ctx_old_len = 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);
@@ -154,10 +163,9 @@ http_streaming.prototype = {
                    // 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;
+            this.ctx_old_len += comm_len;
         } while (again);
         
 
@@ -218,7 +226,6 @@ http_streaming.prototype = {
             delete this.ifra;
             this.ifra = null;
         }
-        this.ctx_old = "";
         this.ctx_old_len = 0;
     },