1 // old targetpage == page and moved into start method
3 function http_streaming(win, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
6 this.console = console;
9 this.cookiename = cookiename;
11 this.sandbox = sandbox;
13 this.cmdproc = cmdproc;
14 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
16 this.doc = win.document;
17 this.keepalive_old = -1;
18 this.keepalive_new = -1;
21 http_streaming.prototype = {
34 cookiepath: "/brisk/",
41 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
42 // FIXME watchdog_timeout: 200,
43 watchdog_timeout: 200,
48 comm_match: /_*@BEGIN@(.*?)@END@/g,
49 comm_clean: /_*@BEGIN@(.*?)@END@/,
53 start: function() { /* public */
57 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
59 this.log("http_streaming:start restart: "+this.restart_n);
60 this.keepalives_equal = 0;
61 this.ifra = this.doc.createElement("iframe");
62 this.ifra.style.visibility = "hidden";
63 this.doc.body.appendChild(this.ifra);
64 this.page = url_complete(this.win.location.href, this.page);
65 // stat, subst, this.gst.st
67 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
71 // this.log(this.ifra);
72 this.ifra.contentWindow.location.href = this.page;
73 // this.ifra.src = this.page;
76 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, 0, this);
85 hbit_set: function (hbit) {
89 watchdog: function () {
92 var comm_newpart, comm_len, comm_arr;
95 if (this.sandbox != null) {
96 // from old: var zug = "POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new+" STOP: "+this.stopped;
97 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
98 if (zug != this.sandbox.innerHTML)
99 this.sandbox.innerHTML = zug;
102 // WATCHDOGING THE CONNECTION
103 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
104 if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
105 if (!this.watchable) {
108 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
116 on IE7 the the window frame scope is cleaned after the href is set, so we wait
117 for a well know variable value before assign this object value to it (OO is a passion)
119 if (this.ifra.contentWindow.http_streaming == "ready") {
120 this.ifra.contentWindow.http_streaming = this;
121 this.watchable = true;
122 this.log("hs::watchdog: watchable = yes");
126 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
127 if (this.keepalive_old == this.keepalive_new) {
128 this.keepalives_equal++;
131 this.keepalive_old = this.keepalive_new;
132 this.keepalives_equal = 0;
135 if (this.keepalives_equal > this.keepalives_eq_max) {
136 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
138 // alert("watchdog return reload");
143 // PICK COMMANDS FROM STREAM
145 // alert("do--while begin ["+again+"]");
146 // CHECK: maybe again here isn't needed
149 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
150 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
157 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
158 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
161 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
162 this.keepalive_new++;
163 // alert("pre-loop 1");
164 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
165 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
166 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
170 // this.log("ctx_new.charAt(i) == '_'");
173 this.ifra.contentWindow.ctx_old_len = i;
174 if (i == ctx_new_len) {
175 this.log("old_len == i");
179 this.log("old_len != i: "+i);
181 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
183 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
184 this.log("COM_NEWPART: ["+comm_newpart+"]");
186 comm_arr = comm_newpart.match(this.comm_match);
188 // alert("do--while middle2 ["+again+"]");
190 var comm_arr_len = comm_arr.length;
191 for (i = 0 ; i < comm_arr_len ; i++) {
192 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
193 this.gst.comms = this.gst.comms.concat(temp);
194 comm_len += comm_arr[i].length;
198 this.ifra.contentWindow.ctx_old_len += comm_len;
199 this.ifra.contentWindow.script_clean = this.gst.st;
200 // alert("do--while end ["+again+"]");
203 // alert("post while");
204 // EXECUTION OF STREAM COMMANDS
207 //MOP ?? xhrrestart = 0;
208 if (this.gst.st_loc < this.gst.st_loc_new) {
209 // there is some slow actions running
212 else if (this.gst.comms.length > 0) {
215 singlecomm = this.gst.comms.shift();
216 // alert("EXE"+gugu);
217 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
220 // alert("SINGLE: ["+singlecomm+"]");
221 this.cmdproc(singlecomm);
227 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
229 // alert("watchdog return normal");
235 // moved to xynt-http-streaming-ifra as push()
237 // keepalive: function (s) {
238 // this.log("hs::keepalive");
241 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
244 // this.ifra.contentWindow.ctx_new += "_";
246 // // this.keepalive_new++;
249 abort: function () { /* public */
250 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
253 if (this.watchdog_hdl != null) {
254 clearTimeout(this.watchdog_hdl);
255 this.watchdog_hdl = null;
259 this.log("hs::reload");
260 this.watchable = false;
261 if (this.ifra != null) {
262 this.doc.body.removeChild(this.ifra);
268 reload: function () {
274 if (this.console != null) {
275 return (this.console.log(s));