add runnable html and js file to start making things actually run

This commit is contained in:
Bruno Windels 2019-02-04 22:31:08 +00:00
parent 5703a034ca
commit 27b98408f1
2 changed files with 39 additions and 0 deletions

8
src/index.html Normal file
View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<script type="module" src="main.js"></script>
</head>
<body>
</body>
</html>

31
src/main.js Normal file
View File

@ -0,0 +1,31 @@
import Network from "../network.js";
import Session from "../session.js";
const HOMESERVER = "http://localhost:8008";
async function getLoginData(username, password) {
const storedCredentials = localStorage.getItem("morpheus_login");
if (!storedCredentials) {
const api = new Network(HOMESERVER);
loginData = await api.passwordLogin(username, password).response();
localStorage.setItem("morpheus_login", JSON.stringify(loginData));
return loginData;
} else {
return JSON.parse(storedCredentials);
}
}
async function main() {
const loginData = await getLoginData("bruno1", "testtest");
const network = new Network(HOMESERVER, loginData.access_token);
const storage = new IdbStorage("morpheus_session");
const session = new Session(loginData, storage);
await session.load();
const sync = new Sync(network, session, storage);
await sync.start();
sync.on("error", err => {
console.error("sync error", err);
});
}
main().catch(err => console.error(err));