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: on Opera on Windows this remove child crash js so is commented
251 // on IE on Windows without it stream abort fails
252 // so we need to decide how can run it
253 this.doc.body.removeChild(this.ifra);
258 alert("destroy exception catched");
262 xstr_is_init: function () { /* public */
263 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
266 /* only after a successfull is_initialized call */
267 xstr_is_ready: function () { /* public */
268 return (this.ifra.contentWindow.xynt_streaming == "ready");
271 /* only after a successfull is_initialized call */
272 xstr_set: function () { /* public */
273 if (this.ifra.contentWindow.xynt_streaming == "ready") {
274 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
277 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
286 /* only after a successfull is_ready call to be sure the accessibility of the var */
287 xstr_set_old: function (xynt_streaming) { /* public */
288 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
291 ctx_new_is_set: function () { /* public */
292 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
295 ctx_new_curlen_get: function () { /* public */
296 return (this.ifra.contentWindow.ctx_new.length);
299 ctx_new_getchar: function(idx) { /* public */
302 ctx_old_len_is_set: function () { /* public */
303 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
306 ctx_old_len_get: function () { /* public */
307 return (this.ifra.contentWindow.ctx_old_len);
310 ctx_old_len_set: function (len) { /* public */
311 this.ifra.contentWindow.ctx_old_len = len;
314 ctx_old_len_add: function (len) { /* public */
315 this.ifra.contentWindow.ctx_old_len += len;
318 new_part: function () { /* public */
319 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
322 scrcls_set: function (step) { /* public */
323 this.ifra.contentWindow.script_clean = step;
326 postproc: function () {
330 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
333 this.transp_type = transp_type;
334 this.console = console;
337 this.cookiename = cookiename;
339 this.sandbox = sandbox;
341 this.cmdproc = cmdproc;
342 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
344 this.doc = win.document;
345 this.keepalive_old = -1;
346 this.keepalive_new = -1;
349 xynt_streaming.prototype = {
363 cookiepath: "/brisk/",
369 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
370 /* restart after 4 * 40 * 100 millisec if server ping is missing => 16secs */
371 keepalives_eq_max: 4,
372 watchdog_checktm: 40,
373 // FIXME watchdog_timeout: 100,
374 watchdog_timeout: 100,
378 comm_match: /_*@BEGIN@(.*?)@END@/g,
379 comm_clean: /_*@BEGIN@(.*?)@END@/,
383 start: function() { /* public */
387 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
389 this.log("xynt_streaming:start restart: "+this.restart_n);
390 this.keepalives_equal = 0;
393 this.page = url_complete(this.win.location.href, this.page);
394 // stat, subst, this.gst.st
396 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
399 // transport instantiation
400 if (this.transp_type == "xhr") {
401 this.page = url_append_args(this.page, "transp", "xhr");
402 this.transp = new transport_xhr(this.doc, this, this.page);
404 else if (this.transp_type == "iframe") {
405 this.page = url_append_args(this.page, "transp", "iframe");
406 this.transp = new transport_iframe(this.doc, this, this.page);
408 else if (this.transp_type == "htmlfile") {
409 this.page = url_append_args(this.page, "transp", "htmlfile");
410 this.transp = new transport_htmlfile(this.doc, this, this.page);
416 this.watchdog_ct = 0;
418 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
427 hbit_set: function (hbit) {
431 watchdog: function () {
432 // alert("watchdog");
434 var comm_newpart, comm_len, comm_arr;
437 if (this.sandbox != null) {
438 // 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;
439 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
440 if (zug != this.sandbox.innerHTML)
441 this.sandbox.innerHTML = zug;
444 // WATCHDOGING THE CONNECTION
445 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
446 if (!this.watchable) {
449 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
450 if (!this.transp.xstr_is_init()) {
451 this.log("hs::watchdog: xstr_is_init = false");
456 this.log("hs::watchdog: exception");
461 on IE7 the the window frame scope is cleaned after the href is set, so we wait
462 for a well know variable value before assign this object value to it (OO is a passion)
464 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
465 if (this.transp.xstr_set()) {
466 // this.ifra.contentWindow.xynt_streaming = this;
467 this.watchable = true;
468 this.watchdog_ct = 0;
469 this.log("hs::watchdog: watchable = yes");
473 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
474 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
475 if (this.keepalive_old == this.keepalive_new) {
476 this.keepalives_equal++;
479 this.keepalive_old = this.keepalive_new;
480 this.keepalives_equal = 0;
483 if (this.keepalives_equal >= this.keepalives_eq_max) {
484 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
486 // alert("watchdog return reload");
491 // PICK COMMANDS FROM STREAM
493 // alert("do--while begin ["+again+"]");
494 // CHECK: maybe again here isn't needed
497 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
498 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
499 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
506 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
507 ctx_new_len = this.transp.ctx_new_curlen_get();
508 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
509 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
512 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
513 this.keepalive_new++;
514 // alert("pre-loop 1");
515 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
516 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
517 if (this.transp.ctx_new_getchar(i) != '_') {
518 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
522 // this.log("ctx_new.charAt(i) == '_'");
525 // this.ifra.contentWindow.ctx_old_len = i;
526 this.transp.ctx_old_len_set(i);
527 if (i == ctx_new_len) {
528 this.log("old_len == i");
532 this.log("old_len != i: "+i);
534 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
536 comm_newpart = this.transp.new_part();
537 this.log("COM_NEWPART: ["+comm_newpart+"]");
539 comm_arr = comm_newpart.match(this.comm_match);
541 // alert("do--while middle2 ["+again+"]");
543 var comm_arr_len = comm_arr.length;
544 for (i = 0 ; i < comm_arr_len ; i++) {
545 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
546 this.gst.comms = this.gst.comms.concat(temp);
547 comm_len += comm_arr[i].length;
551 // this.ifra.contentWindow.ctx_old_len += comm_len;
552 this.transp.ctx_old_len_add(comm_len);
553 // this.ifra.contentWindow.script_clean = this.gst.st;
554 this.transp.scrcls_set(this.gst.st);
555 // alert("do--while end ["+again+"]");
558 // alert("post while");
559 // EXECUTION OF STREAM COMMANDS
562 //MOP ?? xhrrestart = 0;
563 if (this.gst.st_loc < this.gst.st_loc_new) {
564 // there is some slow actions running
567 else if (this.gst.comms.length > 0) {
570 singlecomm = this.gst.comms.shift();
571 // alert("EXE"+gugu);
572 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
575 // alert("SINGLE: ["+singlecomm+"]");
576 this.cmdproc(singlecomm);
582 this.transp.postproc();
583 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
585 // alert("watchdog return normal");
591 // moved to xynt-streaming-ifra as push()
593 // keepalive: function (s) {
594 // this.log("hs::keepalive");
597 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
600 // this.ifra.contentWindow.ctx_new += "_";
602 // // this.keepalive_new++;
605 abort: function () { /* public */
606 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
609 if (this.watchdog_hdl != null) {
610 clearTimeout(this.watchdog_hdl);
611 this.watchdog_hdl = null;
615 this.log("hs::reload");
616 this.watchable = false;
617 if (this.transp != null) {
618 this.transp.destroy();
624 reload: function () {
630 if (this.console != null) {
631 return (this.console.log(s));