console argument passed to http_streaming constructor
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Mon, 2 Apr 2012 15:56:59 +0000 (17:56 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Mon, 2 Apr 2012 15:56:59 +0000 (17:56 +0200)
web/test-hs.php
web/xynt/xynt-http-streaming.js

index 5f48ac3..257d895 100644 (file)
@@ -8,8 +8,8 @@ var allmythings="BEGIN";
 
 window.onload = function () {
     var hs;
-    
-    hs = new http_streaming(document);
+    console.log("zugu");
+    hs = new http_streaming(document, console);
     hs.start('test-hs-rd.php');
 }
     
index cd31ead..cb914e0 100644 (file)
@@ -1,5 +1,6 @@
-function http_streaming(doc)
+function http_streaming(doc, cons)
 {
+    this.console = cons;
     this.doc = doc;
     this.keepalive_old = -1;
     this.keepalive_new = -1;
@@ -14,20 +15,24 @@ function http_streaming(doc)
 }
 
 http_streaming.prototype = {
+    console:           null,
     doc:               null,
     ifra:              null,
     keepalive_old:    -1,
     keepalive_new:    -1,
     keepalives_equal:  0,
     keepalives_eq_max: 6,
+    watchdog_timeout: 2000,
 
     start: function(page) {
+        this.log("http_streaming:start");
         this.ifra.contentWindow.location.href = page;
+        setTimeout(function(obj) { obj.watchdog(); }, this.watchdog_timeout, this);
     },
 
     watchdog: function () {
         /* +this.keepalives_equal */
-        console.log("watchdog ");
+        this.log("hs::watchdog: start");
         if (this.keepalive_old == this.keepalive_new) {
             this.keepalives_equal++;
         }
@@ -36,15 +41,20 @@ http_streaming.prototype = {
         }
         
         if (this.keepalives_equal > this.keepalives_eq_max) {
-            console.log("MAX ACHIEVED "+this.keepalives_equal);
+            this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
         }
         else {
-            setTimeout(function(obj) { obj.watchdog() }, 2000, this);
+            setTimeout(function(obj) { obj.watchdog() }, this.watchdog_timeout, this);
         }
     },
     
     keepalive: function () {
         this.keepalive_new++;
+    },
+
+    log: function (s) {
+        if (this.console != null) {
+            return (this.console.log(s));
+        }
     }
-    
 }
\ No newline at end of file