Skip to content
Snippets Groups Projects
Commit a0b98cbb authored by Midhun Suresh's avatar Midhun Suresh
Browse files

Implement interface and refactor code

parent f1981902
No related branches found
No related tags found
No related merge requests found
import { Platform, Client, LoadStatus, createNavigation, createRouter, RoomViewModel, TimelineView, } from "hydrogen-view-sdk";
import assetPaths from "hydrogen-view-sdk/paths/vite";
import "hydrogen-view-sdk/style.css";
import { IMatrixClient } from "./types/IMatrixClient";
export class Hydrogen {
export class Hydrogen implements IMatrixClient {
private readonly _homeserver: string;
private _platform: Record<string, any>;
private _client: Record<string, any>;
private _urlRouter: Record<string, any>;
private _navigation: Record<string, any>;
private _platform: Platform;
private _client: Client;
private _urlRouter: ReturnType<createRouter>;
private _navigation: ReturnType<createNavigation>;
private _container: HTMLDivElement;
constructor(homeserver: string, container: HTMLDivElement) {
......@@ -21,15 +22,14 @@ export class Hydrogen {
this._client = new Client(this._platform);
}
async register(username: string, password: string, initialDeviceDisplayName: string) {
async register(username: string, password: string, initialDeviceDisplayName: string): Promise<void> {
let stage = await this._client.startRegistration(this._homeserver, username, password, initialDeviceDisplayName);
while (stage !== true) {
stage = await stage.complete();
}
return stage;
}
async login(username: string, password: string) {
async login(username: string, password: string): Promise<void> {
const loginOptions = await this._client.queryLogin(this._homeserver).result;
this._client.startWithLogin(loginOptions.password(username, password));
......@@ -46,7 +46,7 @@ export class Hydrogen {
}
}
async showRoom(roomId: string) {
async showRoom(roomId: string): Promise<void> {
const room = this._session.rooms.get(roomId) ?? await this._joinRoom(roomId);
const vm = new RoomViewModel({
room,
......
export interface IMatrixClient {
register(username: string, password: string, initialDeviceDisplayName: string): Promise<void>;
login(username: string, password: string): Promise<void>;
showRoom(roomId: string): Promise<void>;
attemptStartWithExistingSession(): Promise<boolean>;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment