mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 11:36:24 +01:00
rename Network to HomeServerApi
This commit is contained in:
parent
3f776129f5
commit
6c7474e95e
@ -13,7 +13,7 @@ class RequestWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
export default class Network {
|
||||
export default class HomeServerApi {
|
||||
constructor(homeserver, accessToken) {
|
||||
this._homeserver = homeserver;
|
||||
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 createIdbStorage from "./storage/idb/create.js";
|
||||
const HOMESERVER = "http://localhost:8008";
|
||||
@ -15,8 +15,8 @@ function getSessionId(userId) {
|
||||
}
|
||||
|
||||
async function login(username, password, homeserver) {
|
||||
const api = new Network(homeserver);
|
||||
const loginData = await api.passwordLogin(username, password).response();
|
||||
const hsApi = new HomeServerApi(homeserver);
|
||||
const loginData = await hsApi.passwordLogin(username, password).response();
|
||||
const sessionsJson = localStorage.getItem("morpheus_sessions_v1");
|
||||
const sessions = sessionsJson ? JSON.parse(sessionsJson) : [];
|
||||
const sessionId = (Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)).toString();
|
||||
@ -39,10 +39,10 @@ async function main() {
|
||||
await session.setLoginData(loginData);
|
||||
}
|
||||
await session.load();
|
||||
console.log("session loaded", session);
|
||||
const hsApi = new HomeServerApi(HOMESERVER, session.accessToken);
|
||||
console.log("session loaded", session, hsApi);
|
||||
return;
|
||||
const network = new Network(HOMESERVER, session.accessToken);
|
||||
const sync = new Sync(network, session, storage);
|
||||
const sync = new Sync(hsApi, session, storage);
|
||||
await sync.start();
|
||||
|
||||
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";
|
||||
|
||||
const INCREMENTAL_TIMEOUT = 30;
|
||||
@ -15,8 +15,8 @@ function parseRooms(responseSections, roomMapper) {
|
||||
}
|
||||
|
||||
export class Sync {
|
||||
constructor(network, session, storage) {
|
||||
this._network = network;
|
||||
constructor(hsApi, session, storage) {
|
||||
this._hsApi = hsApi;
|
||||
this._session = session;
|
||||
this._storage = storage;
|
||||
this._isSyncing = false;
|
||||
@ -48,7 +48,7 @@ export class Sync {
|
||||
}
|
||||
|
||||
async _syncRequest(timeout, syncToken) {
|
||||
this._currentRequest = this._network.sync(timeout, syncToken);
|
||||
this._currentRequest = this._hsApi.sync(timeout, syncToken);
|
||||
const response = await this._currentRequest.response;
|
||||
syncToken = response.next_batch;
|
||||
const storeNames = this._storage.storeNames;
|
||||
|
Loading…
Reference in New Issue
Block a user