72923402614da62b514cc4727056bd6471dfc106
[brisk.git] / web / xynt-streaming.js
1 // old targetpage == page and moved into start method
2
3 //
4 // CLASS transport_ws
5 //
6 function transport_ws(doc, xynt_streaming, page)
7 {
8     this.ctx_new = "";
9     var self = this;
10
11     this.doc = doc;
12     this.failed = false;
13     this.xynt_streaming = xynt_streaming;
14     try {
15 this.xynt_streaming.log("PAGE: "+page);
16         this.ws = new WebSocket(page);
17         this.ws.onopen = function () {
18             self.xynt_streaming.log("onopen");
19             if (this.readyState == 1) {
20                 // connected
21                 self.ws_cb("open");
22                 self.init_steps = 1;
23             }
24         };
25         this.ws.onmessage = function (msg) {
26             self.xynt_streaming.log("onmessage");
27             // new data in msg.data
28             self.ctx_new += msg.data;
29         };
30         this.ws.onclose = function (msg) {
31             this.onopen  = null;
32             this.onclose = null;
33             this.onerror = null;
34             self.xynt_streaming.log("onclose"+self.init_steps);
35             if (self.init_steps == 0)
36                 self.ws_cb("error");
37             else
38                 self.ws_cb("close");
39         };
40         this.ws.onerror = function () {
41             // on error
42             this.onopen  = null;
43             this.onclose = null;
44             this.onerror = null;
45             self.xynt_streaming.log("onerror");
46             self.ws_cb("error");
47         };
48     }
49     catch (ex) {
50         throw "websocket creation failed";
51     }
52
53     this.stopped = false;
54 }
55
56 transport_ws.prototype = {
57     doc: null,
58     xynt_streaming: "ready",
59     ws: null,
60     stopped: true,
61     failed: false,
62
63     init_steps: 0,
64
65     ctx_old: "",
66     ctx_old_len: 0,
67     ctx_new: "",
68
69     // script_clean: 0,
70
71     destroy: function () { /* public */
72         if (this.ws != null) {
73             this.ws_abort();
74         }
75         delete this.ws;
76     },
77
78     ws_cb: function (from) {
79         var ret;
80
81         if (from == "error") {
82             if (this.xynt_streaming != "ready") {
83                 if (this.xynt_streaming.transp_fback > 0) {
84 this.xynt_streaming.log("DEC: "+this.xynt_streaming.transp_fback);
85                     this.xynt_streaming.transp_fback--;
86                     this.stopped = true;
87                     this.xynt_streaming.reload();
88                 }
89             }
90         }
91         if (this.ws != null && this.ws.readyState > 1) {
92             this.stopped = true;
93         }
94     },
95
96     ws_abort: function() {
97         if (this.ws != null) {
98 this.xynt_streaming.log("WSCLOSE");
99             this.ws.close();
100         }
101     },
102
103     xstr_is_init: function () { /* public */
104         return (true);
105     },
106
107     /* only after a successfull is_initialized call */
108     xstr_is_ready: function () { /* public */
109         return (this.ws.readyState == 1);
110     },
111
112     xstr_set: function () { /* public */
113         // already set
114     },
115
116     ctx_new_is_set: function () { /* public */
117         return (this.ctx_new != null);
118     },
119
120     ctx_new_curlen_get: function () { /* public */
121         return (this.ctx_new.length);
122     },
123
124     ctx_new_getchar: function(idx) { /* public */
125         return (this.ctx_new[idx]);
126     },
127
128     ctx_old_len_is_set: function () { /* public */
129         return (true);
130     },
131
132     ctx_old_len_get: function () { /* public */
133         return (this.ctx_old_len);
134     },
135
136     ctx_old_len_set: function (len) { /* public */
137         this.ctx_old_len = len;
138     },
139
140     ctx_old_len_add: function (len) { /* public */
141         this.ctx_old_len += len;
142     },
143
144     new_part: function () { /* public */
145         return (this.ctx_new.substr(this.ctx_old_len));
146     },
147
148     scrcls_set: function (step) { /* public */
149         // this.script_clean = step;
150     },
151
152     postproc: function () {
153         if (this.stopped && !this.xstr_is_ready()) {
154             this.xynt_streaming.reload();
155         }
156     }
157 }
158
159 //
160 // CLASS transport_xhr
161 //
162 function transport_xhr(doc, xynt_streaming, page)
163 {
164     this.doc = doc;
165     this.xynt_streaming = xynt_streaming;
166     this.xhr = createXMLHttpRequest();
167     this.xhr.open('GET', page);
168
169     var self = this;
170     this.xhr.onreadystatechange = function () { self.xhr_cb(); };
171     this.xhr.send(null);
172
173     this.stopped = false;
174 }
175
176 transport_xhr.prototype = {
177     doc: null,
178     xynt_streaming: "ready",
179     xhr: null,
180     stopped: true,
181
182     ctx_old: "",
183     ctx_old_len: 0,
184     ctx_new: null,
185
186     // script_clean: 0,
187
188     destroy: function () { /* public */
189         if (this.xhr != null) {
190             this.xhr_abort();
191         }
192         delete this.xhr;
193     },
194
195     xhr_cb: function () {
196         var ret;
197
198         if (this.xhr.readyState == 4) {
199             // console.log("SS: "+safestatus(xhr));
200
201             // NOTE: delay management later
202             // try {
203             //     if ((ret = safestatus(this.xhr)) == 200) {
204             //         this.delay = 0;
205             //         // console.log("del a null "+this.delayed);
206             //     } else if (ret != -1) {
207             //         this.delay = 5000;
208             //         this.hbit('X');
209             //         // alert('There was a problem with the request.' + ret);
210             //     }
211             // } catch(b) {};
212
213             // this.delayed = null;
214             this.stopped = true;
215         }
216     },
217
218     xhr_abort: function() {
219         if (this.xhr != null) {
220             this.xhr.abort();
221         }
222     },
223
224     xstr_is_init: function () { /* public */
225         try {
226             if (this.xhr.responseText != null) {
227                 this.ctx_new = this.xhr.responseText;
228             }
229         }
230         catch (e) {
231         }
232
233         return (this.ctx_new != null);
234     },
235
236     /* only after a successfull is_initialized call */
237     xstr_is_ready: function () { /* public */
238         return (this.xynt_streaming == "ready");
239     },
240
241     xstr_set: function () { /* public */
242         // already set
243     },
244
245     ctx_new_is_set: function () { /* public */
246         return (this.ctx_new != null);
247     },
248
249     ctx_new_curlen_get: function () { /* public */
250         return (this.ctx_new.length);
251     },
252
253     ctx_new_getchar: function(idx) { /* public */
254         return (this.ctx_new[idx]);
255     },
256
257     ctx_old_len_is_set: function () { /* public */
258         return (true);
259     },
260
261     ctx_old_len_get: function () { /* public */
262         return (this.ctx_old_len);
263     },
264
265     ctx_old_len_set: function (len) { /* public */
266         this.ctx_old_len = len;
267     },
268
269     ctx_old_len_add: function (len) { /* public */
270         this.ctx_old_len += len;
271     },
272
273     new_part: function () { /* public */
274         return (this.ctx_new.substr(this.ctx_old_len));
275     },
276
277     scrcls_set: function (step) { /* public */
278         // this.script_clean = step;
279     },
280
281     postproc: function () {
282         if (this.stopped && !this.xstr_is_ready()) {
283             this.xynt_streaming.reload();
284         }
285     }
286 }
287
288 //
289 // CLASS transport_htmlfile
290 //
291 function transport_htmlfile(doc, xynt_streaming, page)
292 {
293     this.doc = doc;
294     this.xynt_streaming = xynt_streaming;
295     this.transfdoc = new ActiveXObject("htmlfile");
296     this.transfdoc.open();
297     this.transfdoc.write("<html><body><iframe id='iframe'></iframe></body></html>");
298     this.transfdoc.close();
299
300     this.ifra = this.transfdoc.getElementById("iframe");
301     this.ifra.contentWindow.location.href = page;
302     this.stopped = false;
303 }
304
305 transport_htmlfile.prototype = {
306     doc: null,
307     xynt_streaming: null,
308     stopped: true,
309     ifra: null,
310     tradoc: null,
311
312     destroy: function () { /* public */
313         if (this.ifra != null) {
314         //     this.doc.body.removeChild(this.ifra);
315         //     delete this.ifra;
316              this.ifra = null;
317         }
318
319         if (this.transfdoc) {
320             delete this.transfdoc;
321             this.transfdoc = null;
322         }
323     },
324
325     xstr_is_init: function () { /* public */
326         return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
327     },
328
329     /* only after a successfull is_initialized call */
330     xstr_is_ready: function () { /* public */
331         return (this.ifra.contentWindow.xynt_streaming == "ready");
332     },
333
334     /* only after a successfull is_initialized call */
335     xstr_set: function () { /* public */
336         if (this.ifra.contentWindow.xynt_streaming == "ready") {
337             this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
338             return (true);
339         }
340         else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
341             return (true);
342         }
343         else {
344             return (false);
345         }
346     },
347
348     ctx_new_is_set: function () { /* public */
349         return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
350     },
351
352     ctx_new_curlen_get: function () { /* public */
353         return (this.ifra.contentWindow.ctx_new.length);
354     },
355
356     ctx_new_getchar: function(idx) { /* public */
357         return (this.ifra.contentWindow.ctx_new.charAt(idx));
358     },
359
360     ctx_old_len_is_set: function () { /* public */
361         return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
362     },
363
364     ctx_old_len_get: function () { /* public */
365         return (this.ifra.contentWindow.ctx_old_len);
366     },
367
368     ctx_old_len_set: function (len) { /* public */
369         this.ifra.contentWindow.ctx_old_len = len;
370     },
371
372     ctx_old_len_add: function (len) { /* public */
373         this.ifra.contentWindow.ctx_old_len += len;
374     },
375
376     new_part: function () { /* public */
377         return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
378     },
379
380     scrcls_set: function (step) { /* public */
381         this.ifra.contentWindow.script_clean = step;
382     },
383
384     postproc: function () { /* public */
385         if (this.stopped && !this.xstr_is_ready()) {
386             this.xynt_streaming.reload();
387         }
388     }
389 }
390
391 //
392 // CLASS transport_iframe
393 //
394 function transport_iframe(doc, xynt_streaming, page)
395 {
396     this.doc = doc;
397     this.xynt_streaming = xynt_streaming;
398     this.ifra = doc.createElement("iframe");
399     this.ifra.style.visibility = "hidden";
400     doc.body.appendChild(this.ifra);
401     this.ifra.contentWindow.location.href = page;
402     this.stopped = false;
403 }
404
405 transport_iframe.prototype = {
406     doc: null,
407     xynt_streaming: null,
408     stopped: true,
409     ifra: null,
410
411     destroy: function () { /* public */
412         try {
413             if (this.ifra != null) {
414                 // NOTE:  on Opera this remove child crash js if called from
415                 //        inside of the iframe, on IE on Windows without
416                 //        it stream abort fails.
417                 //        the problem is fixed setting into the iframe's onload
418                 //        function the stopped attribute to true and delegate
419                 //        postproc() fired by xynt_streaming watchdog()
420                 this.doc.body.removeChild(this.ifra);
421                 delete this.ifra;
422                 this.ifra = null;
423             }
424         } catch (b) {
425             alert("destroy exception catched");
426         }
427     },
428
429     xstr_is_init: function () { /* public */
430         return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
431     },
432
433     /* only after a successfull is_initialized call */
434     xstr_is_ready: function () { /* public */
435         return (this.ifra.contentWindow.xynt_streaming == "ready");
436     },
437
438     /* only after a successfull is_initialized call */
439     xstr_set: function () { /* public */
440         if (this.ifra.contentWindow.xynt_streaming == "ready") {
441             this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
442             return (true);
443         }
444         else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
445             return (true);
446         }
447         else {
448             return (false);
449         }
450     },
451
452
453     /* only after a successfull is_ready call to be sure the accessibility of the var */
454     xstr_set_old: function (xynt_streaming) { /* public */
455         this.ifra.contentWindow.xynt_streaming = xynt_streaming;
456     },
457
458     ctx_new_is_set: function () { /* public */
459         return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
460     },
461
462     ctx_new_curlen_get: function () { /* public */
463         return (this.ifra.contentWindow.ctx_new.length);
464     },
465
466     ctx_new_getchar: function(idx) { /* public */
467         return (this.ifra.contentWindow.ctx_new.charAt(idx));
468     },
469
470     ctx_old_len_is_set: function () { /* public */
471         return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
472     },
473
474     ctx_old_len_get: function () { /* public */
475         return (this.ifra.contentWindow.ctx_old_len);
476     },
477
478     ctx_old_len_set: function (len) { /* public */
479         this.ifra.contentWindow.ctx_old_len = len;
480     },
481
482     ctx_old_len_add: function (len) { /* public */
483         this.ifra.contentWindow.ctx_old_len += len;
484     },
485
486     new_part: function () { /* public */
487         return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
488     },
489
490     scrcls_set: function (step) { /* public */
491         this.ifra.contentWindow.script_clean = step;
492     },
493
494     postproc: function () { /* public */
495         if (this.stopped && !this.xstr_is_ready()) {
496             this.xynt_streaming.reload();
497         }
498     }
499 }
500
501 function xynt_streaming(win, transp_type, transp_port, transp_fback, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
502 {
503     this.win = win;
504     this.transp_type = transp_type;
505     this.transp_port = transp_port;
506     this.transp_fback = transp_fback;
507     this.console = console;
508     this.gst = gst;
509     this.from = from;
510     this.cookiename = cookiename;
511     this.sess = sess;
512     this.sandbox = sandbox;
513     this.page = page;
514     this.cmdproc = cmdproc;
515     // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
516     this.doc = win.document;
517     this.keepalive_old = -1;
518     this.keepalive_new = -1;
519
520     this.mon_errtime = this.keepalives_eq_max * this.watchdog_checktm * this.watchdog_timeout;
521     this.mon_wrntime = this.mon_errtime / 2;
522
523     this.mon_update();
524 }
525
526 xynt_streaming.prototype = {
527     win:               null,
528     transp_type:       null,
529     transp_port:         80,
530     transp_fback:         0,
531     transp:            null,
532     console:           null,
533     gst:               null,
534     from:              null,
535     cookiename:        null,
536     sess:              null,
537     sandbox:           null,
538     page:              null,
539     cmdproc:           null,
540
541     start_time:        0,
542     restart_wait:      5000, // wait restart_wait millisec before begin to check if restart is needed
543
544     doc:               null,
545     cookiepath: "/brisk/",
546     watchdog_hdl:      null,
547     hbit:              function () {},
548     keepalive_old:    -1,
549     keepalive_new:    -1,
550     keepalives_equal:  0,
551     /* NOTE: right watch_timeout value to 100, for devel reasons use 1000 or more */
552     /* restart after  4 * 40 * 100 millisec if server ping is missing => 16secs */
553     keepalives_eq_max: 4,
554     watchdog_checktm:  40,
555     watchdog_timeout:  100,
556     watchdog_ct:       0,
557     watchable:         false,
558     restart_n:         0,
559     comm_match:        /_*@BEGIN@(.*?)@END@/g,
560     comm_clean:        /_*@BEGIN@(.*?)@END@/,
561     stream:            "",
562     the_end:           false,
563
564     mon_time:         -1,
565     mon_wrntime:       0,
566     mon_errtime:       0,
567
568     mon_stat_old:      "",
569
570     mon_update: function()
571     {
572         var date = new Date();
573
574         this.mon_time = date.getTime();
575     },
576
577     /*
578       ping arrives at least every RD_KEEPALIVE_TOUT secs (currently 4 secs)
579
580       return values: 0 unknown
581                      1 ok
582                      2 warning
583                      3 error
584      */
585     mon_status: function()
586     {
587         var delta, date;
588
589         var date = new Date();
590
591         delta = date.getTime() - this.mon_time;
592
593         if (delta < this.mon_wrntime)
594             return 1;
595         else if (delta < this.mon_errtime)
596             return 2;
597         else
598             return 3;
599     },
600
601     start: function() { /* public */
602         var transp_type;
603         var page;
604
605         // this.log("start "+this.transp_type+" "+this.transp_fback);
606         if (this.the_end)
607             return;
608
609         createCookie(this.cookiename, sess, 24*365, this.cookiepath);
610         // alert("start");
611         this.log("xynt_streaming:start restart: "+this.restart_n);
612         this.keepalives_equal = 0;
613
614         // page arrangement
615         this.page = url_complete(this.win.location.href, this.page);
616
617         if (this.transp_fback > 0) {
618             transp_type = "websocket";
619             transp_port = (this.transp_fback == 2 ? 80 : 8080);
620         }
621         else {
622             transp_type = this.transp_type;
623             transp_port = this.transp_port;
624         }
625
626         if (transp_type == "websocket") {
627             var end_proto, first_slash;
628
629             // change protocol
630             this.log("precha ["+this.page+"]");
631             end_proto = this.page.indexOf("://");
632             first_slash = this.page.substring(end_proto+3).indexOf("/");
633
634             page = "ws://" + this.page.substring(end_proto+3, end_proto+3+first_slash) + ":" + transp_port + this.page.substring(end_proto+3 + first_slash);
635         }
636         else {
637             page = this.page;
638         }
639         // stat, subst, this.gst.st
640
641         page = url_append_args(page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
642         // this.log("the page:");
643         // this.log(page);
644
645         try {
646             // transport instantiation
647             if (transp_type == "websocket") {
648                 page = url_append_args(page, "transp", "websocket");
649                 this.transp = new transport_ws(this.doc, this, page);
650             }
651             else if (transp_type == "xhr") {
652                 page = url_append_args(page, "transp", "xhr");
653                 this.transp = new transport_xhr(this.doc, this, page);
654             }
655             else if (transp_type == "iframe") {
656                 page = url_append_args(page, "transp", "iframe");
657                 this.transp = new transport_iframe(this.doc, this, page);
658             }
659             else if (transp_type == "htmlfile") {
660                 page = url_append_args(page, "transp", "htmlfile");
661                 this.transp = new transport_htmlfile(this.doc, this, page);
662             }
663             else
664                 return;
665         }
666         catch (err) {
667             if (this.transp_fback > 0) {
668                 this.transp_fback--;
669                 this.start();
670                 return;
671             }
672         }
673
674         // watchdog setting
675         this.watchdog_ct  = 0;
676         if (!this.the_end) {
677             this.watchdog_hdl = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this);
678         }
679
680         var date = new Date();
681         this.start_time = date.getTime();
682     },
683
684     stop: function() {
685         this.the_end = true;
686         this.abort();
687     },
688
689     hbit_set: function (hbit) {
690         this.hbit = hbit;
691     },
692
693
694     hbit_status: function () {
695         var ret;
696
697         ret = this.mon_status();
698         // console.log("mon_status: "+ret+" 0: "+this.mon_time);
699         switch (ret) {
700         case 0:
701             mon_stat = "b";
702             break;
703         case 1:
704             mon_stat = "g";
705             break;
706         case 2:
707             mon_stat = "y";
708             break;
709         case 3:
710             mon_stat = "r";
711             break;
712         }
713
714         if (this.mon_stat_old != mon_stat) {
715             this.hbit(mon_stat);
716             this.mon_stat_old = mon_stat;
717         }
718     },
719
720
721     watchdog: function () {
722         // alert("watchdog");
723         var i, again;
724         var comm_newpart, comm_len, comm_arr;
725         var ctx_new_len;
726
727         if (this.sandbox != null) {
728             // 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;
729             var zug = "WATCHDOG  sess = ["+this.sess+"]  step = "+this.gst.st+" step_loc = "+this.gst.st_loc+" step_loc_new = "+this.gst.st_loc_new;
730             if (zug != this.sandbox.innerHTML)
731                 this.sandbox.innerHTML = zug;
732         }
733
734         // WATCHDOGING THE CONNECTION
735         this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal);
736         if (!this.watchable) {
737             do {
738                 try{
739                     // if (typeof(this.ifra.contentWindow.xynt_streaming) == 'undefined')
740                     if (!this.transp.xstr_is_init()) {
741                         this.log("hs::watchdog: xstr_is_init = false");
742                         break;
743                     }
744                 }
745                 catch(b) {
746                     this.log("hs::watchdog: exception");
747                     break;
748                 }
749
750                 /*
751                   on IE7 the the window frame scope is cleaned after the href is set, so we wait
752                   for a well know variable value before assign this object value to it (OO is a passion)
753                 */
754                 // if (this.ifra.contentWindow.xynt_streaming == "ready") {
755                 if (this.transp.xstr_set()) {
756                     // this.ifra.contentWindow.xynt_streaming = this;
757                     this.watchable = true;
758                     this.watchdog_ct = 0;
759                     this.log("hs::watchdog: watchable = yes");
760                 }
761             } while (false);
762         }
763         if ( (this.watchdog_ct % this.watchdog_checktm) == 0) {
764             this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new);
765             if (this.keepalive_old == this.keepalive_new) {
766                 this.keepalives_equal++;
767             }
768             else {
769                 this.keepalive_old = this.keepalive_new;
770                 this.keepalives_equal = 0;
771             }
772
773             if (this.keepalives_equal >= this.keepalives_eq_max) {
774                 this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal);
775                 this.reload();
776                 // alert("watchdog return reload");
777                 this.hbit_status();
778                 return;
779             }
780         }
781
782         // PICK COMMANDS FROM STREAM
783         do {
784             // alert("do--while begin ["+again+"]");
785             // CHECK: maybe again here isn't needed
786             again = 0;
787             try {
788                 /* if (typeof(this.ifra.contentWindow.ctx_new)     == 'undefined' ||
789                    typeof(this.ifra.contentWindow.ctx_old_len) == 'undefined') */
790                 if (!this.transp.ctx_new_is_set() || !this.transp.ctx_old_len_is_set())
791                     break;
792             }
793             catch(b) {
794                 break;
795             }
796
797             // ctx_new_len = this.ifra.contentWindow.ctx_new.length;
798             ctx_new_len = this.transp.ctx_new_curlen_get();
799             // if (ctx_new_len <= this.ifra.contentWindow.ctx_old_len) {
800             if (ctx_new_len <= this.transp.ctx_old_len_get()) {
801                 break;
802             }
803             this.log("new: "+ ctx_new_len + "  old: "+this.transp.ctx_old_len_get());
804             this.keepalive_new++;
805             // alert("pre-loop 1");
806             for (i = this.transp.ctx_old_len_get() ; i < ctx_new_len ; i++) {
807                 // if (this.ifra.contentWindow.ctx_new.charAt(i) != '_') {
808                 if (this.transp.ctx_new_getchar(i) != '_') {
809                     // this.log("ctx_new.char(i) != '_' ["+this.ifra.contentWindow.ctx_new.charAt(i)+"]");
810                     break;
811                 }
812                 this.mon_update();
813                 this.hbit_status();
814
815                 // else {
816                 //     this.log("ctx_new.charAt(i) == '_'");
817                 // }
818             }
819             // this.ifra.contentWindow.ctx_old_len = i;
820             this.transp.ctx_old_len_set(i);
821             if (i == ctx_new_len) {
822                 this.log("old_len == i");
823                 break;
824             }
825             else {
826                 this.log("old_len != i: "+i);
827             }
828             // alert("do--while middle ["+this.ifra.contentWindow.ctx_old_len+"]");
829
830             comm_newpart = this.transp.new_part();
831             this.log("COM_NEWPART: ["+comm_newpart+"]");
832             comm_len = 0;
833             comm_arr = comm_newpart.match(this.comm_match);
834
835             // alert("do--while middle2 ["+again+"]");
836             if (comm_arr) {
837                 var comm_arr_len = comm_arr.length;
838                 for (i = 0 ; i < comm_arr_len ; i++) {
839                     var temp = comm_arr[i].replace(this.comm_clean,"$1").split("|");
840                     this.gst.comms = this.gst.comms.concat(temp);
841                     comm_len += comm_arr[i].length;
842                 }
843                 again = 1;
844                 this.mon_update();
845                 this.hbit_status();
846             }
847             // this.ifra.contentWindow.ctx_old_len += comm_len;
848             this.transp.ctx_old_len_add(comm_len);
849             // this.ifra.contentWindow.script_clean = this.gst.st;
850             this.transp.scrcls_set(this.gst.st);
851             // alert("do--while end ["+again+"]");
852         } while (again);
853
854         // alert("post while");
855         // EXECUTION OF STREAM COMMANDS
856         do {
857             again = 0;
858             //MOP ?? xhrrestart = 0;
859             if (this.gst.st_loc < this.gst.st_loc_new) {
860                 // there is some slow actions running
861                 break;
862             }
863             else if (this.gst.comms.length > 0) {
864                 var singlecomm;
865
866                 singlecomm = this.gst.comms.shift();
867                 // alert("EXE"+gugu);
868                 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "&lt;", "g"); +"<br>";
869                 //xx this.hbit("+");
870
871                 // alert("SINGLE: ["+singlecomm+"]");
872                 // window.console.log("["+singlecomm+"]");
873                 this.cmdproc(singlecomm);
874                 again = 1;
875             }
876         } while (again);
877         this.watchdog_ct++;
878         if (!this.the_end) {
879             var date = new Date();
880             if (date.getTime() > (this.start_time + this.restart_wait)) {
881                 this.transp.postproc();
882             }
883             this.watchdog_hdl = setTimeout(function(obj) { /* obj.log("tout2"); */ obj.watchdog(); }, this.watchdog_timeout, this);
884             this.hbit_status();
885         }
886         // alert("watchdog return normal");
887
888         return;
889     },
890
891     //
892     // moved to xynt-streaming-ifra as push()
893     //
894     // keepalive: function (s) {
895     //     this.log("hs::keepalive");
896     //     if (s != null) {
897     //         this.log(s);
898     //         this.ifra.contentWindow.ctx_new += "@BEGIN@"+s+"@END@";
899     //     }
900     //     else {
901     //         this.ifra.contentWindow.ctx_new += "_";
902     //     }
903     //     // this.keepalive_new++;
904     // },
905
906     abort: function () { /* public */
907         // this.log("PATH: "+this.ifra.contentWindow.location.protocol + "://" + this.ifra.contentWindow.location.host + "/" + this.ifra.contentWindow.location.pathname);
908
909         this.gst.abort();
910         if (this.watchdog_hdl != null) {
911             clearTimeout(this.watchdog_hdl);
912             this.watchdog_hdl = null;
913         }
914
915         this.restart_n++;
916         this.log("hs::reload");
917         this.watchable = false;
918         if (this.transp != null) {
919             this.transp.destroy();
920             delete this.transp;
921             this.transp = null;
922         }
923     },
924
925     reload: function () {
926         this.abort();
927         this.start(null);
928     },
929
930     log: function (s) {
931         if (this.console != null) {
932             return (this.console.log(s));
933         }
934     }
935 }