add selfName to API

master
adbenitez 2022-01-02 15:47:10 -05:00
parent a4f9e07f4e
commit 3f8569174e
2 changed files with 5 additions and 3 deletions

View File

@ -12,11 +12,11 @@
function sendMsg() {
msg = document.getElementById("input").value;
window.webxdc.sendUpdate('someone typed "'+msg+'"', {"addr": window.webxdc.selfAddr(), "msg": msg});
window.webxdc.sendUpdate('someone typed "'+msg+'"', {"name": window.webxdc.selfName(), "msg": msg});
}
function receiveUpdate(update) {
document.getElementById('output').innerHTML += "<strong>&lt;" + update.payload.addr + "&gt;</strong> " + update.payload.msg + "<br>";
document.getElementById('output').innerHTML += "<strong>&lt;" + update.payload.name + "&gt;</strong> " + update.payload.msg + "<br>";
}
window.webxdc.setUpdateListener(receiveUpdate);

View File

@ -6,6 +6,7 @@ window.webxdc = (() => {
return {
selfAddr: () => window.xdcSelfAddr || "device0@local.host",
selfName: () => window.xdcSelfName || "device0",
setUpdateListener: (cb) => (window.xdcUpdateListener = cb),
getAllUpdates: () => {
return JSON.parse(
@ -47,7 +48,8 @@ function addPeer() {
var xdcChild = window.open(window.location);
var xdcRoot = getXdcRoot();
xdcChild.xdcRoot = xdcRoot;
xdcChild.xdcSelfAddr = "device" + xdcRoot.allXdcWindows.length + "@local.host";
xdcChild.xdcSelfName = "device" + getAllXdcWindows().length;
xdcChild.xdcSelfAddr = xdcChild.xdcSelfName + "@local.host";
xdcRoot.allXdcWindows.push(xdcChild);
}