From 3f8569174e060d010c91e9da08fa64fc65645e81 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Sun, 2 Jan 2022 15:47:10 -0500 Subject: [PATCH 1/2] add selfName to API --- index.html | 4 ++-- webxdc.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 9831560..d02b41a 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 d80e91f..c96c58a 100644 --- a/webxdc.js +++ b/webxdc.js @@ -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); } From 7ccffa6c890eb105c165720ca74589aa4e4838dd Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 2 Jan 2022 22:01:17 +0100 Subject: [PATCH 2/2] taps to spaces, correct equal check --- webxdc.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/webxdc.js b/webxdc.js index d80e91f..6980897 100644 --- a/webxdc.js +++ b/webxdc.js @@ -54,18 +54,18 @@ function addPeer() { 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' + - '
'; - document.getElementsByTagName('body')[0].append(div.firstChild); + if (getXdcRoot() === window) { + var div = document.createElement('div'); + div.innerHTML = + '
' + + 'Add Peer' + + '
'; + document.getElementsByTagName('body')[0].append(div.firstChild); } }