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 */
100 ctx_old_len_is_set: function () { /* public */
104 ctx_old_len_get: function () { /* public */
105 return (this.ctx_old_len);
108 ctx_old_len_set: function (len) { /* public */
109 this.ctx_old_len = len;
112 ctx_old_len_add: function (len) { /* public */
113 this.ctx_old_len += len;
116 new_part: function () { /* public */
117 return (this.ctx_new.substr(this.ctx_old_len));
120 scrcls_set: function (step) { /* public */
121 // this.script_clean = step;
124 postproc: function () {
125 if (this.stopped && !this.xstr_is_ready()) {
126 this.xynt_streaming.reload();
132 // CLASS transport_htmlfile
134 function transport_htmlfile(doc, xynt_streaming, page)
137 this.xynt_streaming = xynt_streaming;
138 this.transfdoc = new ActiveXObject("htmlfile");
139 this.transfdoc.open();
140 /*this.transfdoc.write("<html><head><script>");
141 this.transfdoc.write("document.domain=\""+(doc.domain)+"\";");
142 this.transfdoc.write("</"+"script></"+"head>"); */
143 this.transfdoc.write("<html><body><iframe id='iframe'></iframe></body></html>");
144 this.transfdoc.close();
146 this.ifra = this.transfdoc.getElementById("iframe");
147 this.ifra.contentWindow.location.href = page;
150 transport_htmlfile.prototype = {
152 xynt_streaming: null,
156 destroy: function () { /* public */
157 if (this.ifra != null) {
158 // this.doc.body.removeChild(this.ifra);
163 if (this.transfdoc) {
164 delete this.transfdoc;
165 this.transfdoc = null;
169 xstr_is_init: function () { /* public */
170 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
173 /* only after a successfull is_initialized call */
174 xstr_set: function () { /* public */
175 if (this.ifra.contentWindow.xynt_streaming == "ready") {
176 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
179 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
187 ctx_new_is_set: function () { /* public */
188 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
191 ctx_new_curlen_get: function () { /* public */
192 return (this.ifra.contentWindow.ctx_new.length);
195 ctx_new_getchar: function(idx) { /* public */
198 ctx_old_len_is_set: function () { /* public */
199 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
202 ctx_old_len_get: function () { /* public */
203 return (this.ifra.contentWindow.ctx_old_len);
206 ctx_old_len_set: function (len) { /* public */
207 this.ifra.contentWindow.ctx_old_len = len;
210 ctx_old_len_add: function (len) { /* public */
211 this.ifra.contentWindow.ctx_old_len += len;
214 new_part: function () { /* public */
215 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
218 scrcls_set: function (step) { /* public */
219 this.ifra.contentWindow.script_clean = step;
222 postproc: function () {
229 // CLASS transport_iframe
231 function transport_iframe(doc, xynt_streaming, page)
234 this.xynt_streaming = xynt_streaming;
235 this.ifra = doc.createElement("iframe");
236 this.ifra.style.visibility = "hidden";
237 doc.body.appendChild(this.ifra);
238 this.ifra.contentWindow.location.href = page;
241 transport_iframe.prototype = {
243 xynt_streaming: null,
246 destroy: function () { /* public */
248 if (this.ifra != null) {
249 // FIXME: with opera on win this remove child crash js so is
251 // this.doc.body.removeChild(this.ifra);
260 xstr_is_init: function () { /* public */
261 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
264 /* only after a successfull is_initialized call */
265 xstr_is_ready: function () { /* public */
266 return (this.ifra.contentWindow.xynt_streaming == "ready");
269 /* only after a successfull is_initialized call */
270 xstr_set: function () { /* public */
271 if (this.ifra.contentWindow.xynt_streaming == "ready") {
272 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
275 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
284 /* only after a successfull is_ready call to be sure the accessibility of the var */
285 xstr_set_old: function (xynt_streaming) { /* public */
286 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
289 ctx_new_is_set: function () { /* public */
290 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
293 ctx_new_curlen_get: function () { /* public */
294 return (this.ifra.contentWindow.ctx_new.length);
297 ctx_new_getchar: function(idx) { /* public */
300 ctx_old_len_is_set: function () { /* public */
301 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
304 ctx_old_len_get: function () { /* public */
305 return (this.ifra.contentWindow.ctx_old_len);
308 ctx_old_len_set: function (len) { /* public */
309 this.ifra.contentWindow.ctx_old_len = len;
312 ctx_old_len_add: function (len) { /* public */
313 this.ifra.contentWindow.ctx_old_len += len;
316 new_part: function () { /* public */
317 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
320 scrcls_set: function (step) { /* public */
321 this.ifra.contentWindow.script_clean = step;
324 postproc: function () {
328 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
331 this.transp_type = transp_type;
332 this.console = console;
335 this.cookiename = cookiename;
337 this.sandbox = sandbox;
339 this.cmdproc = cmdproc;
340 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
342 this.doc = win.document;
343 this.keepalive_old = -1;
344 this.keepalive_new = -1;
347 xynt_streaming.prototype = {
361 cookiepath: "/brisk/",
367 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
368 /* restart after 3 * 40 * 100 millisec if server ping is missing => 12secs */
369 keepalives_eq_max: 3,
370 watchdog_checktm: 40,
371 // FIXME watchdog_timeout: 100,
372 watchdog_timeout: 100,
376 comm_match: /_*@BEGIN@(.*?)@END@/g,
377 comm_clean: /_*@BEGIN@(.*?)@END@/,
381 start: function() { /* public */
385 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
387 this.log("xynt_streaming:start restart: "+this.restart_n);
388 this.keepalives_equal = 0;
391 this.page = url_complete(this.win.location.href, this.page);
392 // stat, subst, this.gst.st
394 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
397 // transport instantiation
398 if (this.transp_type == "xhr") {
399 this.page = url_append_args(this.page, "transp", "xhr");
400 this.transp = new transport_xhr(this.doc, this, this.page);
402 else if (this.transp_type == "iframe") {
403 this.page = url_append_args(this.page, "transp", "iframe");
404 this.transp = new transport_iframe(this.doc, this, this.page);
406 else if (this.transp_type == "htmlfile") {
407 this.page = url_append_args(this.page, "transp", "htmlfile");
408 this.transp = new transport_htmlfile(this.doc, this, this.page);
414 this.watchdog_ct = 0;
416 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
425 hbit_set: function (hbit) {
429 watchdog: function () {
430 // alert("watchdog");
432 var comm_newpart, comm_len, comm_arr;
435 if (this.sandbox != null) {
436 // 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;
437 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
438 if (zug != this.sandbox.innerHTML)
439 this.sandbox.innerHTML = zug;
442 // WATCHDOGING THE CONNECTION
443 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
444 if (!this.watchable) {
447 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
448 if (!this.transp.xstr_is_init()) {
449 this.log("hs::watchdog: xstr_is_init = false");
454 this.log("hs::watchdog: exception");
459 on IE7 the the window frame scope is cleaned after the href is set, so we wait
460 for a well know variable value before assign this object value to it (OO is a passion)
462 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
463 if (this.transp.xstr_set()) {
464 // this.ifra.contentWindow.xynt_streaming = this;
465 this.watchable = true;
466 this.watchdog_ct = 0;
467 this.log("hs::watchdog: watchable = yes");
471 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
472 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
473 if (this.keepalive_old == this.keepalive_new) {
474 this.keepalives_equal++;
477 this.keepalive_old = this.keepalive_new;
478 this.keepalives_equal = 0;
481 if (this.keepalives_equal > this.keepalives_eq_max) {
482 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
484 // alert("watchdog return reload");
489 // PICK COMMANDS FROM STREAM
491 // alert("do--while begin ["+again+"]");
492 // CHECK: maybe again here isn't needed
495 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
496 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
497 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
504 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
505 ctx_new_len = this.transp.ctx_new_curlen_get();
506 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
507 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
510 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
511 this.keepalive_new++;
512 // alert("pre-loop 1");
513 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
514 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
515 if (this.transp.ctx_new_getchar(i) != '_') {
516 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
520 // this.log("ctx_new.charAt(i) == '_'");
523 // this.ifra.contentWindow.ctx_old_len = i;
524 this.transp.ctx_old_len_set(i);
525 if (i == ctx_new_len) {
526 this.log("old_len == i");
530 this.log("old_len != i: "+i);
532 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
534 comm_newpart = this.transp.new_part();
535 this.log("COM_NEWPART: ["+comm_newpart+"]");
537 comm_arr = comm_newpart.match(this.comm_match);
539 // alert("do--while middle2 ["+again+"]");
541 var comm_arr_len = comm_arr.length;
542 for (i = 0 ; i < comm_arr_len ; i++) {
543 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
544 this.gst.comms = this.gst.comms.concat(temp);
545 comm_len += comm_arr[i].length;
549 // this.ifra.contentWindow.ctx_old_len += comm_len;
550 this.transp.ctx_old_len_add(comm_len);
551 // this.ifra.contentWindow.script_clean = this.gst.st;
552 this.transp.scrcls_set(this.gst.st);
553 // alert("do--while end ["+again+"]");
556 // alert("post while");
557 // EXECUTION OF STREAM COMMANDS
560 //MOP ?? xhrrestart = 0;
561 if (this.gst.st_loc < this.gst.st_loc_new) {
562 // there is some slow actions running
565 else if (this.gst.comms.length > 0) {
568 singlecomm = this.gst.comms.shift();
569 // alert("EXE"+gugu);
570 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
573 // alert("SINGLE: ["+singlecomm+"]");
574 this.cmdproc(singlecomm);
580 this.transp.postproc();
581 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
583 // alert("watchdog return normal");
589 // moved to xynt-streaming-ifra as push()
591 // keepalive: function (s) {
592 // this.log("hs::keepalive");
595 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
598 // this.ifra.contentWindow.ctx_new += "_";
600 // // this.keepalive_new++;
603 abort: function () { /* public */
604 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
607 if (this.watchdog_hdl != null) {
608 clearTimeout(this.watchdog_hdl);
609 this.watchdog_hdl = null;
613 this.log("hs::reload");
614 this.watchable = false;
615 if (this.transp != null) {
616 this.transp.destroy();
622 reload: function () {
628 if (this.console != null) {
629 return (this.console.log(s));