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