diff --git a/index.html b/index.html index 2a4e511..753ec18 100644 --- a/index.html +++ b/index.html @@ -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 += "<" + update.payload.addr + "> " + update.payload.msg + "
"; + document.getElementById('output').innerHTML += "<" + update.payload.name + "> " + update.payload.msg + "
"; } window.webxdc.setUpdateListener(receiveUpdate); diff --git a/webxdc.js b/webxdc.js index 5a4166f..57a71fa 100644 --- a/webxdc.js +++ b/webxdc.js @@ -54,6 +54,7 @@ window.webxdc = (() => { return { selfAddr: () => window.xdcSelfAddr || "device0@local.host", + selfName: () => window.xdcSelfName || "device0", setUpdateListener: (cb) => (window.xdcUpdateListener = cb), getAllUpdates: () => {return getXdcRoot().xdcStorage.getUpdates();}, sendUpdate: (description, payload) => { @@ -92,7 +93,8 @@ function addXdcPeer() { 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); } @@ -104,19 +106,19 @@ function clearXdcStorage() { function alterApp() { var title = document.getElementsByTagName('title')[0]; if (typeof title == 'undefined') { - title = document.createElement('title'); - document.getElementsByTagName('head')[0].append(title); + title = document.createElement('title'); + document.getElementsByTagName('head')[0].append(title); } title.innerText = window.webxdc.selfAddr(); - if (getXdcRoot() == window) { - var div = document.createElement('div'); - div.innerHTML = - '
' + - 'Add Peer | ' + - 'Clear Storage' + - '
'; - document.getElementsByTagName('body')[0].append(div.firstChild); + if (getXdcRoot() === window) { + var div = document.createElement('div'); + div.innerHTML = + '
' + + 'Add Peer | ' + + 'Clear Storage' + + '
'; + document.getElementsByTagName('body')[0].append(div.firstChild); } }