1 // old targetpage == page and moved into start method
4 // CLASS transport_htmlfile
6 function transport_htmlfile(doc, page)
9 this.transfdoc = new ActiveXObject("htmlfile");
10 this.transfdoc.open();
11 /*this.transfdoc.write("<html><head><script>");
12 this.transfdoc.write("document.domain=\""+(doc.domain)+"\";");
13 this.transfdoc.write("</"+"script></"+"head>"); */
14 this.transfdoc.write("<html><body><iframe id='iframe'></iframe></body></html>");
15 this.transfdoc.close();
17 this.ifra = this.transfdoc.getElementById("iframe");
18 this.ifra.contentWindow.location.href = page;
21 transport_htmlfile.prototype = {
26 destroy: function () { /* public */
27 if (this.ifra != null) {
28 // this.doc.body.removeChild(this.ifra);
34 delete this.transfdoc;
35 this.transfdoc = null;
39 xstr_is_init: function () { /* public */
40 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
43 /* only after a successfull is_initialized call */
44 xstr_is_ready: function () { /* public */
45 return (this.ifra.contentWindow.xynt_streaming == "ready");
48 /* only after a successfull is_ready call to be sure the accessibility of the var */
49 xstr_set: function (xynt_streaming) { /* public */
50 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
53 ctx_new_is_set: function () { /* public */
54 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
57 ctx_new_curlen_get: function () { /* public */
58 return (this.ifra.contentWindow.ctx_new.length);
61 ctx_new_getchar: function(idx) { /* public */
64 ctx_old_len_is_set: function () { /* public */
65 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
68 ctx_old_len_get: function () { /* public */
69 return (this.ifra.contentWindow.ctx_old_len);
72 ctx_old_len_set: function (len) { /* public */
73 this.ifra.contentWindow.ctx_old_len = len;
76 ctx_old_len_add: function (len) { /* public */
77 this.ifra.contentWindow.ctx_old_len += len;
80 new_part: function () { /* public */
81 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
84 scrcls_set: function (step) { /* public */
85 this.ifra.contentWindow.script_clean = step;
92 // CLASS transport_iframe
94 function transport_iframe(doc, page)
97 this.ifra = doc.createElement("iframe");
98 this.ifra.style.visibility = "hidden";
99 doc.body.appendChild(this.ifra);
100 this.ifra.contentWindow.location.href = page;
103 transport_iframe.prototype = {
107 destroy: function () { /* public */
108 if (this.ifra != null) {
109 this.doc.body.removeChild(this.ifra);
115 xstr_is_init: function () { /* public */
116 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
119 /* only after a successfull is_initialized call */
120 xstr_is_ready: function () { /* public */
121 return (this.ifra.contentWindow.xynt_streaming == "ready");
124 /* only after a successfull is_ready call to be sure the accessibility of the var */
125 xstr_set: function (xynt_streaming) { /* public */
126 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
129 ctx_new_is_set: function () { /* public */
130 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
133 ctx_new_curlen_get: function () { /* public */
134 return (this.ifra.contentWindow.ctx_new.length);
137 ctx_new_getchar: function(idx) { /* public */
140 ctx_old_len_is_set: function () { /* public */
141 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
144 ctx_old_len_get: function () { /* public */
145 return (this.ifra.contentWindow.ctx_old_len);
148 ctx_old_len_set: function (len) { /* public */
149 this.ifra.contentWindow.ctx_old_len = len;
152 ctx_old_len_add: function (len) { /* public */
153 this.ifra.contentWindow.ctx_old_len += len;
156 new_part: function () { /* public */
157 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
160 scrcls_set: function (step) { /* public */
161 this.ifra.contentWindow.script_clean = step;
165 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
168 this.transp_type = transp_type;
169 this.console = console;
172 this.cookiename = cookiename;
174 this.sandbox = sandbox;
176 this.cmdproc = cmdproc;
177 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
179 this.doc = win.document;
180 this.keepalive_old = -1;
181 this.keepalive_new = -1;
184 xynt_streaming.prototype = {
198 cookiepath: "/brisk/",
204 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
205 // FIXME watchdog_timeout: 200,
206 /* restart after 3 * 40 * 100 millisec if server ping is missing => 12secs */
207 keepalives_eq_max: 3,
208 watchdog_checktm: 40,
209 watchdog_timeout: 100,
213 comm_match: /_*@BEGIN@(.*?)@END@/g,
214 comm_clean: /_*@BEGIN@(.*?)@END@/,
218 start: function() { /* public */
222 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
224 this.log("xynt_streaming:start restart: "+this.restart_n);
225 this.keepalives_equal = 0;
228 this.page = url_complete(this.win.location.href, this.page);
229 // stat, subst, this.gst.st
231 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
234 // transport instantiation
235 if (this.transp_type == "iframe") {
236 this.transp = new transport_iframe(this.doc, this.page);
238 else if (this.transp_type == "htmlfile") {
239 this.transp = new transport_htmlfile(this.doc, this.page);
245 this.watchdog_ct = 0;
247 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
256 hbit_set: function (hbit) {
260 watchdog: function () {
261 // alert("watchdog");
263 var comm_newpart, comm_len, comm_arr;
266 if (this.sandbox != null) {
267 // 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;
268 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
269 if (zug != this.sandbox.innerHTML)
270 this.sandbox.innerHTML = zug;
273 // WATCHDOGING THE CONNECTION
274 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
275 if (!this.watchable) {
278 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
279 if (!this.transp.xstr_is_init()) {
280 this.log("hs::watchdog: xstr_is_init = false");
285 this.log("hs::watchdog: exception");
290 on IE7 the the window frame scope is cleaned after the href is set, so we wait
291 for a well know variable value before assign this object value to it (OO is a passion)
293 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
294 if (this.transp.xstr_is_ready()) {
295 // this.ifra.contentWindow.xynt_streaming = this;
296 this.transp.xstr_set(this);
297 this.watchable = true;
298 this.watchdog_ct = 0;
299 this.log("hs::watchdog: watchable = yes");
303 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
304 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
305 if (this.keepalive_old == this.keepalive_new) {
306 this.keepalives_equal++;
309 this.keepalive_old = this.keepalive_new;
310 this.keepalives_equal = 0;
313 if (this.keepalives_equal > this.keepalives_eq_max) {
314 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
316 // alert("watchdog return reload");
321 // PICK COMMANDS FROM STREAM
323 // alert("do--while begin ["+again+"]");
324 // CHECK: maybe again here isn't needed
327 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
328 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
329 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
336 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
337 ctx_new_len = this.transp.ctx_new_curlen_get();
338 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
339 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
342 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
343 this.keepalive_new++;
344 // alert("pre-loop 1");
345 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
346 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
347 if (this.transp.ctx_new_getchar(i) != '_') {
348 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
352 // this.log("ctx_new.charAt(i) == '_'");
355 // this.ifra.contentWindow.ctx_old_len = i;
356 this.transp.ctx_old_len_set(i);
357 if (i == ctx_new_len) {
358 this.log("old_len == i");
362 this.log("old_len != i: "+i);
364 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
366 comm_newpart = this.transp.new_part();
367 this.log("COM_NEWPART: ["+comm_newpart+"]");
369 comm_arr = comm_newpart.match(this.comm_match);
371 // alert("do--while middle2 ["+again+"]");
373 var comm_arr_len = comm_arr.length;
374 for (i = 0 ; i < comm_arr_len ; i++) {
375 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
376 this.gst.comms = this.gst.comms.concat(temp);
377 comm_len += comm_arr[i].length;
381 // this.ifra.contentWindow.ctx_old_len += comm_len;
382 this.transp.ctx_old_len_add(comm_len);
383 // this.ifra.contentWindow.script_clean = this.gst.st;
384 this.transp.scrcls_set(this.gst.st);
385 // alert("do--while end ["+again+"]");
388 // alert("post while");
389 // EXECUTION OF STREAM COMMANDS
392 //MOP ?? xhrrestart = 0;
393 if (this.gst.st_loc < this.gst.st_loc_new) {
394 // there is some slow actions running
397 else if (this.gst.comms.length > 0) {
400 singlecomm = this.gst.comms.shift();
401 // alert("EXE"+gugu);
402 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
405 // alert("SINGLE: ["+singlecomm+"]");
406 this.cmdproc(singlecomm);
412 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
414 // alert("watchdog return normal");
420 // moved to xynt-streaming-ifra as push()
422 // keepalive: function (s) {
423 // this.log("hs::keepalive");
426 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
429 // this.ifra.contentWindow.ctx_new += "_";
431 // // this.keepalive_new++;
434 abort: function () { /* public */
435 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
438 if (this.watchdog_hdl != null) {
439 clearTimeout(this.watchdog_hdl);
440 this.watchdog_hdl = null;
444 this.log("hs::reload");
445 this.watchable = false;
446 if (this.transp != null) {
447 this.transp.destroy();
453 reload: function () {
459 if (this.console != null) {
460 return (this.console.log(s));