first http-streaming with iframe working on ff and ie
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sun, 1 Apr 2012 14:53:03 +0000 (16:53 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sun, 1 Apr 2012 14:53:03 +0000 (16:53 +0200)
web/test-hs-rd.php [new file with mode: 0644]
web/test-hs.php [new file with mode: 0644]
web/xynt/xynt-http-streaming.js [new file with mode: 0644]

diff --git a/web/test-hs-rd.php b/web/test-hs-rd.php
new file mode 100644 (file)
index 0000000..67bc876
--- /dev/null
@@ -0,0 +1,53 @@
+<html>
+<head>
+<script type="text/javascript" src="xynt/xynt-console.js"></script>
+<!-- <script type="text/javascript">
+window.onload_old = function() {
+    // parent.ifra.contentWindow.location.href = 'winstream_rd.php';     
+     window.location.href = 'winstream_rd.php';     
+}
+
+</script> -->
+<?php
+function mop_flush()
+{
+    ob_flush();
+    flush();
+}
+
+function main()
+{
+    $s = "";
+    for ($i = 0 ; $i < 4096 ; $i++) {
+        $s .= rand(0,255);
+    }
+    for ($i = 0 ; $i < 300 ; $i++) {
+        
+        /*                    parent.document.getElementById('cont').innerHTML = \"%d\";
+                             parent.allmythings =  \"%d\"; */
+        if ($i != 350) {
+            printf("<script id=\"hs%d\" type=\"text/javascript\">
+                    parent.allmythings = %d;
+                    console.log(\"zorro \"+parent.allmythings);
+
+                </script>", $i, $i);
+        }
+        else {
+            printf("<script id=\"hs%d\" type=\"text/javascript\">
+                    parent.allmythings = %d;
+                    console.log(\"zorro \"+parent.allmythings);
+                    parent.document.location.assign('winstream2.php');
+                </script>", $i, $i);
+        }
+        if ($i == 0)
+            printf("<!-- %s -->", $s);
+        mop_flush();
+        usleep(1000000);
+    }
+}
+main();
+?>
+</head>
+<body>
+</body>
+</html>
\ No newline at end of file
diff --git a/web/test-hs.php b/web/test-hs.php
new file mode 100644 (file)
index 0000000..5f48ac3
--- /dev/null
@@ -0,0 +1,21 @@
+<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" src="xynt/xynt-http-streaming.js"></script>
+<script type="text/javascript"><!--
+var allmythings="BEGIN";
+
+window.onload = function () {
+    var hs;
+    
+    hs = new http_streaming(document);
+    hs.start('test-hs-rd.php');
+}
+    
+//-->
+</script>
+<body>
+<div id="cont">INIT</div>
+</body>
+</html>
diff --git a/web/xynt/xynt-http-streaming.js b/web/xynt/xynt-http-streaming.js
new file mode 100644 (file)
index 0000000..cd31ead
--- /dev/null
@@ -0,0 +1,50 @@
+function http_streaming(doc)
+{
+    this.doc = doc;
+    this.keepalive_old = -1;
+    this.keepalive_new = -1;
+    this.keepalives_equal = 0;
+    this.ifra = doc.createElement("iframe");
+    this.ifra.style.visibility = "hidden";
+    doc.body.appendChild(this.ifra);
+    // this.ifra.contentWindow.onload = function () {
+    //     this.ifra.contentWindow.location.href = 'winstream_rdxxx.php';     
+    // }
+    
+}
+
+http_streaming.prototype = {
+    doc:               null,
+    ifra:              null,
+    keepalive_old:    -1,
+    keepalive_new:    -1,
+    keepalives_equal:  0,
+    keepalives_eq_max: 6,
+
+    start: function(page) {
+        this.ifra.contentWindow.location.href = page;
+    },
+
+    watchdog: function () {
+        /* +this.keepalives_equal */
+        console.log("watchdog ");
+        if (this.keepalive_old == this.keepalive_new) {
+            this.keepalives_equal++;
+        }
+        else {
+            this.keepalives_equal = 0;
+        }
+        
+        if (this.keepalives_equal > this.keepalives_eq_max) {
+            console.log("MAX ACHIEVED "+this.keepalives_equal);
+        }
+        else {
+            setTimeout(function(obj) { obj.watchdog() }, 2000, this);
+        }
+    },
+    
+    keepalive: function () {
+        this.keepalive_new++;
+    }
+    
+}
\ No newline at end of file