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