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;
74 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, 0, this);
83 hbit_set: function (hbit) {
87 watchdog: function () {
90 var comm_newpart, comm_len, comm_arr;
93 if (this.sandbox != null) {
94 // 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;
95 var zug = "WATCHDOG step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
96 if (zug != this.sandbox.innerHTML)
97 this.sandbox.innerHTML = zug;
100 // WATCHDOGING THE CONNECTION
101 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
102 if ( (this.watchdog_ct % this.watchdog_checktm) == 0 || !this.watchable) {
103 if (!this.watchable) {
106 if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined')
114 on IE7 the the window frame scope is cleaned after the href is set, so we wait
115 for a well know variable value before assign this object value to it (OO is a passion)
117 if (this.ifra.contentWindow.http_streaming == "ready") {
118 this.ifra.contentWindow.http_streaming = this;
119 this.watchable = true;
120 this.log("hs::watchdog: watchable = yes");
124 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
125 if (this.keepalive_old == this.keepalive_new) {
126 this.keepalives_equal++;
129 this.keepalive_old = this.keepalive_new;
130 this.keepalives_equal = 0;
133 if (this.keepalives_equal > this.keepalives_eq_max) {
134 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
136 // alert("watchdog return reload");
141 // PICK COMMANDS FROM STREAM
143 // alert("do--while begin ["+again+"]");
144 // CHECK: maybe again here isn't needed
147 if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
148 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined')
155 ctx_new_len = this.ifra.contentWindow.ctx_new.length;
156 if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
159 this.log("new: "+ ctx_new_len + " old: "+this.ifra.contentWindow.ctx_old_len);
160 this.keepalive_new++;
161 // alert("pre-loop 1");
162 for (i = this.ifra.contentWindow.ctx_old_len ; i < ctx_new_len ; i++) {
163 if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
164 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
168 // this.log("ctx_new.charAt(i) == '_'");
171 this.ifra.contentWindow.ctx_old_len = i;
172 if (i == ctx_new_len) {
173 this.log("old_len == i");
177 this.log("old_len != i: "+i);
179 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
181 comm_newpart = this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len);
182 this.log("COM_NEWPART: ["+comm_newpart+"]");
184 comm_arr = comm_newpart.match(this.comm_match);
186 // alert("do--while middle2 ["+again+"]");
188 var comm_arr_len = comm_arr.length;
189 for (i = 0 ; i < comm_arr_len ; i++) {
190 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
191 this.gst.comms = this.gst.comms.concat(temp);
192 comm_len += comm_arr[i].length;
196 this.ifra.contentWindow.ctx_old_len += comm_len;
197 this.ifra.contentWindow.script_clean = this.gst.st;
198 // alert("do--while end ["+again+"]");
201 // alert("post while");
202 // EXECUTION OF STREAM COMMANDS
205 //MOP ?? xhrrestart = 0;
206 if (this.gst.st_loc < this.gst.st_loc_new) {
207 // there is some slow actions running
210 else if (this.gst.comms.length > 0) {
213 singlecomm = this.gst.comms.shift();
214 // alert("EXE"+gugu);
215 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
218 // alert("SINGLE: ["+singlecomm+"]");
219 this.cmdproc(singlecomm);
225 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
227 // alert("watchdog return normal");
233 // moved to xynt-http-streaming-ifra as push()
235 // keepalive: function (s) {
236 // this.log("hs::keepalive");
239 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
242 // this.ifra.contentWindow.ctx_new += "_";
244 // // this.keepalive_new++;
247 abort: function () { /* public */
248 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
251 if (this.watchdog_hdl != null) {
252 clearTimeout(this.watchdog_hdl);
253 this.watchdog_hdl = null;
257 this.log("hs::reload");
258 this.watchable = false;
259 if (this.ifra != null) {
260 this.doc.body.removeChild(this.ifra);
266 reload: function () {
272 if (this.console != null) {
273 return (this.console.log(s));