5 this.comms = new Array;
15 sleep: function(delay) {
18 this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }},
23 if (this.sleep_hdl != null) {
24 clearTimeout(this.sleep_hdl);
25 this.sleep_hdl = null;
30 function http_streaming(win, cons)
34 this.doc = win.document;
35 this.keepalive_old = -1;
36 this.keepalive_new = -1;
37 this.gst = new globst();
38 this.cmdproc = function(com){eval(com);}
41 http_streaming.prototype = {
52 watchdog_timeout: 100,
59 comm_match: /_*@BEGIN@(.*?)@END@/g,
60 comm_clean: /_*@BEGIN@(.*?)@END@/,
67 start: function(page) {
68 this.log("http_streaming:start restart: "+this.restart_n);
69 this.keepalives_equal = 0;
70 this.ifra = this.doc.createElement("iframe");
71 this.ifra.style.visibility = "hidden";
72 this.doc.body.appendChild(this.ifra);
75 // this.log(this.ifra);
76 this.ifra.contentWindow.location.href = this.page;
78 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
81 watchdog: function () {
83 var comm_newpart, comm_len, comm_arr;
85 // WATCHDOGING THE CONNECTION
86 if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
87 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
88 if (!this.watchable) {
90 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
93 on IE7 the the window frame scope is cleaned after the href is set, so we wait
94 for a well know variable value before assign this object value to it (OO is a passion)
96 if (this.ifra.contentWindow.http_streaming == "ready") {
97 this.ifra.contentWindow.http_streaming = this;
98 this.watchable = true;
99 this.log("hs::watchdog: watchable = yes");
103 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
104 if (this.keepalive_old == this.keepalive_new) {
105 this.keepalives_equal++;
108 this.keepalive_old = this.keepalive_new;
109 this.keepalives_equal = 0;
112 if (this.keepalives_equal > this.keepalives_eq_max) {
113 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
119 // PICK COMMANDS FROM STREAM
121 // CHECK: maybe again here isn't needed
123 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined')
125 if (this.ifra.contentWindow.ctx_new.length == this.ctx_old_len) {
126 // this.ctx_new = this.ctx_old = "";
127 // FIXME find a more robust clean method
130 this.log("new: "+ this.ifra.contentWindow.ctx_new.length + " old: "+this.ctx_old_len);
131 this.keepalive_new++;
132 for (i = this.ctx_old_len ; i < this.ifra.contentWindow.ctx_new.length ; i++) {
133 if (this.ifra.contentWindow.ctx_new[i] != '_')
136 if (i == this.ifra.contentWindow.ctx_new.length) {
137 this.ctx_old_len = i;
140 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ctx_old_len);
142 comm_arr = comm_newpart.match(this.comm_match);
145 for (i = 0 ; i < comm_arr.length ; i++) {
146 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
148 this.gst.comms = this.gst.comms.concat(temp);
149 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
150 comm_len += comm_arr[i].length;
152 this.ctx_old += comm_newpart.substr(0,comm_len);
155 this.ctx_old_len = this.ctx_old.length;
160 // EXECUTION OF STREAM COMMANDS
163 //MOP ?? xhrrestart = 0;
164 if (this.gst.st_loc < this.gst.st_loc_new) {
165 // there is some slow actions running
168 else if (this.gst.comms.length > 0) {
171 singlecomm = this.gst.comms.shift();
172 // alert("EXE"+gugu);
173 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
176 this.cmdproc(singlecomm);
183 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
187 keepalive: function (s) {
188 this.log("hs::keepalive");
191 this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
194 this.ifra.contentWindow.ctx_new += "_";
196 // this.keepalive_new++;
201 if (this.watchdog_hdl != null) {
202 clearTimeout(this.watchdog_hdl);
203 this.watchdog_hdl = null;
207 this.log("hs::reload");
208 this.watchable = false;
209 if (this.ifra != null) {
210 this.doc.body.removeChild(this.ifra);
215 this.ctx_old_len = 0;
218 reload: function () {
224 if (this.console != null) {
225 return (this.console.log(s));