adapt to new async api and real properties

master
B. Petersen 2022-01-28 16:45:02 +01:00 committed by bjoern
parent 7a0e8c314a
commit f8e58dd532
2 changed files with 8 additions and 13 deletions

View File

@ -11,7 +11,7 @@
<script> <script>
function sendMsg() { function sendMsg() {
msg = document.getElementById("input").value; msg = document.getElementById("input").value;
window.webxdc.sendUpdate({payload: {name: window.webxdc.selfName(), msg: msg}}, 'someone typed "'+msg+'"'); window.webxdc.sendUpdate({payload: {name: window.webxdc.selfName, msg: msg}}, 'someone typed "'+msg+'"');
} }
function receiveUpdate(update) { function receiveUpdate(update) {
@ -19,7 +19,7 @@
} }
window.webxdc.setUpdateListener(receiveUpdate); window.webxdc.setUpdateListener(receiveUpdate);
window.webxdc.getAllUpdates().forEach(receiveUpdate); window.webxdc.getAllUpdates().then(updates => updates.forEach(receiveUpdate));
</script> </script>
</body> </body>
</html> </html>

View File

@ -15,19 +15,14 @@ window.webxdc = (() => {
} }
}); });
var params = new URLSearchParams(window.location.hash.substr(1));
return { return {
selfAddr: () => { selfAddr: params.get("addr") || "device0@local.host",
var params = new URLSearchParams(window.location.hash.substr(1)); selfName: params.get("name") || "device0",
return params.get("addr") || "device0@local.host";
},
selfName: () => {
var params = new URLSearchParams(window.location.hash.substr(1));
return params.get("name") || "device0";
},
setUpdateListener: (cb) => (updateListener = cb), setUpdateListener: (cb) => (updateListener = cb),
getAllUpdates: () => { getAllUpdates: () => {
var updatesJSON = window.localStorage.getItem(updatesKey); var updatesJSON = window.localStorage.getItem(updatesKey);
return updatesJSON ? JSON.parse(updatesJSON) : []; return Promise.resolve(updatesJSON ? JSON.parse(updatesJSON) : []);
}, },
sendUpdate: (update, description) => { sendUpdate: (update, description) => {
// alert(description+"\n\n"+JSON.stringify(payload)); // alert(description+"\n\n"+JSON.stringify(payload));
@ -72,9 +67,9 @@ window.alterXdcApp = () => {
title = document.createElement('title'); title = document.createElement('title');
document.getElementsByTagName('head')[0].append(title); document.getElementsByTagName('head')[0].append(title);
} }
title.innerText = window.webxdc.selfAddr(); title.innerText = window.webxdc.selfAddr;
if (window.webxdc.selfName() === "device0") { if (window.webxdc.selfName === "device0") {
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = div.innerHTML =
'<div style="' + styleControlPanel + '">' + '<div style="' + styleControlPanel + '">' +