4 * Copyright (C) 2006-2011 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
28 * - sandbox management
29 * - myfrom into the constructor
30 * - target page into the constructor
31 * - type of streaming into the constructor
32 * - all iframe related streaming add
33 * - xhr_rd prefix remove from inner class attrs
34 * - substitute fixed "eval" with a generic command hunks processor
40 if ($("heartbit").innerHTML.length >= 120) {
41 $("heartbit").innerHTML = $("heartbit").innerHTML.substring(10);
42 $("heartbit").innerHTML += symb;
45 $("heartbit").innerHTML += symb;
47 // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!!
48 // console.log($("heartbit").innerHTML);
52 function http_streaming()
54 this.xhr_rd = createXMLHttpRequest();
57 http_streaming.prototype = {
58 xhr_rd_cookiepath: "/brisk/",
61 xhr_rd_watchdog: null,
77 hbit_set: function (hbit) {
81 xhr_rd_cb: function () {
84 if (this.xhr_rd.readyState == 4) {
85 if (this.xhr_rd_watchdog != null) {
87 clearTimeout(this.xhr_rd_watchdog);
88 this.xhr_rd_watchdog = null;
91 // console.log("SS: "+safestatus(xhr_rd));
94 if ((ret = safestatus(this.xhr_rd)) == 200) {
95 this.xhr_rd_delay = 0;
96 // console.log("del a null "+this.xhr_rd_delayed);
97 } else if (ret != -1) {
98 this.xhr_rd_delay = 5000;
100 // alert('There was a problem with the request.' + ret);
104 this.xhr_rd_delayed = null;
105 this.xhr_rd_stopped = true;
109 xhr_rd_abort: function()
112 if (this.xhr_rd != null)
117 xhr_rd_start: function(sess, stat, subst, step)
120 //x alert("the_end1");
121 if (this.xhr_rd_watchdog != null) {
123 clearTimeout(this.xhr_rd_watchdog);
124 this.xhr_rd_watchdog = null;
128 createCookie("sess", sess, 24*365, this.xhr_rd_cookiepath);
130 // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
131 this.xhr_rd_oldctx = "";
132 this.xhr_rd_newctx = "";
134 /* NOTE document.uniqueID exists only under IE */
135 // if (g_is_spawn == 1)
136 // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
137 this.xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
141 this.xhr_rd.onreadystatechange = function () { self.xhr_rd_cb(); };
142 this.xhr_rd.send(null);
144 // TODO: qui avvio del timer per riavviare xhr
146 this.xhr_rd_watchdog = setTimeout(function(obj){ obj.xhr_rd_abort(); }, 60000, this);
148 this.xhr_rd_stopped = false;
152 /* WORK HERE TO RUN WIN OR LIN STREAM */
154 xhr_rd_poll: function(sess)
163 if (this.watchdog >= 50) {
165 // alert("ABORT XHR_RD");
166 this.xhr_rd_stopped = true;
170 var zug = "XHR_RD_POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+this.xhr_rd_stopped;
172 if (zug != $("sandbox").innerHTML)
173 $("sandbox").innerHTML = zug;
180 if (gst.st_loc < gst.st_loc_new) {
181 // there is some slow actions running
184 else if (gst.comms.length > 0) {
187 singlecomm = gst.comms.shift();
188 // alert("EXE"+gugu);
189 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
198 if (this.xhr_rd == null)
200 if (this.xhr_rd.responseText != null)
201 this.xhr_rd_newctx = this.xhr_rd.responseText;
204 if (this.xhr_rd_stopped == true) {
205 this.xhr_rd_stopped = false;
206 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
207 if (this.xhr_rd_delay > 0) {
208 if (this.xhr_rd_delayed == null) {
209 // console.log("XXX DI QUI "+this.xhr_rd_delay);
211 this.xhr_rd_delayed = setTimeout(
212 function(f_obj, f_sess, f_stat, f_subst, f_step){ f_obj.xhr_rd_start(f_sess, f_stat, f_subst, f_step); },
213 this.xhr_rd_delay, this, sess, stat, subst, gst.st);
214 // console.log("XXX DI QUI post"+this.xhr_rd_delayed);
218 // console.log("yyy DI QUI "+this.xhr_rd_delay);
219 this.xhr_rd_start(sess, stat, subst, gst.st);
224 // $("sandbox").innerHTML += "return 1<br>";
225 if (this.the_end != true) {
227 setTimeout(function(obj, sess){ obj.xhr_rd_poll(sess); }, tout, this, sess);
233 //x alert("the_end2");
234 if (this.xhr_rd_watchdog != null) {
235 clearTimeout(this.xhr_rd_watchdog);
236 this.xhr_rd_watchdog = null;
243 // no new char from the last loop, break
244 if (this.xhr_rd_old_n == this.xhr_rd_cur_n &&
245 this.xhr_rd_newctx.length == this.xhr_rd_checkedlen) {
250 // $("sandbox").innerHTML += "BIG IF<br>";
258 var match_lines = /^_*$/;
263 // check for the same command group
264 if (this.xhr_rd_old_n != this.xhr_rd_cur_n) {
265 this.xhr_rd_old_n = this.xhr_rd_cur_n;
266 this.xhr_rd_checkedlen = 0;
267 this.xhr_rd_oldctx = "";
270 delta = this.xhr_rd_oldctx.length;
272 // $("xhrlog").innerHTML += "EVERY SEC<br>";
273 for (i = delta ; i < this.xhr_rd_newctx.length ; i++) {
274 if (this.xhr_rd_newctx[i] != '_')
277 if (i == this.xhr_rd_newctx.length) {
278 this.xhr_rd_checkedlen = i;
282 // $("xhrlog").innerHTML += "CHECK COM<br>";
283 // extracts the new part of the command string
284 comm_newpart = this.xhr_rd_newctx.substr(delta);
286 // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
288 // $("response").innerHTML = comm_newpart;
289 comm_match = /_*@BEGIN@(.*?)@END@/g;
290 comm_clean = /_*@BEGIN@(.*?)@END@/;
292 comm_arr = comm_newpart.match(comm_match);
294 // $("sandbox").innerHTML += "PRE COMMARR<br>";
296 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
297 // XX alert("xhr_rd_newctx: "+this.xhr_rd_newctx);
298 // $("sandbox").innerHTML += "POST COMMARR<br>";
299 for (i = 0 ; i < comm_arr.length ; i++) {
300 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
301 gst.comms = gst.comms.concat(temp);
302 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
303 comm_len += comm_arr[i].length;
306 this.xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
307 // XX alert("XHR_RD_OLDCTX: "+this.xhr_rd_oldctx);
310 this.xhr_rd_checkedlen = this.xhr_rd_oldctx.length;
315 if (xhrrestart == 1 && this.xhr_rd_stopped == true) {
316 // $("sandbox").innerHTML += "LITTLE IF<br>";
318 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
319 if (this.xhr_rd_delay > 0) {
320 if (this.xhr_rd_delayed == null) {
321 // console.log("XXX DI QUO "+this.xhr_rd_delay);
323 this.xhr_rd_delayed = setTimeout(
324 function(obj, sess, stat, subst, step){ obj.xhr_rd_start(sess, stat, subst, step); },
325 this.xhr_rd_delay, this, sess, stat, subst, gst.st);
326 // console.log("XXX DI QUO post"+this.xhr_rd_delayed);
330 // console.log("yyy DI QUO "+this.xhr_rd_delay);
331 this.xhr_rd_start(sess, stat, subst, gst.st);
336 if (this.the_end != true) {
337 setTimeout(function(obj, sess){ obj.xhr_rd_poll(sess); }, tout, this, sess);
340 //x alert("the_end3");
341 if (this.xhr_rd_watchdog != null) {
342 clearTimeout(this.xhr_rd_watchdog);
343 this.xhr_rd_watchdog = null;
351 window.onload = function () {
352 xhr_rd = createXMLHttpRequest();
354 sess = $("user").value;
355 window.setTimeout(xhr_rd_poll, 0, sess);