summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-10-08 19:14:13 +0000
committerroot <root@beaglebone.local.sublab.org>2013-10-08 19:14:13 +0000
commitecfa61ab231482d6403add3f163250564824fc62 (patch)
tree34c2e213574b3897844379cea91f04c107663a9a
parent60aa74a2eb4aa23e355afb78dc2f24c511406aef (diff)
svg/js: enable longpolling
-rw-r--r--svg/subcan.js46
-rw-r--r--svg/subcan_dxf.svg16
2 files changed, 58 insertions, 4 deletions
diff --git a/svg/subcan.js b/svg/subcan.js
index 6c56062..63d0e74 100644
--- a/svg/subcan.js
+++ b/svg/subcan.js
@@ -394,14 +394,27 @@ function update_elements(json) {
}
var xhr = new XMLHttpRequest();
+var xhrtimeout = null;
+var xhrlastref = null;
+
function xhr_handler() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
- data = JSON.parse(xhr.responseText);
+ if (xhr.responseText != '') {
+ rdata = JSON.parse(xhr.responseText);
+ data = rdata['data'];
+ xhrlastref = rdata['ref'];
+ }
+ console.log('xhr OK', xhrlastref);
+
+ timer(0);
+
/* for (attr in data) {
console.log('xhr attr', attr);
} */
update_elements(data);
+ } else if (xhr.status === 0) {
+ /* request abort, ignore */
} else {
console.log('xhr: something went wrong', xhr.status, xhr.statusText);
}
@@ -409,11 +422,36 @@ function xhr_handler() {
}
xhr.onreadystatechange = xhr_handler;
-function timer() {
- xhr.open('GET', '/');
+function ISOTS() {
+ function pad(n){return n<10 ? '0'+n : n}
+ var d = new Date();
+ return d.getUTCFullYear()+'-'
+ + pad(d.getUTCMonth()+1)+'-'
+ + pad(d.getUTCDate())+'T'
+ + pad(d.getUTCHours())+':'
+ + pad(d.getUTCMinutes())+':'
+ + pad(d.getUTCSeconds())+'Z';
+}
+
+function timer(expired) {
+ var dbgtext = document.getElementById('dbgtextreal');
+
+ if (expired) {
+ xhr.abort();
+ } else {
+ window.clearTimeout(xhrtimeout);
+ }
+
+ if (xhrlastref === null) {
+ xhr.open('GET', '/longpoll');
+ dbgtext.textContent = ISOTS() + ' (none)';
+ } else {
+ xhr.open('GET', '/longpoll?' + xhrlastref);
+ dbgtext.textContent = ISOTS() + ' ' + xhrlastref;
+ }
// xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.send(null);
- window.setTimeout(timer, 2000);
+ xhrtimeout = window.setTimeout(timer, 45000, 1);
}
function doload() {
diff --git a/svg/subcan_dxf.svg b/svg/subcan_dxf.svg
index 456ccb9..7e923c2 100644
--- a/svg/subcan_dxf.svg
+++ b/svg/subcan_dxf.svg
@@ -1302,6 +1302,22 @@
</g>
<g
inkscape:groupmode="layer"
+ id="layer13"
+ inkscape:label="debug">
+ <text
+ xml:space="preserve"
+ style="font-size:8px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:100%;letter-spacing:0px;word-spacing:0px;fill:#444444;fill-opacity:1;stroke:none;font-family:Monospace;-inkscape-font-specification:Monospace;text-anchor:start;text-align:start;writing-mode:lr"
+ x="40"
+ y="460"
+ id="dbgtext"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="dbgtextreal"
+ x="40"
+ y="460">loading...</tspan></text>
+ </g>
+ <g
+ inkscape:groupmode="layer"
id="layer11"
inkscape:label="guides"
style="opacity:0.14903846"