implement getAllUpdates()

master
adbenitez 2022-01-02 16:19:04 -05:00
parent a4f9e07f4e
commit be5f1b8f99
2 changed files with 6 additions and 5 deletions

View File

@ -20,6 +20,7 @@
}
window.webxdc.setUpdateListener(receiveUpdate);
window.webxdc.getAllUpdates().forEach(receiveUpdate);
</script>
</body>

View File

@ -8,23 +8,23 @@ window.webxdc = (() => {
selfAddr: () => window.xdcSelfAddr || "device0@local.host",
setUpdateListener: (cb) => (window.xdcUpdateListener = cb),
getAllUpdates: () => {
return JSON.parse(
'[]'
//'[{"action":"configure", "question":"your favorite colorxx", "answers":["red","green","blue","yellow","purple1"]},{"action":"vote", "sender":"foo2@bar.de", "vote":0},{"action":"vote", "sender":"foo@bar.de", "vote":0}]'
);
return getXdcRoot().xdcUpdates;
},
sendUpdate: (description, payload) => {
// alert(description+"\n\n"+JSON.stringify(payload));
var update = {payload: payload};
getXdcRoot().xdcUpdates.push(update);
var all = getAllXdcWindows();
all.forEach((w) => {
//alert(w.xdcUpdateListener);
w.xdcUpdateListener({payload: payload});
w.xdcUpdateListener(update);
});
},
};
})();
window.allXdcWindows = [window];
window.xdcUpdates = [];
window.xdcUpdateListener = 12;
var styleControlPanel = 'position: fixed; bottom:1em; left:1em; background-color: #000; opacity:0.8; padding:.5em; font-family: sans-serif; width: 50%;';