From 27b98408f11beb8291fc678f1d4e176bfd9a1fd9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 4 Feb 2019 22:31:08 +0000 Subject: [PATCH] add runnable html and js file to start making things actually run --- src/index.html | 8 ++++++++ src/main.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/index.html create mode 100644 src/main.js diff --git a/src/index.html b/src/index.html new file mode 100644 index 00000000..fe5dda16 --- /dev/null +++ b/src/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 00000000..01760ab7 --- /dev/null +++ b/src/main.js @@ -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)); \ No newline at end of file