1 // old targetpage == page and moved into start method
6 function transport_xhr(doc, xynt_streaming, page)
9 this.xynt_streaming = xynt_streaming;
10 this.xhr = createXMLHttpRequest();
11 this.xhr.open('GET', page);
14 this.xhr.onreadystatechange = function () { self.xhr_cb(); };
20 transport_xhr.prototype = {
22 xynt_streaming: "ready",
32 destroy: function () { /* public */
33 if (this.xhr != null) {
42 if (this.xhr.readyState == 4) {
43 // console.log("SS: "+safestatus(xhr));
45 // NOTE: delay management later
47 // if ((ret = safestatus(this.xhr)) == 200) {
49 // // console.log("del a null "+this.delayed);
50 // } else if (ret != -1) {
53 // // alert('There was a problem with the request.' + ret);
57 // this.delayed = null;
62 xhr_abort: function() {
63 if (this.xhr != null) {
68 xstr_is_init: function () { /* public */
70 if (this.xhr.responseText != null) {
71 this.ctx_new = this.xhr.responseText;
77 return (this.ctx_new != null);
80 /* only after a successfull is_initialized call */
81 xstr_is_ready: function () { /* public */
82 return (this.xynt_streaming == "ready");
85 xstr_set: function () { /* public */
89 ctx_new_is_set: function () { /* public */
90 return (this.ctx_new != null);
93 ctx_new_curlen_get: function () { /* public */
94 return (this.ctx_new.length);
97 ctx_new_getchar: function(idx) { /* public */
98 return (this.ctx_new[idx]);
101 ctx_old_len_is_set: function () { /* public */
105 ctx_old_len_get: function () { /* public */
106 return (this.ctx_old_len);
109 ctx_old_len_set: function (len) { /* public */
110 this.ctx_old_len = len;
113 ctx_old_len_add: function (len) { /* public */
114 this.ctx_old_len += len;
117 new_part: function () { /* public */
118 return (this.ctx_new.substr(this.ctx_old_len));
121 scrcls_set: function (step) { /* public */
122 // this.script_clean = step;
125 postproc: function () {
126 if (this.stopped && !this.xstr_is_ready()) {
127 this.xynt_streaming.reload();
133 // CLASS transport_htmlfile
135 function transport_htmlfile(doc, xynt_streaming, page)
138 this.xynt_streaming = xynt_streaming;
139 this.transfdoc = new ActiveXObject("htmlfile");
140 this.transfdoc.open();
141 /*this.transfdoc.write("<html><head><script>");
142 this.transfdoc.write("document.domain=\""+(doc.domain)+"\";");
143 this.transfdoc.write("</"+"script></"+"head>"); */
144 this.transfdoc.write("<html><body><iframe id='iframe'></iframe></body></html>");
145 this.transfdoc.close();
147 this.ifra = this.transfdoc.getElementById("iframe");
148 this.ifra.contentWindow.location.href = page;
151 transport_htmlfile.prototype = {
153 xynt_streaming: null,
157 destroy: function () { /* public */
158 if (this.ifra != null) {
159 // this.doc.body.removeChild(this.ifra);
164 if (this.transfdoc) {
165 delete this.transfdoc;
166 this.transfdoc = null;
170 xstr_is_init: function () { /* public */
171 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
174 /* only after a successfull is_initialized call */
175 xstr_set: function () { /* public */
176 if (this.ifra.contentWindow.xynt_streaming == "ready") {
177 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
180 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
188 ctx_new_is_set: function () { /* public */
189 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
192 ctx_new_curlen_get: function () { /* public */
193 return (this.ifra.contentWindow.ctx_new.length);
196 ctx_new_getchar: function(idx) { /* public */
199 ctx_old_len_is_set: function () { /* public */
200 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
203 ctx_old_len_get: function () { /* public */
204 return (this.ifra.contentWindow.ctx_old_len);
207 ctx_old_len_set: function (len) { /* public */
208 this.ifra.contentWindow.ctx_old_len = len;
211 ctx_old_len_add: function (len) { /* public */
212 this.ifra.contentWindow.ctx_old_len += len;
215 new_part: function () { /* public */
216 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
219 scrcls_set: function (step) { /* public */
220 this.ifra.contentWindow.script_clean = step;
223 postproc: function () {
230 // CLASS transport_iframe
232 function transport_iframe(doc, xynt_streaming, page)
235 this.xynt_streaming = xynt_streaming;
236 this.ifra = doc.createElement("iframe");
237 this.ifra.style.visibility = "hidden";
238 doc.body.appendChild(this.ifra);
239 this.ifra.contentWindow.location.href = page;
242 transport_iframe.prototype = {
244 xynt_streaming: null,
247 destroy: function () { /* public */
249 if (this.ifra != null) {
250 // FIXME: with opera on win this remove child crash js so is
251 // commented AND NOWWW ????
252 this.doc.body.removeChild(this.ifra);
257 alert("destroy exception catched");
261 xstr_is_init: function () { /* public */
262 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
265 /* only after a successfull is_initialized call */
266 xstr_is_ready: function () { /* public */
267 return (this.ifra.contentWindow.xynt_streaming == "ready");
270 /* only after a successfull is_initialized call */
271 xstr_set: function () { /* public */
272 if (this.ifra.contentWindow.xynt_streaming == "ready") {
273 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
276 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
285 /* only after a successfull is_ready call to be sure the accessibility of the var */
286 xstr_set_old: function (xynt_streaming) { /* public */
287 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
290 ctx_new_is_set: function () { /* public */
291 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
294 ctx_new_curlen_get: function () { /* public */
295 return (this.ifra.contentWindow.ctx_new.length);
298 ctx_new_getchar: function(idx) { /* public */
301 ctx_old_len_is_set: function () { /* public */
302 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
305 ctx_old_len_get: function () { /* public */
306 return (this.ifra.contentWindow.ctx_old_len);
309 ctx_old_len_set: function (len) { /* public */
310 this.ifra.contentWindow.ctx_old_len = len;
313 ctx_old_len_add: function (len) { /* public */
314 this.ifra.contentWindow.ctx_old_len += len;
317 new_part: function () { /* public */
318 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
321 scrcls_set: function (step) { /* public */
322 this.ifra.contentWindow.script_clean = step;
325 postproc: function () {
329 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
332 this.transp_type = transp_type;
333 this.console = console;
336 this.cookiename = cookiename;
338 this.sandbox = sandbox;
340 this.cmdproc = cmdproc;
341 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
343 this.doc = win.document;
344 this.keepalive_old = -1;
345 this.keepalive_new = -1;
348 xynt_streaming.prototype = {
362 cookiepath: "/brisk/",
368 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
369 /* restart after 4 * 40 * 100 millisec if server ping is missing => 16secs */
370 keepalives_eq_max: 4,
371 watchdog_checktm: 40,
372 // FIXME watchdog_timeout: 100,
373 watchdog_timeout: 100,
377 comm_match: /_*@BEGIN@(.*?)@END@/g,
378 comm_clean: /_*@BEGIN@(.*?)@END@/,
382 start: function() { /* public */
386 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
388 this.log("xynt_streaming:start restart: "+this.restart_n);
389 this.keepalives_equal = 0;
392 this.page = url_complete(this.win.location.href, this.page);
393 // stat, subst, this.gst.st
395 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
398 // transport instantiation
399 if (this.transp_type == "xhr") {
400 this.page = url_append_args(this.page, "transp", "xhr");
401 this.transp = new transport_xhr(this.doc, this, this.page);
403 else if (this.transp_type == "iframe") {
404 this.page = url_append_args(this.page, "transp", "iframe");
405 this.transp = new transport_iframe(this.doc, this, this.page);
407 else if (this.transp_type == "htmlfile") {
408 this.page = url_append_args(this.page, "transp", "htmlfile");
409 this.transp = new transport_htmlfile(this.doc, this, this.page);
415 this.watchdog_ct = 0;
417 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
426 hbit_set: function (hbit) {
430 watchdog: function () {
431 // alert("watchdog");
433 var comm_newpart, comm_len, comm_arr;
436 if (this.sandbox != null) {
437 // 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;
438 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
439 if (zug != this.sandbox.innerHTML)
440 this.sandbox.innerHTML = zug;
443 // WATCHDOGING THE CONNECTION
444 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
445 if (!this.watchable) {
448 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
449 if (!this.transp.xstr_is_init()) {
450 this.log("hs::watchdog: xstr_is_init = false");
455 this.log("hs::watchdog: exception");
460 on IE7 the the window frame scope is cleaned after the href is set, so we wait
461 for a well know variable value before assign this object value to it (OO is a passion)
463 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
464 if (this.transp.xstr_set()) {
465 // this.ifra.contentWindow.xynt_streaming = this;
466 this.watchable = true;
467 this.watchdog_ct = 0;
468 this.log("hs::watchdog: watchable = yes");
472 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
473 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
474 if (this.keepalive_old == this.keepalive_new) {
475 this.keepalives_equal++;
478 this.keepalive_old = this.keepalive_new;
479 this.keepalives_equal = 0;
482 if (this.keepalives_equal >= this.keepalives_eq_max) {
483 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
485 // alert("watchdog return reload");
490 // PICK COMMANDS FROM STREAM
492 // alert("do--while begin ["+again+"]");
493 // CHECK: maybe again here isn't needed
496 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
497 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
498 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
505 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
506 ctx_new_len = this.transp.ctx_new_curlen_get();
507 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
508 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
511 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
512 this.keepalive_new++;
513 // alert("pre-loop 1");
514 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
515 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
516 if (this.transp.ctx_new_getchar(i) != '_') {
517 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
521 // this.log("ctx_new.charAt(i) == '_'");
524 // this.ifra.contentWindow.ctx_old_len = i;
525 this.transp.ctx_old_len_set(i);
526 if (i == ctx_new_len) {
527 this.log("old_len == i");
531 this.log("old_len != i: "+i);
533 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
535 comm_newpart = this.transp.new_part();
536 this.log("COM_NEWPART: ["+comm_newpart+"]");
538 comm_arr = comm_newpart.match(this.comm_match);
540 // alert("do--while middle2 ["+again+"]");
542 var comm_arr_len = comm_arr.length;
543 for (i = 0 ; i < comm_arr_len ; i++) {
544 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
545 this.gst.comms = this.gst.comms.concat(temp);
546 comm_len += comm_arr[i].length;
550 // this.ifra.contentWindow.ctx_old_len += comm_len;
551 this.transp.ctx_old_len_add(comm_len);
552 // this.ifra.contentWindow.script_clean = this.gst.st;
553 this.transp.scrcls_set(this.gst.st);
554 // alert("do--while end ["+again+"]");
557 // alert("post while");
558 // EXECUTION OF STREAM COMMANDS
561 //MOP ?? xhrrestart = 0;
562 if (this.gst.st_loc < this.gst.st_loc_new) {
563 // there is some slow actions running
566 else if (this.gst.comms.length > 0) {
569 singlecomm = this.gst.comms.shift();
570 // alert("EXE"+gugu);
571 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
574 // alert("SINGLE: ["+singlecomm+"]");
575 this.cmdproc(singlecomm);
581 this.transp.postproc();
582 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
584 // alert("watchdog return normal");
590 // moved to xynt-streaming-ifra as push()
592 // keepalive: function (s) {
593 // this.log("hs::keepalive");
596 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
599 // this.ifra.contentWindow.ctx_new += "_";
601 // // this.keepalive_new++;
604 abort: function () { /* public */
605 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
608 if (this.watchdog_hdl != null) {
609 clearTimeout(this.watchdog_hdl);
610 this.watchdog_hdl = null;
614 this.log("hs::reload");
615 this.watchable = false;
616 if (this.transp != null) {
617 this.transp.destroy();
623 reload: function () {
629 if (this.console != null) {
630 return (this.console.log(s));