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 watchdog_timeout: 100,
46 comm_match: /_*@BEGIN@(.*?)@END@/g,
47 comm_clean: /_*@BEGIN@(.*?)@END@/,
51 start: function() { /* public */
55 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
57 this.log("http_streaming:start restart: "+this.restart_n);
58 this.keepalives_equal = 0;
59 this.ifra = this.doc.createElement("iframe");
60 this.ifra.style.visibility = "hidden";
61 this.doc.body.appendChild(this.ifra);
62 this.page = url_complete(this.win.location.href, this.page);
63 // stat, subst, this.gst.st
65 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
69 // this.log(this.ifra);
70 this.ifra.contentWindow.location.href = this.page;
73 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, 0, this);
82 hbit_set: function (hbit) {
86 watchdog: function () {
89 var comm_newpart, comm_len, comm_arr;
92 if (this.sandbox != null) {
93 // 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;
94 var zug = "WATCHDOG step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
95 if (zug != this.sandbox.innerHTML)
96 this.sandbox.innerHTML = zug;
99 // WATCHDOGING THE CONNECTION
100 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
101 if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
102 if (!this.watchable) {
104 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
107 on IE7 the the window frame scope is cleaned after the href is set, so we wait
108 for a well know variable value before assign this object value to it (OO is a passion)
110 if (this.ifra.contentWindow.http_streaming == "ready") {
111 this.ifra.contentWindow.http_streaming = this;
112 this.watchable = true;
113 this.log("hs::watchdog: watchable = yes");
117 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
118 if (this.keepalive_old == this.keepalive_new) {
119 this.keepalives_equal++;
122 this.keepalive_old = this.keepalive_new;
123 this.keepalives_equal = 0;
126 if (this.keepalives_equal > this.keepalives_eq_max) {
127 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
129 // alert("watchdog return reload");
134 // PICK COMMANDS FROM STREAM
136 // alert("do--while begin ["+again+"]");
137 // CHECK: maybe again here isn't needed
139 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
140 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
143 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
144 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
147 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
148 this.keepalive_new++;
149 // alert("pre-loop 1");
150 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
151 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
152 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
156 // this.log("ctx_new.charAt(i) == '_'");
159 this.ifra.contentWindow.ctx_old_len = i;
160 if (i == ctx_new_len) {
161 this.log("old_len == i");
165 this.log("old_len != i: "+i);
167 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
169 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
170 this.log("COM_NEWPART: ["+comm_newpart+"]");
172 comm_arr = comm_newpart.match(this.comm_match);
174 // alert("do--while middle2 ["+again+"]");
176 var comm_arr_len = comm_arr.length;
177 for (i = 0 ; i < comm_arr_len ; i++) {
178 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
179 this.gst.comms = this.gst.comms.concat(temp);
180 comm_len += comm_arr[i].length;
184 this.ifra.contentWindow.ctx_old_len += comm_len;
185 this.ifra.contentWindow.script_clean = this.gst.st;
186 // alert("do--while end ["+again+"]");
189 // alert("post while");
190 // EXECUTION OF STREAM COMMANDS
193 //MOP ?? xhrrestart = 0;
194 if (this.gst.st_loc < this.gst.st_loc_new) {
195 // there is some slow actions running
198 else if (this.gst.comms.length > 0) {
201 singlecomm = this.gst.comms.shift();
202 // alert("EXE"+gugu);
203 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
206 // alert("SINGLE: ["+singlecomm+"]");
207 this.cmdproc(singlecomm);
213 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
215 // alert("watchdog return normal");
221 // moved to xynt-http-streaming-ifra as push()
223 // keepalive: function (s) {
224 // this.log("hs::keepalive");
227 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
230 // this.ifra.contentWindow.ctx_new += "_";
232 // // this.keepalive_new++;
235 abort: function () { /* public */
236 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
239 if (this.watchdog_hdl != null) {
240 clearTimeout(this.watchdog_hdl);
241 this.watchdog_hdl = null;
245 this.log("hs::reload");
246 this.watchable = false;
247 if (this.ifra != null) {
248 this.doc.body.removeChild(this.ifra);
254 reload: function () {
260 if (this.console != null) {
261 return (this.console.log(s));