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 watchdog_timeout: 200,
47 comm_match: /_*@BEGIN@(.*?)@END@/g,
48 comm_clean: /_*@BEGIN@(.*?)@END@/,
52 start: function() { /* public */
56 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
58 this.log("http_streaming:start restart: "+this.restart_n);
59 this.keepalives_equal = 0;
60 this.ifra = this.doc.createElement("iframe");
61 this.ifra.style.visibility = "hidden";
62 this.doc.body.appendChild(this.ifra);
63 this.page = url_complete(this.win.location.href, this.page);
64 // stat, subst, this.gst.st
66 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
70 // this.log(this.ifra);
71 this.ifra.contentWindow.location.href = this.page;
72 // this.ifra.src = this.page;
75 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, 0, this);
84 hbit_set: function (hbit) {
88 watchdog: function () {
91 var comm_newpart, comm_len, comm_arr;
94 if (this.sandbox != null) {
95 // 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;
96 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
97 if (zug != this.sandbox.innerHTML)
98 this.sandbox.innerHTML = zug;
101 // WATCHDOGING THE CONNECTION
102 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
103 if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
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.log("hs::watchdog: watchable = yes");
125 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
126 if (this.keepalive_old == this.keepalive_new) {
127 this.keepalives_equal++;
130 this.keepalive_old = this.keepalive_new;
131 this.keepalives_equal = 0;
134 if (this.keepalives_equal > this.keepalives_eq_max) {
135 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
137 // alert("watchdog return reload");
142 // PICK COMMANDS FROM STREAM
144 // alert("do--while begin ["+again+"]");
145 // CHECK: maybe again here isn't needed
148 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
149 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
156 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
157 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
160 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
161 this.keepalive_new++;
162 // alert("pre-loop 1");
163 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
164 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
165 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
169 // this.log("ctx_new.charAt(i) == '_'");
172 this.ifra.contentWindow.ctx_old_len = i;
173 if (i == ctx_new_len) {
174 this.log("old_len == i");
178 this.log("old_len != i: "+i);
180 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
182 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
183 this.log("COM_NEWPART: ["+comm_newpart+"]");
185 comm_arr = comm_newpart.match(this.comm_match);
187 // alert("do--while middle2 ["+again+"]");
189 var comm_arr_len = comm_arr.length;
190 for (i = 0 ; i < comm_arr_len ; i++) {
191 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
192 this.gst.comms = this.gst.comms.concat(temp);
193 comm_len += comm_arr[i].length;
197 this.ifra.contentWindow.ctx_old_len += comm_len;
198 this.ifra.contentWindow.script_clean = this.gst.st;
199 // alert("do--while end ["+again+"]");
202 // alert("post while");
203 // EXECUTION OF STREAM COMMANDS
206 //MOP ?? xhrrestart = 0;
207 if (this.gst.st_loc < this.gst.st_loc_new) {
208 // there is some slow actions running
211 else if (this.gst.comms.length > 0) {
214 singlecomm = this.gst.comms.shift();
215 // alert("EXE"+gugu);
216 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
219 // alert("SINGLE: ["+singlecomm+"]");
220 this.cmdproc(singlecomm);
226 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
228 // alert("watchdog return normal");
234 // moved to xynt-http-streaming-ifra as push()
236 // keepalive: function (s) {
237 // this.log("hs::keepalive");
240 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
243 // this.ifra.contentWindow.ctx_new += "_";
245 // // this.keepalive_new++;
248 abort: function () { /* public */
249 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
252 if (this.watchdog_hdl != null) {
253 clearTimeout(this.watchdog_hdl);
254 this.watchdog_hdl = null;
258 this.log("hs::reload");
259 this.watchable = false;
260 if (this.ifra != null) {
261 this.doc.body.removeChild(this.ifra);
267 reload: function () {
273 if (this.console != null) {
274 return (this.console.log(s));