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) {
105 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
113 on IE7 the the window frame scope is cleaned after the href is set, so we wait
114 for a well know variable value before assign this object value to it (OO is a passion)
116 if (this.ifra.contentWindow.http_streaming == "ready") {
117 this.ifra.contentWindow.http_streaming = this;
118 this.watchable = true;
119 this.log("hs::watchdog: watchable = yes");
123 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
124 if (this.keepalive_old == this.keepalive_new) {
125 this.keepalives_equal++;
128 this.keepalive_old = this.keepalive_new;
129 this.keepalives_equal = 0;
132 if (this.keepalives_equal > this.keepalives_eq_max) {
133 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
135 // alert("watchdog return reload");
140 // PICK COMMANDS FROM STREAM
142 // alert("do--while begin ["+again+"]");
143 // CHECK: maybe again here isn't needed
146 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
147 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
154 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
155 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
158 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
159 this.keepalive_new++;
160 // alert("pre-loop 1");
161 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
162 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
163 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
167 // this.log("ctx_new.charAt(i) == '_'");
170 this.ifra.contentWindow.ctx_old_len = i;
171 if (i == ctx_new_len) {
172 this.log("old_len == i");
176 this.log("old_len != i: "+i);
178 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
180 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
181 this.log("COM_NEWPART: ["+comm_newpart+"]");
183 comm_arr = comm_newpart.match(this.comm_match);
185 // alert("do--while middle2 ["+again+"]");
187 var comm_arr_len = comm_arr.length;
188 for (i = 0 ; i < comm_arr_len ; i++) {
189 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
190 this.gst.comms = this.gst.comms.concat(temp);
191 comm_len += comm_arr[i].length;
195 this.ifra.contentWindow.ctx_old_len += comm_len;
196 this.ifra.contentWindow.script_clean = this.gst.st;
197 // alert("do--while end ["+again+"]");
200 // alert("post while");
201 // EXECUTION OF STREAM COMMANDS
204 //MOP ?? xhrrestart = 0;
205 if (this.gst.st_loc < this.gst.st_loc_new) {
206 // there is some slow actions running
209 else if (this.gst.comms.length > 0) {
212 singlecomm = this.gst.comms.shift();
213 // alert("EXE"+gugu);
214 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
217 // alert("SINGLE: ["+singlecomm+"]");
218 this.cmdproc(singlecomm);
224 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
226 // alert("watchdog return normal");
232 // moved to xynt-http-streaming-ifra as push()
234 // keepalive: function (s) {
235 // this.log("hs::keepalive");
238 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
241 // this.ifra.contentWindow.ctx_new += "_";
243 // // this.keepalive_new++;
246 abort: function () { /* public */
247 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
250 if (this.watchdog_hdl != null) {
251 clearTimeout(this.watchdog_hdl);
252 this.watchdog_hdl = null;
256 this.log("hs::reload");
257 this.watchable = false;
258 if (this.ifra != null) {
259 this.doc.body.removeChild(this.ifra);
265 reload: function () {
271 if (this.console != null) {
272 return (this.console.log(s));