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 */
247 if (this.ifra != null) {
248 this.doc.body.removeChild(this.ifra);
254 xstr_is_init: function () { /* public */
255 return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
258 /* only after a successfull is_initialized call */
259 xstr_is_ready: function () { /* public */
260 return (this.ifra.contentWindow.xynt_streaming == "ready");
263 /* only after a successfull is_initialized call */
264 xstr_set: function () { /* public */
265 if (this.ifra.contentWindow.xynt_streaming == "ready") {
266 this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
269 else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
278 /* only after a successfull is_ready call to be sure the accessibility of the var */
279 xstr_set_old: function (xynt_streaming) { /* public */
280 this.ifra.contentWindow.xynt_streaming = xynt_streaming;
283 ctx_new_is_set: function () { /* public */
284 return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
287 ctx_new_curlen_get: function () { /* public */
288 return (this.ifra.contentWindow.ctx_new.length);
291 ctx_new_getchar: function(idx) { /* public */
294 ctx_old_len_is_set: function () { /* public */
295 return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
298 ctx_old_len_get: function () { /* public */
299 return (this.ifra.contentWindow.ctx_old_len);
302 ctx_old_len_set: function (len) { /* public */
303 this.ifra.contentWindow.ctx_old_len = len;
306 ctx_old_len_add: function (len) { /* public */
307 this.ifra.contentWindow.ctx_old_len += len;
310 new_part: function () { /* public */
311 return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
314 scrcls_set: function (step) { /* public */
315 this.ifra.contentWindow.script_clean = step;
318 postproc: function () {
322 function xynt_streaming(win, transp_type, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
325 this.transp_type = transp_type;
326 this.console = console;
329 this.cookiename = cookiename;
331 this.sandbox = sandbox;
333 this.cmdproc = cmdproc;
334 // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
336 this.doc = win.document;
337 this.keepalive_old = -1;
338 this.keepalive_new = -1;
341 xynt_streaming.prototype = {
355 cookiepath: "/brisk/",
361 /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
362 /* restart after 3 * 40 * 100 millisec if server ping is missing => 12secs */
363 keepalives_eq_max: 3,
364 watchdog_checktm: 40,
365 // FIXME watchdog_timeout: 100,
366 watchdog_timeout: 100,
370 comm_match: /_*@BEGIN@(.*?)@END@/g,
371 comm_clean: /_*@BEGIN@(.*?)@END@/,
375 start: function() { /* public */
379 createCookie(this.cookiename, sess, 24*365, this.cookiepath);
381 this.log("xynt_streaming:start restart: "+this.restart_n);
382 this.keepalives_equal = 0;
385 this.page = url_complete(this.win.location.href, this.page);
386 // stat, subst, this.gst.st
388 this.page = url_append_args(this.page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
391 // transport instantiation
392 if (this.transp_type == "xhr") {
393 this.transp = new transport_xhr(this.doc, this, this.page);
395 else if (this.transp_type == "iframe") {
396 this.transp = new transport_iframe(this.doc, this, this.page);
398 else if (this.transp_type == "htmlfile") {
399 this.transp = new transport_htmlfile(this.doc, this, this.page);
405 this.watchdog_ct = 0;
407 this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
416 hbit_set: function (hbit) {
420 watchdog: function () {
421 // alert("watchdog");
423 var comm_newpart, comm_len, comm_arr;
426 if (this.sandbox != null) {
427 // 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;
428 var zug = "WATCHDOG sess = ["+this.sess+"] step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
429 if (zug != this.sandbox.innerHTML)
430 this.sandbox.innerHTML = zug;
433 // WATCHDOGING THE CONNECTION
434 this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
435 if (!this.watchable) {
438 // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
439 if (!this.transp.xstr_is_init()) {
440 this.log("hs::watchdog: xstr_is_init = false");
445 this.log("hs::watchdog: exception");
450 on IE7 the the window frame scope is cleaned after the href is set, so we wait
451 for a well know variable value before assign this object value to it (OO is a passion)
453 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
454 if (this.transp.xstr_set()) {
455 // this.ifra.contentWindow.xynt_streaming = this;
456 this.watchable = true;
457 this.watchdog_ct = 0;
458 this.log("hs::watchdog: watchable = yes");
462 if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
463 this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
464 if (this.keepalive_old == this.keepalive_new) {
465 this.keepalives_equal++;
468 this.keepalive_old = this.keepalive_new;
469 this.keepalives_equal = 0;
472 if (this.keepalives_equal > this.keepalives_eq_max) {
473 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
475 // alert("watchdog return reload");
480 // PICK COMMANDS FROM STREAM
482 // alert("do--while begin ["+again+"]");
483 // CHECK: maybe again here isn't needed
486 /* if (typeof(this.ifra.contentWindow.ctx_new) == 'undefined' ||
487 typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
488 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
495 // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
496 ctx_new_len = this.transp.ctx_new_curlen_get();
497 // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
498 if (ctx_new_len <= this.transp.ctx_old_len_get()) {
501 this.log("new: "+ ctx_new_len + " old: "+this.transp.ctx_old_len_get());
502 this.keepalive_new++;
503 // alert("pre-loop 1");
504 for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
505 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
506 if (this.transp.ctx_new_getchar(i) != '_') {
507 // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
511 // this.log("ctx_new.charAt(i) == '_'");
514 // this.ifra.contentWindow.ctx_old_len = i;
515 this.transp.ctx_old_len_set(i);
516 if (i == ctx_new_len) {
517 this.log("old_len == i");
521 this.log("old_len != i: "+i);
523 // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
525 comm_newpart = this.transp.new_part();
526 this.log("COM_NEWPART: ["+comm_newpart+"]");
528 comm_arr = comm_newpart.match(this.comm_match);
530 // alert("do--while middle2 ["+again+"]");
532 var comm_arr_len = comm_arr.length;
533 for (i = 0 ; i < comm_arr_len ; i++) {
534 var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
535 this.gst.comms = this.gst.comms.concat(temp);
536 comm_len += comm_arr[i].length;
540 // this.ifra.contentWindow.ctx_old_len += comm_len;
541 this.transp.ctx_old_len_add(comm_len);
542 // this.ifra.contentWindow.script_clean = this.gst.st;
543 this.transp.scrcls_set(this.gst.st);
544 // alert("do--while end ["+again+"]");
547 // alert("post while");
548 // EXECUTION OF STREAM COMMANDS
551 //MOP ?? xhrrestart = 0;
552 if (this.gst.st_loc < this.gst.st_loc_new) {
553 // there is some slow actions running
556 else if (this.gst.comms.length > 0) {
559 singlecomm = this.gst.comms.shift();
560 // alert("EXE"+gugu);
561 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
564 // alert("SINGLE: ["+singlecomm+"]");
565 this.cmdproc(singlecomm);
571 this.transp.postproc();
572 this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
574 // alert("watchdog return normal");
580 // moved to xynt-streaming-ifra as push()
582 // keepalive: function (s) {
583 // this.log("hs::keepalive");
586 // this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
589 // this.ifra.contentWindow.ctx_new += "_";
591 // // this.keepalive_new++;
594 abort: function () { /* public */
595 // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
598 if (this.watchdog_hdl != null) {
599 clearTimeout(this.watchdog_hdl);
600 this.watchdog_hdl = null;
604 this.log("hs::reload");
605 this.watchable = false;
606 if (this.transp != null) {
607 this.transp.destroy();
613 reload: function () {
619 if (this.console != null) {
620 return (this.console.log(s));