adapt to new async api and real properties
This commit is contained in:
parent
7a0e8c314a
commit
f8e58dd532
|
@ -11,7 +11,7 @@
|
|||
<script>
|
||||
function sendMsg() {
|
||||
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) {
|
||||
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
|
||||
window.webxdc.setUpdateListener(receiveUpdate);
|
||||
window.webxdc.getAllUpdates().forEach(receiveUpdate);
|
||||
window.webxdc.getAllUpdates().then(updates => updates.forEach(receiveUpdate));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
17
webxdc.js
17
webxdc.js
|
@ -15,19 +15,14 @@ window.webxdc = (() => {
|
|||
}
|
||||
});
|
||||
|
||||
var params = new URLSearchParams(window.location.hash.substr(1));
|
||||
return {
|
||||
selfAddr: () => {
|
||||
var params = new URLSearchParams(window.location.hash.substr(1));
|
||||
return params.get("addr") || "device0@local.host";
|
||||
},
|
||||
selfName: () => {
|
||||
var params = new URLSearchParams(window.location.hash.substr(1));
|
||||
return params.get("name") || "device0";
|
||||
},
|
||||
selfAddr: params.get("addr") || "device0@local.host",
|
||||
selfName: params.get("name") || "device0",
|
||||
setUpdateListener: (cb) => (updateListener = cb),
|
||||
getAllUpdates: () => {
|
||||
var updatesJSON = window.localStorage.getItem(updatesKey);
|
||||
return updatesJSON ? JSON.parse(updatesJSON) : [];
|
||||
return Promise.resolve(updatesJSON ? JSON.parse(updatesJSON) : []);
|
||||
},
|
||||
sendUpdate: (update, description) => {
|
||||
// alert(description+"\n\n"+JSON.stringify(payload));
|
||||
|
@ -72,9 +67,9 @@ window.alterXdcApp = () => {
|
|||
title = document.createElement('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');
|
||||
div.innerHTML =
|
||||
'<div style="' + styleControlPanel + '">' +
|
||||
|
|
Loading…
Reference in a new issue