Merge branch 'master' into issue-2

master
Asiel Díaz Benítez 2022-01-02 18:26:38 -05:00 committed by GitHub
commit a2dc524416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 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

@ -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 =
'<div style="' + styleControlPanel + '">' +
'<a href="javascript:addXdcPeer();" style="' + styleMenuLink + '">Add Peer</a> | ' +
'<a href="javascript:clearXdcStorage();" style="' + styleMenuLink + '">Clear Storage</a>' +
'<div>';
document.getElementsByTagName('body')[0].append(div.firstChild);
if (getXdcRoot() === window) {
var div = document.createElement('div');
div.innerHTML =
'<div style="' + styleControlPanel + '">' +
'<a href="javascript:addXdcPeer();" style="' + styleMenuLink + '">Add Peer</a> | ' +
'<a href="javascript:clearXdcStorage();" style="' + styleMenuLink + '">Clear Storage</a>' +
'<div>';
document.getElementsByTagName('body')[0].append(div.firstChild);
}
}