forked from mystiq/hydrogen-web
rename Network to HomeServerApi
This commit is contained in:
parent
3f776129f5
commit
6c7474e95e
3 changed files with 11 additions and 11 deletions
|
@ -13,7 +13,7 @@ class RequestWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Network {
|
export default class HomeServerApi {
|
||||||
constructor(homeserver, accessToken) {
|
constructor(homeserver, accessToken) {
|
||||||
this._homeserver = homeserver;
|
this._homeserver = homeserver;
|
||||||
this._accessToken = accessToken;
|
this._accessToken = accessToken;
|
12
src/main.js
12
src/main.js
|
@ -1,4 +1,4 @@
|
||||||
import Network from "./network.js";
|
import HomeServerApi from "./hs-api.js";
|
||||||
import Session from "./session.js";
|
import Session from "./session.js";
|
||||||
import createIdbStorage from "./storage/idb/create.js";
|
import createIdbStorage from "./storage/idb/create.js";
|
||||||
const HOMESERVER = "http://localhost:8008";
|
const HOMESERVER = "http://localhost:8008";
|
||||||
|
@ -15,8 +15,8 @@ function getSessionId(userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(username, password, homeserver) {
|
async function login(username, password, homeserver) {
|
||||||
const api = new Network(homeserver);
|
const hsApi = new HomeServerApi(homeserver);
|
||||||
const loginData = await api.passwordLogin(username, password).response();
|
const loginData = await hsApi.passwordLogin(username, password).response();
|
||||||
const sessionsJson = localStorage.getItem("morpheus_sessions_v1");
|
const sessionsJson = localStorage.getItem("morpheus_sessions_v1");
|
||||||
const sessions = sessionsJson ? JSON.parse(sessionsJson) : [];
|
const sessions = sessionsJson ? JSON.parse(sessionsJson) : [];
|
||||||
const sessionId = (Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)).toString();
|
const sessionId = (Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)).toString();
|
||||||
|
@ -39,10 +39,10 @@ async function main() {
|
||||||
await session.setLoginData(loginData);
|
await session.setLoginData(loginData);
|
||||||
}
|
}
|
||||||
await session.load();
|
await session.load();
|
||||||
console.log("session loaded", session);
|
const hsApi = new HomeServerApi(HOMESERVER, session.accessToken);
|
||||||
|
console.log("session loaded", session, hsApi);
|
||||||
return;
|
return;
|
||||||
const network = new Network(HOMESERVER, session.accessToken);
|
const sync = new Sync(hsApi, session, storage);
|
||||||
const sync = new Sync(network, session, storage);
|
|
||||||
await sync.start();
|
await sync.start();
|
||||||
|
|
||||||
sync.on("error", err => {
|
sync.on("error", err => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {RequestAbortError} from "./network.js";
|
import {RequestAbortError} from "./hs-api.js";
|
||||||
import {HomeServerError, StorageError} from "./error.js";
|
import {HomeServerError, StorageError} from "./error.js";
|
||||||
|
|
||||||
const INCREMENTAL_TIMEOUT = 30;
|
const INCREMENTAL_TIMEOUT = 30;
|
||||||
|
@ -15,8 +15,8 @@ function parseRooms(responseSections, roomMapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Sync {
|
export class Sync {
|
||||||
constructor(network, session, storage) {
|
constructor(hsApi, session, storage) {
|
||||||
this._network = network;
|
this._hsApi = hsApi;
|
||||||
this._session = session;
|
this._session = session;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
this._isSyncing = false;
|
this._isSyncing = false;
|
||||||
|
@ -48,7 +48,7 @@ export class Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _syncRequest(timeout, syncToken) {
|
async _syncRequest(timeout, syncToken) {
|
||||||
this._currentRequest = this._network.sync(timeout, syncToken);
|
this._currentRequest = this._hsApi.sync(timeout, syncToken);
|
||||||
const response = await this._currentRequest.response;
|
const response = await this._currentRequest.response;
|
||||||
syncToken = response.next_batch;
|
syncToken = response.next_batch;
|
||||||
const storeNames = this._storage.storeNames;
|
const storeNames = this._storage.storeNames;
|
||||||
|
|
Loading…
Reference in a new issue