+//
+// CLASS transport_ws
+//
+function transport_ws(doc, xynt_streaming, page)
+{
+ this.ctx_new = "";
+ var self = this;
+
+ this.doc = doc;
+ this.failed = false;
+ this.xynt_streaming = xynt_streaming;
+ try {
+this.xynt_streaming.log("PAGE: "+page);
+ this.ws = new WebSocket(page);
+ this.ws.onopen = function () {
+ self.xynt_streaming.log("onopen");
+ if (this.readyState == 1) {
+ // connected
+ self.ws_cb("open");
+ self.init_steps = 1;
+ }
+ };
+ this.ws.onmessage = function (msg) {
+ self.xynt_streaming.log("onmessage");
+ // new data in msg.data
+ self.ctx_new += msg.data;
+ };
+ this.ws.onclose = function (msg) {
+ this.onopen = null;
+ this.onclose = null;
+ this.onerror = null;
+ self.xynt_streaming.log("onclose"+self.init_steps);
+ if (self.init_steps == 0)
+ self.ws_cb("error");
+ else
+ self.ws_cb("close");
+ };
+ this.ws.onerror = function () {
+ // on error
+ this.onopen = null;
+ this.onclose = null;
+ this.onerror = null;
+ self.xynt_streaming.log("onerror");
+ self.ws_cb("error");
+ };
+ }
+ catch (ex) {
+ throw "websocket creation failed";
+ }
+
+ this.stopped = false;
+}
+
+transport_ws.prototype = {
+ doc: null,
+ xynt_streaming: "ready",
+ ws: null,
+ stopped: true,
+ failed: false,
+
+ init_steps: 0,
+
+ ctx_old: "",
+ ctx_old_len: 0,
+ ctx_new: "",
+
+ // script_clean: 0,
+
+ destroy: function () { /* public */
+ if (this.ws != null) {
+ this.ws_abort();
+ }
+ delete this.ws;
+ },
+
+ ws_cb: function (from) {
+ var ret;
+
+ if (from == "error") {
+ if (this.xynt_streaming != "ready") {
+ if (this.xynt_streaming.transp_fback > 0) {
+this.xynt_streaming.log("DEC: "+this.xynt_streaming.transp_fback);
+ this.xynt_streaming.transp_fback--;
+ this.stopped = true;
+ this.xynt_streaming.reload();
+ }
+ }
+ }
+ if (this.ws != null && this.ws.readyState > 1) {
+ this.stopped = true;
+ }
+ },
+
+ ws_abort: function() {
+ if (this.ws != null) {
+this.xynt_streaming.log("WSCLOSE");
+ this.ws.close();
+ }
+ },
+
+ xstr_is_init: function () { /* public */
+ return (true);
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_is_ready: function () { /* public */
+ return (this.ws.readyState == 1);
+ },
+
+ xstr_set: function () { /* public */
+ // already set
+ },
+
+ ctx_new_is_set: function () { /* public */
+ return (this.ctx_new != null);
+ },
+
+ ctx_new_curlen_get: function () { /* public */
+ return (this.ctx_new.length);
+ },
+
+ ctx_new_getchar: function(idx) { /* public */
+ return (this.ctx_new[idx]);
+ },
+
+ ctx_old_len_is_set: function () { /* public */
+ return (true);
+ },
+
+ ctx_old_len_get: function () { /* public */
+ return (this.ctx_old_len);
+ },
+
+ ctx_old_len_set: function (len) { /* public */
+ this.ctx_old_len = len;
+ },
+
+ ctx_old_len_add: function (len) { /* public */
+ this.ctx_old_len += len;
+ },
+
+ new_part: function () { /* public */
+ return (this.ctx_new.substr(this.ctx_old_len));
+ },
+
+ scrcls_set: function (step) { /* public */
+ // this.script_clean = step;
+ },
+
+ postproc: function () {
+ if (this.stopped && !this.xstr_is_ready()) {
+ this.xynt_streaming.reload();
+ }
+ }
+}
+
+//
+// CLASS transport_xhr
+//
+function transport_xhr(doc, xynt_streaming, page)
+{
+ this.doc = doc;
+ this.xynt_streaming = xynt_streaming;
+ this.xhr = createXMLHttpRequest();
+ this.xhr.open('GET', page);
+
+ var self = this;
+ this.xhr.onreadystatechange = function () { self.xhr_cb(); };
+ this.xhr.send(null);
+
+ this.stopped = false;
+}
+
+transport_xhr.prototype = {
+ doc: null,
+ xynt_streaming: "ready",
+ xhr: null,
+ stopped: true,
+
+ ctx_old: "",
+ ctx_old_len: 0,
+ ctx_new: null,
+
+ // script_clean: 0,
+
+ destroy: function () { /* public */
+ if (this.xhr != null) {
+ this.xhr_abort();
+ }
+ delete this.xhr;
+ },
+
+ xhr_cb: function () {
+ var ret;
+
+ if (this.xhr.readyState == 4) {
+ // console.log("SS: "+safestatus(xhr));
+
+ // NOTE: delay management later
+ // try {
+ // if ((ret = safestatus(this.xhr)) == 200) {
+ // this.delay = 0;
+ // // console.log("del a null "+this.delayed);
+ // } else if (ret != -1) {
+ // this.delay = 5000;
+ // this.hbit('X');
+ // // alert('There was a problem with the request.' + ret);
+ // }
+ // } catch(b) {};
+
+ // this.delayed = null;
+ this.stopped = true;
+ }
+ },
+
+ xhr_abort: function() {
+ if (this.xhr != null) {
+ this.xhr.abort();
+ }
+ },
+
+ xstr_is_init: function () { /* public */
+ try {
+ if (this.xhr.responseText != null) {
+ this.ctx_new = this.xhr.responseText;
+ }
+ }
+ catch (e) {
+ }
+
+ return (this.ctx_new != null);
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_is_ready: function () { /* public */
+ return (this.xynt_streaming == "ready");
+ },
+
+ xstr_set: function () { /* public */
+ // already set
+ },
+
+ ctx_new_is_set: function () { /* public */
+ return (this.ctx_new != null);
+ },
+
+ ctx_new_curlen_get: function () { /* public */
+ return (this.ctx_new.length);
+ },
+
+ ctx_new_getchar: function(idx) { /* public */
+ return (this.ctx_new[idx]);
+ },
+
+ ctx_old_len_is_set: function () { /* public */
+ return (true);
+ },
+
+ ctx_old_len_get: function () { /* public */
+ return (this.ctx_old_len);
+ },
+
+ ctx_old_len_set: function (len) { /* public */
+ this.ctx_old_len = len;
+ },
+
+ ctx_old_len_add: function (len) { /* public */
+ this.ctx_old_len += len;
+ },
+
+ new_part: function () { /* public */
+ return (this.ctx_new.substr(this.ctx_old_len));
+ },
+
+ scrcls_set: function (step) { /* public */
+ // this.script_clean = step;
+ },
+
+ postproc: function () {
+ if (this.stopped && !this.xstr_is_ready()) {
+ this.xynt_streaming.reload();
+ }
+ }
+}
+
+//
+// CLASS transport_htmlfile
+//
+function transport_htmlfile(doc, xynt_streaming, page)
+{
+ this.doc = doc;
+ this.xynt_streaming = xynt_streaming;
+ this.transfdoc = new ActiveXObject("htmlfile");
+ this.transfdoc.open();
+ this.transfdoc.write("<html><body><iframe id='iframe'></iframe></body></html>");
+ this.transfdoc.close();
+
+ this.ifra = this.transfdoc.getElementById("iframe");
+ this.ifra.contentWindow.location.href = page;
+ this.stopped = false;
+}
+
+transport_htmlfile.prototype = {
+ doc: null,
+ xynt_streaming: null,
+ stopped: true,
+ ifra: null,
+ tradoc: null,
+
+ destroy: function () { /* public */
+ if (this.ifra != null) {
+ // this.doc.body.removeChild(this.ifra);
+ // delete this.ifra;
+ this.ifra = null;
+ }
+
+ if (this.transfdoc) {
+ delete this.transfdoc;
+ this.transfdoc = null;
+ }
+ },
+
+ xstr_is_init: function () { /* public */
+ return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_is_ready: function () { /* public */
+ return (this.ifra.contentWindow.xynt_streaming == "ready");
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_set: function () { /* public */
+ if (this.ifra.contentWindow.xynt_streaming == "ready") {
+ this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
+ return (true);
+ }
+ else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
+ return (true);
+ }
+ else {
+ return (false);
+ }
+ },
+
+ ctx_new_is_set: function () { /* public */
+ return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
+ },
+
+ ctx_new_curlen_get: function () { /* public */
+ return (this.ifra.contentWindow.ctx_new.length);
+ },
+
+ ctx_new_getchar: function(idx) { /* public */
+ return (this.ifra.contentWindow.ctx_new.charAt(idx));
+ },
+
+ ctx_old_len_is_set: function () { /* public */
+ return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
+ },
+
+ ctx_old_len_get: function () { /* public */
+ return (this.ifra.contentWindow.ctx_old_len);
+ },
+
+ ctx_old_len_set: function (len) { /* public */
+ this.ifra.contentWindow.ctx_old_len = len;
+ },
+
+ ctx_old_len_add: function (len) { /* public */
+ this.ifra.contentWindow.ctx_old_len += len;
+ },
+
+ new_part: function () { /* public */
+ return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
+ },
+
+ scrcls_set: function (step) { /* public */
+ this.ifra.contentWindow.script_clean = step;
+ },
+
+ postproc: function () { /* public */
+ if (this.stopped && !this.xstr_is_ready()) {
+ this.xynt_streaming.reload();
+ }
+ }
+}
+
+//
+// CLASS transport_iframe
+//
+function transport_iframe(doc, xynt_streaming, page)
+{
+ this.doc = doc;
+ this.xynt_streaming = xynt_streaming;
+ this.ifra = doc.createElement("iframe");
+ this.ifra.style.visibility = "hidden";
+ doc.body.appendChild(this.ifra);
+ this.ifra.contentWindow.location.href = page;
+ this.stopped = false;
+}
+
+transport_iframe.prototype = {
+ doc: null,
+ xynt_streaming: null,
+ stopped: true,
+ ifra: null,
+
+ destroy: function () { /* public */
+ try {
+ if (this.ifra != null) {
+ // NOTE: on Opera this remove child crash js if called from
+ // inside of the iframe, on IE on Windows without
+ // it stream abort fails.
+ // the problem is fixed setting into the iframe's onload
+ // function the stopped attribute to true and delegate
+ // postproc() fired by xynt_streaming watchdog()
+ this.doc.body.removeChild(this.ifra);
+ delete this.ifra;
+ this.ifra = null;
+ }
+ } catch (b) {
+ alert("destroy exception catched");
+ }
+ },
+
+ xstr_is_init: function () { /* public */
+ return (typeof(this.ifra.contentWindow.xynt_streaming) != 'undefined');
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_is_ready: function () { /* public */
+ return (this.ifra.contentWindow.xynt_streaming == "ready");
+ },
+
+ /* only after a successfull is_initialized call */
+ xstr_set: function () { /* public */
+ if (this.ifra.contentWindow.xynt_streaming == "ready") {
+ this.ifra.contentWindow.xynt_streaming = this.xynt_streaming;
+ return (true);
+ }
+ else if (this.ifra.contentWindow.xynt_streaming == this.xynt_streaming) {
+ return (true);
+ }
+ else {
+ return (false);
+ }
+ },
+
+
+ /* only after a successfull is_ready call to be sure the accessibility of the var */
+ xstr_set_old: function (xynt_streaming) { /* public */
+ this.ifra.contentWindow.xynt_streaming = xynt_streaming;
+ },
+
+ ctx_new_is_set: function () { /* public */
+ return (typeof(this.ifra.contentWindow.ctx_new) != 'undefined');
+ },
+
+ ctx_new_curlen_get: function () { /* public */
+ return (this.ifra.contentWindow.ctx_new.length);
+ },
+
+ ctx_new_getchar: function(idx) { /* public */
+ return (this.ifra.contentWindow.ctx_new.charAt(idx));
+ },
+
+ ctx_old_len_is_set: function () { /* public */
+ return (typeof(this.ifra.contentWindow.ctx_old_len) != 'undefined');
+ },
+
+ ctx_old_len_get: function () { /* public */
+ return (this.ifra.contentWindow.ctx_old_len);
+ },
+
+ ctx_old_len_set: function (len) { /* public */
+ this.ifra.contentWindow.ctx_old_len = len;
+ },
+
+ ctx_old_len_add: function (len) { /* public */
+ this.ifra.contentWindow.ctx_old_len += len;
+ },
+
+ new_part: function () { /* public */
+ return (this.ifra.contentWindow.ctx_new.substr(this.ifra.contentWindow.ctx_old_len));
+ },
+
+ scrcls_set: function (step) { /* public */
+ this.ifra.contentWindow.script_clean = step;
+ },
+
+ postproc: function () { /* public */
+ if (this.stopped && !this.xstr_is_ready()) {
+ this.xynt_streaming.reload();
+ }
+ }
+}
+
+function xynt_streaming(win, transp_type, transp_port, transp_fback, console, gst, from, cookiename, sess, sandbox, page, cmdproc)