init
This commit is contained in:
commit
2a8232a78a
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# w30 development tool
|
||||
|
||||
this is a little tool to make development of w30 apps easier.
|
||||
|
||||
for developing w30 apps,
|
||||
just copy the `deltachat.js` from this repo beside
|
||||
your `index.html` and you are ready to go.
|
||||
|
||||
no server or installation required.
|
||||
|
||||
- include your `deltachat.js` to your `index.html` as usual
|
||||
- open your `index.html` from your local disk in your browser,
|
||||
tested with Firefox.
|
||||
- the emulation layer will add an "add peer" button,
|
||||
open as many peers as you like
|
||||
- once you call sendUpdate() in on peer,
|
||||
all peers will get the update with their update listeners.
|
||||
|
||||
keep in mind, when bundling your w30 app, deltachat.js is not needed,
|
||||
it will be provided by the target implementation.
|
||||
|
||||
note, that the api is not yet complete,
|
||||
this is just a, maybe already useful, proof-of-concept for now.
|
||||
|
||||
|
62
deltachat.js
Normal file
62
deltachat.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
// debug friend: document.writeln(JSON.stringify(value));
|
||||
// maybe helpful: window.sessionStorage, https://www.w3schools.com/html/html5_webstorage.asp
|
||||
|
||||
window.deltachat = (() => {
|
||||
var updateListener = () => {};
|
||||
|
||||
return {
|
||||
selfAddr: () => "foo@bar.dex",
|
||||
setUpdateListener: (cb) => (window.xdcUpdateListener = cb),
|
||||
getAllUpdates: () => {
|
||||
return JSON.parse(
|
||||
'[]'
|
||||
//'[{"action":"configure", "question":"your favorite colorxx", "answers":["red","green","blue","yellow","purple1"]},{"action":"vote", "sender":"foo2@bar.de", "vote":0},{"action":"vote", "sender":"foo@bar.de", "vote":0}]'
|
||||
);
|
||||
},
|
||||
sendUpdate: (description, payload) => {
|
||||
// alert(description+"\n\n"+JSON.stringify(payload));
|
||||
var all = getAllXdcWindows();
|
||||
all.forEach((w) => {
|
||||
//alert(w.xdcUpdateListener);
|
||||
w.xdcUpdateListener({payload: payload});
|
||||
});
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
window.allXdcWindows = [window];
|
||||
window.xdcUpdateListener = 12;
|
||||
|
||||
var styleControlPanel = 'position: fixed; bottom:1em; left:1em; background-color: #000; opacity:0.8; padding:.5em; font-family: sans-serif; width: 50%;';
|
||||
var styleMenuLink = 'color:#fff; text-decoration: none;';
|
||||
|
||||
function getXdcRoot() {
|
||||
var test = window;
|
||||
while (typeof test.xdcRoot != 'undefined') {
|
||||
test = test.xdcRoot;
|
||||
}
|
||||
return test;
|
||||
}
|
||||
|
||||
function getAllXdcWindows() {
|
||||
var xdcRoot = getXdcRoot();
|
||||
return xdcRoot.allXdcWindows;
|
||||
}
|
||||
|
||||
function addPeer() {
|
||||
var xdcChild = window.open(window.location);
|
||||
var xdcRoot = getXdcRoot();
|
||||
xdcChild.xdcRoot = xdcRoot;
|
||||
xdcRoot.allXdcWindows.push(xdcChild);
|
||||
}
|
||||
|
||||
function alterBody() {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML =
|
||||
'<div style="' + styleControlPanel + '">' +
|
||||
'<a href="javascript:addPeer();" style="' + styleMenuLink + '">Add Peer</a>' +
|
||||
'<div>';
|
||||
document.getElementsByTagName('body')[0].append(div.firstChild);
|
||||
}
|
||||
|
||||
window.addEventListener("load", alterBody);
|
26
index.html
Normal file
26
index.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="deltachat.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<input id="input" type="text"/>
|
||||
<a href="" onclick="sendMsg(); return false;">Send</a>
|
||||
<p id="output"></p>
|
||||
<script>
|
||||
|
||||
function sendMsg() {
|
||||
msg = document.getElementById("input").value;
|
||||
window.deltachat.sendUpdate('someone typed "'+msg+'"', msg);
|
||||
}
|
||||
|
||||
function receiveUpdate(update) {
|
||||
document.getElementById('output').innerHTML += update.payload + "<br>";
|
||||
}
|
||||
|
||||
window.deltachat.setUpdateListener(receiveUpdate);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue