From 500b601f26d3c352800f45136e2ff617c8f7627c Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Mon, 3 Dec 2012 18:11:39 +0100 Subject: [PATCH] transport_xhr added --- web/Obj/transports.phh | 10 +++ web/xynt-streaming.js | 194 +++++++++++++++++++++++++++++++++++++---- web/xynt_test01.php | 5 +- 3 files changed, 190 insertions(+), 19 deletions(-) diff --git a/web/Obj/transports.phh b/web/Obj/transports.phh index b426043..72ad49b 100644 --- a/web/Obj/transports.phh +++ b/web/Obj/transports.phh @@ -47,14 +47,24 @@ class Transport_xhr { function init($enc, &$header_out, $init_string, $base, $step) { + $ret = $init_string; + if ($enc != 'plain') + $header_out['Content-Encoding'] = $enc; + $header_out['Cache-Control'] = 'no-cache, must-revalidate'; // HTTP/1.1 + $header_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // Date in the past + $header_out['Content-type'] = 'application/xml; charset="utf-8"'; + + return ($ret); } static function fini($init_string, $blockerr) { + return (""); } function chunk($step, $cont) { + return ("@BEGIN@".$cont."@END@"); } } diff --git a/web/xynt-streaming.js b/web/xynt-streaming.js index f703aff..117c9f7 100644 --- a/web/xynt-streaming.js +++ b/web/xynt-streaming.js @@ -1,11 +1,140 @@ // old targetpage == page and moved into start method +// +// 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 */ + }, + + 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, page) +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("