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 /* restart after 200 * 20 * 3 millisec if server ping is missing => 12secs */
44 watchdog_timeout: 200,
49 comm_match: /_*@BEGIN@(.*?)@END@/g,
50 comm_clean: /_*@BEGIN@(.*?)@END@/,
54 start: function() { /* public */
58 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
60 this.log("http_streaming:start restart: "+this.restart_n);
61 this.keepalives_equal = 0;
62 this.ifra = this.doc.createElement("iframe");
63 this.ifra.style.visibility = "hidden";
64 this.doc.body.appendChild(this.ifra);
65 this.page = url_complete(this.win.location.href, this.page);
66 // stat, subst, this.gst.st
68 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
72 // this.log(this.ifra);
73 this.ifra.contentWindow.location.href = this.page;
74 // this.ifra.src = this.page;
77 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
86 hbit_set: function (hbit) {
90 watchdog: function () {
93 var comm_newpart, comm_len, comm_arr;
96 if (this.sandbox != null) {
97 // 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;
98 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
99 if (zug != this.sandbox.innerHTML)
100 this.sandbox.innerHTML = zug;
103 // WATCHDOGING THE CONNECTION
104 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
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.watchdog_ct = 0;
123 this.log("hs::watchdog: watchable = yes");
127 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
128 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
129 if (this.keepalive_old == this.keepalive_new) {
130 this.keepalives_equal++;
133 this.keepalive_old = this.keepalive_new;
134 this.keepalives_equal = 0;
137 if (this.keepalives_equal > this.keepalives_eq_max) {
138 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
140 // alert("watchdog return reload");
145 // PICK COMMANDS FROM STREAM
147 // alert("do--while begin ["+again+"]");
148 // CHECK: maybe again here isn't needed
151 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
152 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
159 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
160 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
163 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
164 this.keepalive_new++;
165 // alert("pre-loop 1");
166 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
167 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
168 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
172 // this.log("ctx_new.charAt(i) == '_'");
175 this.ifra.contentWindow.ctx_old_len = i;
176 if (i == ctx_new_len) {
177 this.log("old_len == i");
181 this.log("old_len != i: "+i);
183 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
185 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
186 this.log("COM_NEWPART: ["+comm_newpart+"]");
188 comm_arr = comm_newpart.match(this.comm_match);
190 // alert("do--while middle2 ["+again+"]");
192 var comm_arr_len = comm_arr.length;
193 for (i = 0 ; i < comm_arr_len ; i++) {
194 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
195 this.gst.comms = this.gst.comms.concat(temp);
196 comm_len += comm_arr[i].length;
200 this.ifra.contentWindow.ctx_old_len += comm_len;
201 this.ifra.contentWindow.script_clean = this.gst.st;
202 // alert("do--while end ["+again+"]");
205 // alert("post while");
206 // EXECUTION OF STREAM COMMANDS
209 //MOP ?? xhrrestart = 0;
210 if (this.gst.st_loc < this.gst.st_loc_new) {
211 // there is some slow actions running
214 else if (this.gst.comms.length > 0) {
217 singlecomm = this.gst.comms.shift();
218 // alert("EXE"+gugu);
219 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
222 // alert("SINGLE: ["+singlecomm+"]");
223 this.cmdproc(singlecomm);
229 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
231 // alert("watchdog return normal");
237 // moved to xynt-http-streaming-ifra as push()
239 // keepalive: function (s) {
240 // this.log("hs::keepalive");
243 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
246 // this.ifra.contentWindow.ctx_new += "_";
248 // // this.keepalive_new++;
251 abort: function () { /* public */
252 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
255 if (this.watchdog_hdl != null) {
256 clearTimeout(this.watchdog_hdl);
257 this.watchdog_hdl = null;
261 this.log("hs::reload");
262 this.watchable = false;
263 if (this.ifra != null) {
264 this.doc.body.removeChild(this.ifra);
270 reload: function () {
276 if (this.console != null) {
277 return (this.console.log(s));