Merge pull request #1 from adbenitez/master
set unique selfAddr per device/window and use that data in the exampl…
This commit is contained in:
commit
3d70e6f05b
16
deltachat.js
16
deltachat.js
|
@ -5,7 +5,7 @@ window.deltachat = (() => {
|
||||||
var updateListener = () => {};
|
var updateListener = () => {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selfAddr: () => "foo@bar.dex",
|
selfAddr: () => window.xdcSelfAddr || "device0@local.host",
|
||||||
setUpdateListener: (cb) => (window.xdcUpdateListener = cb),
|
setUpdateListener: (cb) => (window.xdcUpdateListener = cb),
|
||||||
getAllUpdates: () => {
|
getAllUpdates: () => {
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
|
@ -47,10 +47,19 @@ function addPeer() {
|
||||||
var xdcChild = window.open(window.location);
|
var xdcChild = window.open(window.location);
|
||||||
var xdcRoot = getXdcRoot();
|
var xdcRoot = getXdcRoot();
|
||||||
xdcChild.xdcRoot = xdcRoot;
|
xdcChild.xdcRoot = xdcRoot;
|
||||||
|
xdcChild.xdcSelfAddr = "device" + xdcRoot.allXdcWindows.length + "@local.host";
|
||||||
xdcRoot.allXdcWindows.push(xdcChild);
|
xdcRoot.allXdcWindows.push(xdcChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
function alterBody() {
|
function alterApp() {
|
||||||
|
var title = document.getElementsByTagName('title')[0];
|
||||||
|
if (typeof title == 'undefined') {
|
||||||
|
title = document.createElement('title');
|
||||||
|
document.getElementsByTagName('head')[0].append(title);
|
||||||
|
}
|
||||||
|
title.innerText = window.deltachat.selfAddr();
|
||||||
|
|
||||||
|
if (getXdcRoot() == window) {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
div.innerHTML =
|
div.innerHTML =
|
||||||
'<div style="' + styleControlPanel + '">' +
|
'<div style="' + styleControlPanel + '">' +
|
||||||
|
@ -58,5 +67,6 @@ function alterBody() {
|
||||||
'<div>';
|
'<div>';
|
||||||
document.getElementsByTagName('body')[0].append(div.firstChild);
|
document.getElementsByTagName('body')[0].append(div.firstChild);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener("load", alterBody);
|
window.addEventListener("load", alterApp);
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
|
|
||||||
function sendMsg() {
|
function sendMsg() {
|
||||||
msg = document.getElementById("input").value;
|
msg = document.getElementById("input").value;
|
||||||
window.deltachat.sendUpdate('someone typed "'+msg+'"', msg);
|
window.deltachat.sendUpdate('someone typed "'+msg+'"', {"addr": window.deltachat.selfAddr(), "msg": msg});
|
||||||
}
|
}
|
||||||
|
|
||||||
function receiveUpdate(update) {
|
function receiveUpdate(update) {
|
||||||
document.getElementById('output').innerHTML += update.payload + "<br>";
|
document.getElementById('output').innerHTML += "<strong><" + update.payload.addr + "></strong> " + update.payload.msg + "<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
window.deltachat.setUpdateListener(receiveUpdate);
|
window.deltachat.setUpdateListener(receiveUpdate);
|
||||||
|
|
Loading…
Reference in a new issue