add session management and step passed to the streamer
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Wed, 18 Apr 2012 06:22:09 +0000 (08:22 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Wed, 18 Apr 2012 06:22:09 +0000 (08:22 +0200)
web/test-commons.php [new file with mode: 0644]
web/test-hs-rd.php
web/test-hs.php
web/xynt/xynt-http-streaming-ifra.js
web/xynt/xynt-http-streaming.js

diff --git a/web/test-commons.php b/web/test-commons.php
new file mode 100644 (file)
index 0000000..7cb325a
--- /dev/null
@@ -0,0 +1,73 @@
+<html>
+<head>
+<script type="text/javascript" src="xynt/xynt-commons.js"></script>
+<script type="text/javascript" src="xynt/xynt-console.js"></script>
+     <script type="text/javascript"><!--
+
+function test_item(ins, nms, vls, out)
+{
+    this.in  = ins;
+    this.nm  = nms;
+    this.vl  = vls;
+    this.out = out;
+}
+
+test_item.prototype = {
+in: null,
+nm: null,
+vl: null,
+out: null
+};
+    window.onload = function () 
+    {
+        var i, test_items;
+
+        test_items = new Array( new test_item("http://www.pippo.com", "assoli", "new_value", "http://www.pippo.com?assoli=new_value"),
+                                new test_item("http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3",
+                                        "assoli", "new_value",
+                                              "http://www.example.com/pippo/pluto.php?asso=1&assoli=new_value&assolino=3"),
+                                new test_item("http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3",
+                                              "bossoli", "new_value",
+                                              "http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3&bossoli=new_value"),
+
+                                new test_item("http://www.pippo.com", "assoli", "new_value_&_with_ampersand", "http://www.pippo.com?assoli=new_value_%26_with_ampersand"),
+                                new test_item("http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3",
+                                        "assoli", "new_value_&_with_ampersand",
+                                              "http://www.example.com/pippo/pluto.php?asso=1&assoli=new_value_%26_with_ampersand&assolino=3"),
+                                new test_item("http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3",
+                                              "bossoli", "new_value_&_with_ampersand",
+                                              "http://www.example.com/pippo/pluto.php?asso=1&assoli=2&assolino=3&bossoli=new_value_%26_with_ampersand"),
+                                new test_item("http://dodo.birds.lan/xynt/test-hs-rd.php?sess=51583d21b104d28eac58b59f310499e5", "st", "-1", "http://dodo.birds.lan/xynt/test-hs-rd.php?sess=51583d21b104d28eac58b59f310499e5&st=-1"),
+                                new test_item("http://dodo.birds.lan/xynt/test-hs-rd.php?sess=51583d21b104d28eac58b59f310499e5&st=-1", "st", "15", "http://dodo.birds.lan/xynt/test-hs-rd.php?sess=51583d21b104d28eac58b59f310499e5&st=15")
+                 
+                                );
+
+        for (i = 0 ; i < test_items.length ; i++) {
+            $('cont').innerHTML += i+"<br>";
+            $('cont').innerHTML += "original: "+test_items[i].in+"<br>";
+            $('cont').innerHTML += "name: ["+ test_items[i].nm + "]  value: ["+test_items[i].vl+"]<br>";
+            ret = url_append_arg(test_items[i].in, test_items[i].nm, test_items[i].vl);
+            $('cont').innerHTML += "result: "+ret+"<br>";
+            if (ret != test_items[i].out) {
+                break;
+            }
+            $('cont').innerHTML += "<hr>";
+        }
+
+        if (i < test_items.length) {
+            $('cont').innerHTML += "<b>ERROR AT: "+i+"</b><br>";
+        }
+        else {
+            $('cont').innerHTML += "<b>TEST SUCCESS</b><br>";
+        }
+    }
+       
+//-->
+        </script>
+     </head>
+     <body>
+     <div id="cont"></div>
+     </body>
+     </html>
+     
\ No newline at end of file
index 4f13f24..d9a0867 100644 (file)
@@ -4,7 +4,6 @@
 <script type="text/javascript" src="xynt/xynt-http-streaming-ifra.js"></script>
 <script type="text/javascript">
 var http_streaming = "ready";
-var ctx_new = "";
 
 window.onload = function () { if (http_streaming != "ready") http_streaming.reload(); };
 </script> 
@@ -20,24 +19,28 @@ function mop_flush()
 
 function main()
 {
+    GLOBAL $st;
+
     $s = "";
     for ($i = 0 ; $i < 4096 ; $i++) {
         $s .= rand(65,90);
     }
-    for ($i = 0 ; $i < 15 ; $i++) {
+
+    $to = rand(10,20);
+    for ($first = true, $i = $st+1 ; $i < $st+$to ; $i++, $first = false) {
         // if ($i == 0)
         //    sleep(1);
      
         if ($i != 8 || true) {
             printf("<script id='hs%d' type='text/javascript'>
-push(\"$('cont').innerHTML += '%s %d';\");
-</script>", $i, ($i == 0 ? "<br/>" : ""), $i);
+push(\"$('cont').innerHTML += '%s %d'; gst.st = %d;\");
+</script>", $i, ($first ? "<br/>" : ""), $i, $i);
         }
         else {
             // exit();
             // sleep(30);
         }
-        if ($i == 0)
+        if ($first)
             printf("<!-- %s -->", $s);
         mop_flush();
         usleep(1000000);
index 3ffd263..c09c75c 100644 (file)
@@ -4,14 +4,25 @@
 <script type="text/javascript" src="xynt/xynt-console.js"></script>
 <script type="text/javascript" src="xynt/xynt-http-streaming.js"></script>
 <script type="text/javascript"><!--
-var allmythings="BEGIN";
+var gst = null;
 
 <?php
     if ($action != 'stop') {
 ?>
 window.onload = function () {
     var hs;
-    hs = new http_streaming(window, console);
+    var sess;
+
+    sess = '<?php
+    if (!isset($sess)) {
+        $sess = md5(mt_rand());
+    }
+    printf("%s", $sess);
+?>';
+    
+    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');
@@ -20,8 +31,6 @@ window.onload = function () {
     }
 ?>
 
-
-
 window.onkeypress = function () {
     console.log("win kpress");
 }
index a854c05..7b4124f 100644 (file)
@@ -1,3 +1,5 @@
+var ctx_new = "";
+
 function push(s) {
     if (s != null) {
         ctx_new += "@BEGIN@"+s+"@END@";
index 7efb2f5..477e754 100644 (file)
@@ -27,14 +27,15 @@ globst.prototype = {
     }
 }
 
-function http_streaming(win, cons)
+function http_streaming(win, gst, sess, cons)
 {
     this.console = cons;
     this.win = win;
+    this.sess = sess;
     this.doc = win.document;
     this.keepalive_old = -1;
     this.keepalive_new = -1;
-    this.gst = new globst();
+    this.gst = gst;
     this.cmdproc = function(com){eval(com);}
 }
 
@@ -42,6 +43,7 @@ http_streaming.prototype = {
     console:           null,
     win:               null,
     doc:               null,
+    sess:              null,
     ifra:              null,
     page:              null,
     watchdog_hdl:      null,
@@ -72,7 +74,8 @@ http_streaming.prototype = {
         this.doc.body.appendChild(this.ifra);
         if (page != null)
             this.page = page;
-        // this.log(this.ifra);
+        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);