cb914e051cce4ae826a95a5081418d54e4b2c9d0
[xynt.git] / web / xynt / xynt-http-streaming.js
1 function http_streaming(doc, cons)
2 {
3     this.console = cons;
4     this.doc = doc;
5     this.keepalive_old = -1;
6     this.keepalive_new = -1;
7     this.keepalives_equal = 0;
8     this.ifra = doc.createElement("iframe");
9     this.ifra.style.visibility = "hidden";
10     doc.body.appendChild(this.ifra);
11     // this.ifra.contentWindow.onload = function () {
12     //     this.ifra.contentWindow.location.href = 'winstream_rdxxx.php';     
13     // }
14     
15 }
16
17 http_streaming.prototype = {
18     console:           null,
19     doc:               null,
20     ifra:              null,
21     keepalive_old:    -1,
22     keepalive_new:    -1,
23     keepalives_equal:  0,
24     keepalives_eq_max: 6,
25     watchdog_timeout: 2000,
26
27     start: function(page) {
28         this.log("http_streaming:start");
29         this.ifra.contentWindow.location.href = page;
30         setTimeout(function(obj) { obj.watchdog(); }, this.watchdog_timeout, this);
31     },
32
33     watchdog: function () {
34         /* +this.keepalives_equal */
35         this.log("hs::watchdog: start");
36         if (this.keepalive_old == this.keepalive_new) {
37             this.keepalives_equal++;
38         }
39         else {
40             this.keepalives_equal = 0;
41         }
42         
43         if (this.keepalives_equal > this.keepalives_eq_max) {
44             this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
45         }
46         else {
47             setTimeout(function(obj) { obj.watchdog() }, this.watchdog_timeout, this);
48         }
49     },
50     
51     keepalive: function () {
52         this.keepalive_new++;
53     },
54
55     log: function (s) {
56         if (this.console != null) {
57             return (this.console.log(s));
58         }
59     }
60 }