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;
149 this.stopped = false;
152 transport_htmlfile.prototype = {
154 xynt_streaming: null,
159 destroy: function () { /* public */
160 if (this.ifra != null) {
161 // this.doc.body.removeChild(this.ifra);
166 if (this.transfdoc) {
167 delete this.transfdoc;
168 this.transfdoc = null;
172 xstr_is_init: function () { /* public */
173 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
176 /* only after a successfull is_initialized call */
177 xstr_set: function () { /* public */
178 if (this.ifra.contentWindow.xynt_streaming == "ready") {
179 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
182 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
190 ctx_new_is_set: function () { /* public */
191 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
194 ctx_new_curlen_get: function () { /* public */
195 return (this.ifra.contentWindow.ctx_new.length);
198 ctx_new_getchar: function(idx) { /* public */
201 ctx_old_len_is_set: function () { /* public */
202 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
205 ctx_old_len_get: function () { /* public */
206 return (this.ifra.contentWindow.ctx_old_len);
209 ctx_old_len_set: function (len) { /* public */
210 this.ifra.contentWindow.ctx_old_len = len;
213 ctx_old_len_add: function (len) { /* public */
214 this.ifra.contentWindow.ctx_old_len += len;
217 new_part: function () { /* public */
218 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
221 scrcls_set: function (step) { /* public */
222 this.ifra.contentWindow.script_clean = step;
225 postproc: function () { /* public */
226 if (this.stopped && !this.xstr_is_ready()) {
227 this.xynt_streaming.reload();
235 // CLASS transport_iframe
237 function transport_iframe(doc, xynt_streaming, page)
240 this.xynt_streaming = xynt_streaming;
241 this.ifra = doc.createElement("iframe");
242 this.ifra.style.visibility = "hidden";
243 doc.body.appendChild(this.ifra);
244 this.ifra.contentWindow.location.href = page;
245 this.stopped = false;
248 transport_iframe.prototype = {
250 xynt_streaming: null,
254 destroy: function () { /* public */
256 if (this.ifra != null) {
257 // NOTE: on Opera this remove child crash js if called from
258 // inside of the iframe, on IE on Windows without
259 // it stream abort fails.
260 // the problem is fixed setting into the iframe's onload
261 // function the stopped attribute to true and delegate
262 // postproc() fired by xynt_streaming watchdog()
263 this.doc.body.removeChild(this.ifra);
268 alert("destroy exception catched");
272 xstr_is_init: function () { /* public */
273 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
276 /* only after a successfull is_initialized call */
277 xstr_is_ready: function () { /* public */
278 return (this.ifra.contentWindow.xynt_streaming == "ready");
281 /* only after a successfull is_initialized call */
282 xstr_set: function () { /* public */
283 if (this.ifra.contentWindow.xynt_streaming == "ready") {
284 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
287 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
296 /* only after a successfull is_ready call to be sure the accessibility of the var */
297 xstr_set_old: function (xynt_streaming) { /* public */
298 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
301 ctx_new_is_set: function () { /* public */
302 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
305 ctx_new_curlen_get: function () { /* public */
306 return (this.ifra.contentWindow.ctx_new.length);
309 ctx_new_getchar: function(idx) { /* public */
312 ctx_old_len_is_set: function () { /* public */
313 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
316 ctx_old_len_get: function () { /* public */
317 return (this.ifra.contentWindow.ctx_old_len);
320 ctx_old_len_set: function (len) { /* public */
321 this.ifra.contentWindow.ctx_old_len = len;
324 ctx_old_len_add: function (len) { /* public */
325 this.ifra.contentWindow.ctx_old_len += len;
328 new_part: function () { /* public */
329 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
332 scrcls_set: function (step) { /* public */
333 this.ifra.contentWindow.script_clean = step;
336 postproc: function () { /* public */
337 if (this.stopped && !this.xstr_is_ready()) {
338 this.xynt_streaming.reload();
343 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
346 this.transp_type = transp_type;
347 this.console = console;
350 this.cookiename = cookiename;
352 this.sandbox = sandbox;
354 this.cmdproc = cmdproc;
355 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
357 this.doc = win.document;
358 this.keepalive_old = -1;
359 this.keepalive_new = -1;
362 xynt_streaming.prototype = {
376 cookiepath: "/brisk/",
382 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
383 /* restart after 4 * 40 * 100 millisec if server ping is missing => 16secs */
384 keepalives_eq_max: 4,
385 watchdog_checktm: 40,
386 // FIXME watchdog_timeout: 100,
387 watchdog_timeout: 100,
391 comm_match: /_*@BEGIN@(.*?)@END@/g,
392 comm_clean: /_*@BEGIN@(.*?)@END@/,
396 start: function() { /* public */
400 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
402 this.log("xynt_streaming:start restart: "+this.restart_n);
403 this.keepalives_equal = 0;
406 this.page = url_complete(this.win.location.href, this.page);
407 // stat, subst, this.gst.st
409 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
412 // transport instantiation
413 if (this.transp_type == "xhr") {
414 this.page = url_append_args(this.page, "transp", "xhr");
415 this.transp = new transport_xhr(this.doc, this, this.page);
417 else if (this.transp_type == "iframe") {
418 this.page = url_append_args(this.page, "transp", "iframe");
419 this.transp = new transport_iframe(this.doc, this, this.page);
421 else if (this.transp_type == "htmlfile") {
422 this.page = url_append_args(this.page, "transp", "htmlfile");
423 this.transp = new transport_htmlfile(this.doc, this, this.page);
429 this.watchdog_ct = 0;
431 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
440 hbit_set: function (hbit) {
444 watchdog: function () {
445 // alert("watchdog");
447 var comm_newpart, comm_len, comm_arr;
450 if (this.sandbox != null) {
451 // 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;
452 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
453 if (zug != this.sandbox.innerHTML)
454 this.sandbox.innerHTML = zug;
457 // WATCHDOGING THE CONNECTION
458 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
459 if (!this.watchable) {
462 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
463 if (!this.transp.xstr_is_init()) {
464 this.log("hs::watchdog: xstr_is_init = false");
469 this.log("hs::watchdog: exception");
474 on IE7 the the window frame scope is cleaned after the href is set, so we wait
475 for a well know variable value before assign this object value to it (OO is a passion)
477 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
478 if (this.transp.xstr_set()) {
479 // this.ifra.contentWindow.xynt_streaming = this;
480 this.watchable = true;
481 this.watchdog_ct = 0;
482 this.log("hs::watchdog: watchable = yes");
486 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
487 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
488 if (this.keepalive_old == this.keepalive_new) {
489 this.keepalives_equal++;
492 this.keepalive_old = this.keepalive_new;
493 this.keepalives_equal = 0;
496 if (this.keepalives_equal >= this.keepalives_eq_max) {
497 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
499 // alert("watchdog return reload");
504 // PICK COMMANDS FROM STREAM
506 // alert("do--while begin ["+again+"]");
507 // CHECK: maybe again here isn't needed
510 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
511 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
512 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
519 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
520 ctx_new_len = this.transp.ctx_new_curlen_get();
521 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
522 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
525 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
526 this.keepalive_new++;
527 // alert("pre-loop 1");
528 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
529 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
530 if (this.transp.ctx_new_getchar(i) != '_') {
531 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
535 // this.log("ctx_new.charAt(i) == '_'");
538 // this.ifra.contentWindow.ctx_old_len = i;
539 this.transp.ctx_old_len_set(i);
540 if (i == ctx_new_len) {
541 this.log("old_len == i");
545 this.log("old_len != i: "+i);
547 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
549 comm_newpart = this.transp.new_part();
550 this.log("COM_NEWPART: ["+comm_newpart+"]");
552 comm_arr = comm_newpart.match(this.comm_match);
554 // alert("do--while middle2 ["+again+"]");
556 var comm_arr_len = comm_arr.length;
557 for (i = 0 ; i < comm_arr_len ; i++) {
558 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
559 this.gst.comms = this.gst.comms.concat(temp);
560 comm_len += comm_arr[i].length;
564 // this.ifra.contentWindow.ctx_old_len += comm_len;
565 this.transp.ctx_old_len_add(comm_len);
566 // this.ifra.contentWindow.script_clean = this.gst.st;
567 this.transp.scrcls_set(this.gst.st);
568 // alert("do--while end ["+again+"]");
571 // alert("post while");
572 // EXECUTION OF STREAM COMMANDS
575 //MOP ?? xhrrestart = 0;
576 if (this.gst.st_loc < this.gst.st_loc_new) {
577 // there is some slow actions running
580 else if (this.gst.comms.length > 0) {
583 singlecomm = this.gst.comms.shift();
584 // alert("EXE"+gugu);
585 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
588 // alert("SINGLE: ["+singlecomm+"]");
589 this.cmdproc(singlecomm);
595 this.transp.postproc();
596 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
598 // alert("watchdog return normal");
604 // moved to xynt-streaming-ifra as push()
606 // keepalive: function (s) {
607 // this.log("hs::keepalive");
610 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
613 // this.ifra.contentWindow.ctx_new += "_";
615 // // this.keepalive_new++;
618 abort: function () { /* public */
619 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
622 if (this.watchdog_hdl != null) {
623 clearTimeout(this.watchdog_hdl);
624 this.watchdog_hdl = null;
628 this.log("hs::reload");
629 this.watchable = false;
630 if (this.transp != null) {
631 this.transp.destroy();
637 reload: function () {
643 if (this.console != null) {
644 return (this.console.log(s));