mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
add runnable html and js file to start making things actually run
This commit is contained in:
parent
5703a034ca
commit
27b98408f1
8
src/index.html
Normal file
8
src/index.html
Normal 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
31
src/main.js
Normal 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));
|
Loading…
Reference in New Issue
Block a user