vector-im-hydrogen-web/src/main.js

36 lines
1.5 KiB
JavaScript
Raw Normal View History

import HomeServerApi from "./matrix/hs-api.js";
// import {RecordRequester, ReplayRequester} from "./matrix/net/replay.js";
2019-12-23 14:28:27 +01:00
import fetchRequest from "./matrix/net/fetch.js";
2019-10-12 21:16:48 +02:00
import StorageFactory from "./matrix/storage/idb/create.js";
2019-07-31 00:07:04 +02:00
import SessionsStore from "./matrix/sessions-store/localstorage/SessionsStore.js";
import BrawlViewModel from "./domain/BrawlViewModel.js";
import BrawlView from "./ui/web/BrawlView.js";
2019-02-26 22:45:58 +01:00
export default async function main(container) {
2019-06-26 22:31:36 +02:00
try {
// to replay:
// const fetchLog = await (await fetch("/fetchlogs/constrainterror.json")).json();
// const replay = new ReplayRequester(fetchLog, {delay: false});
// const request = replay.request;
// to record:
// const recorder = new RecordRequester(fetchRequest);
// const request = recorder.request;
// window.getBrawlFetchLog = () => recorder.log();
// normal network:
2019-12-23 14:28:27 +01:00
const request = fetchRequest;
2019-07-31 00:07:04 +02:00
const vm = new BrawlViewModel({
2019-10-12 21:16:48 +02:00
storageFactory: new StorageFactory(),
2019-12-23 14:28:27 +01:00
createHsApi: (homeServer, accessToken = null) => new HomeServerApi({homeServer, accessToken, request}),
sessionStore: new SessionsStore("brawl_sessions_v1"),
2019-07-31 00:07:04 +02:00
clock: Date //just for `now` fn
});
await vm.load();
const view = new BrawlView(vm);
container.appendChild(view.mount());
2019-06-26 22:31:36 +02:00
} catch(err) {
2019-06-02 14:59:30 +02:00
console.error(`${err.message}:\n${err.stack}`);
2019-06-26 22:31:36 +02:00
}
}