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(); }, this.watchdog_timeout, 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.watchable) {
107 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
115 on IE7 the the window frame scope is cleaned after the href is set, so we wait
116 for a well know variable value before assign this object value to it (OO is a passion)
118 if (this.ifra.contentWindow.http_streaming == "ready") {
119 this.ifra.contentWindow.http_streaming = this;
120 this.watchable = true;
121 this.watchdog_ct = 0;
122 this.log("hs::watchdog: watchable = yes");
126 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
127 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
128 if (this.keepalive_old == this.keepalive_new) {
129 this.keepalives_equal++;
132 this.keepalive_old = this.keepalive_new;
133 this.keepalives_equal = 0;
136 if (this.keepalives_equal > this.keepalives_eq_max) {
137 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
139 // alert("watchdog return reload");
144 // PICK COMMANDS FROM STREAM
146 // alert("do--while begin ["+again+"]");
147 // CHECK: maybe again here isn't needed
150 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
151 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
158 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
159 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
162 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
163 this.keepalive_new++;
164 // alert("pre-loop 1");
165 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
166 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
167 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
171 // this.log("ctx_new.charAt(i) == '_'");
174 this.ifra.contentWindow.ctx_old_len = i;
175 if (i == ctx_new_len) {
176 this.log("old_len == i");
180 this.log("old_len != i: "+i);
182 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
184 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
185 this.log("COM_NEWPART: ["+comm_newpart+"]");
187 comm_arr = comm_newpart.match(this.comm_match);
189 // alert("do--while middle2 ["+again+"]");
191 var comm_arr_len = comm_arr.length;
192 for (i = 0 ; i < comm_arr_len ; i++) {
193 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
194 this.gst.comms = this.gst.comms.concat(temp);
195 comm_len += comm_arr[i].length;
199 this.ifra.contentWindow.ctx_old_len += comm_len;
200 this.ifra.contentWindow.script_clean = this.gst.st;
201 // alert("do--while end ["+again+"]");
204 // alert("post while");
205 // EXECUTION OF STREAM COMMANDS
208 //MOP ?? xhrrestart = 0;
209 if (this.gst.st_loc < this.gst.st_loc_new) {
210 // there is some slow actions running
213 else if (this.gst.comms.length > 0) {
216 singlecomm = this.gst.comms.shift();
217 // alert("EXE"+gugu);
218 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
221 // alert("SINGLE: ["+singlecomm+"]");
222 this.cmdproc(singlecomm);
228 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
230 // alert("watchdog return normal");
236 // moved to xynt-http-streaming-ifra as push()
238 // keepalive: function (s) {
239 // this.log("hs::keepalive");
242 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
245 // this.ifra.contentWindow.ctx_new += "_";
247 // // this.keepalive_new++;
250 abort: function () { /* public */
251 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
254 if (this.watchdog_hdl != null) {
255 clearTimeout(this.watchdog_hdl);
256 this.watchdog_hdl = null;
260 this.log("hs::reload");
261 this.watchable = false;
262 if (this.ifra != null) {
263 this.doc.body.removeChild(this.ifra);
269 reload: function () {
275 if (this.console != null) {
276 return (this.console.log(s));