forked from mystiq/hydrogen-web
Compare commits
7 commits
master
...
ts-convers
Author | SHA1 | Date | |
---|---|---|---|
|
e40d74ebce | ||
|
eaa31eb8fb | ||
|
866bef7223 | ||
|
998ad06cd7 | ||
|
e6e20044c8 | ||
|
fe6090183f | ||
|
cf76e9c605 |
4 changed files with 75 additions and 11 deletions
58
src/platform/types/Platform.d.ts
vendored
Normal file
58
src/platform/types/Platform.d.ts
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import type {BaseLogger} from "../../logging/BaseLogger";
|
||||
import type {SettingsStorage} from "../web/dom/SettingsStorage.js";
|
||||
import type {Clock} from "../web/dom/Clock.js";
|
||||
import type {History} from "../web/dom/History.js";
|
||||
import type {OnlineStatus} from "../web/dom/OnlineStatus.js";
|
||||
import type {ServiceWorkerHandler} from "../web/dom/ServiceWorkerHandler.js";
|
||||
import type {Encoding} from "../web/utils/Encoding.js";
|
||||
|
||||
export interface IPlatformConfig {
|
||||
worker: string;
|
||||
downloadSandbox: string;
|
||||
defaultHomeServer: string;
|
||||
serviceWorker?: string;
|
||||
olm: {
|
||||
wasm: string;
|
||||
legacyBundle: string;
|
||||
wasmBundle: string;
|
||||
};
|
||||
push: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPlatformOptions {
|
||||
development?: boolean;
|
||||
}
|
||||
|
||||
export interface CryptoExtras {
|
||||
aesjs?: any;
|
||||
hkdf?: any;
|
||||
}
|
||||
|
||||
export interface IPlatform {
|
||||
readonly logger: BaseLogger;
|
||||
readonly settingsStorage: SettingsStorage;
|
||||
readonly clock: Clock;
|
||||
readonly encoding: Encoding;
|
||||
readonly random: () => number;
|
||||
readonly history: History;
|
||||
readonly onlineStatus: OnlineStatus;
|
||||
readonly updateService?: ServiceWorkerHandler;
|
||||
}
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import aesjs from "../../../lib/aes-js/index.js";
|
||||
import {hkdf} from "../../utils/crypto/hkdf.js";
|
||||
import {Platform as ModernPlatform} from "./Platform.js";
|
||||
import {Platform as ModernPlatform} from "./Platform";
|
||||
|
||||
export function Platform(container, paths) {
|
||||
return new ModernPlatform(container, paths, {aesjs, hkdf});
|
||||
|
|
|
@ -38,6 +38,8 @@ import {downloadInIframe} from "./dom/download.js";
|
|||
import {Disposables} from "../../utils/Disposables.js";
|
||||
import {parseHTML} from "./parsehtml.js";
|
||||
import {handleAvatarError} from "./ui/avatar.js";
|
||||
import {IPlatform, IPlatformConfig, IPlatformOptions} from "../types/Platform";
|
||||
import type {BaseLogger} from "../../logging/BaseLogger.js";
|
||||
|
||||
function addScript(src) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -124,22 +126,26 @@ function adaptUIOnVisualViewportResize(container) {
|
|||
};
|
||||
}
|
||||
|
||||
export class Platform {
|
||||
constructor(container, config, cryptoExtras = null, options = null) {
|
||||
export class Platform implements IPlatform {
|
||||
public readonly logger: BaseLogger;
|
||||
public readonly settingsStorage: SettingsStorage = new SettingsStorage("hydrogen_setting_v1_");
|
||||
public readonly clock: Clock = new Clock();
|
||||
public readonly encoding: Encoding = new Encoding();
|
||||
public readonly random: () => number = Math.random;
|
||||
public readonly history: History = new History();
|
||||
public readonly onlineStatus: OnlineStatus = new OnlineStatus();
|
||||
private readonly _config: IPlatformConfig;
|
||||
private readonly _container: HTMLElement;
|
||||
private readonly _serviceWorkerHandler?: ServiceWorkerHandler;
|
||||
|
||||
constructor(container: HTMLElement, config: IPlatformConfig, cryptoExtras = null, options?: IPlatformOptions) {
|
||||
this._config = config;
|
||||
this._container = container;
|
||||
this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_");
|
||||
this.clock = new Clock();
|
||||
this.encoding = new Encoding();
|
||||
this.random = Math.random;
|
||||
if (options?.development) {
|
||||
this.logger = new ConsoleLogger({platform: this});
|
||||
} else {
|
||||
this.logger = new IDBLogger({name: "hydrogen_logs", platform: this});
|
||||
}
|
||||
this.history = new History();
|
||||
this.onlineStatus = new OnlineStatus();
|
||||
this._serviceWorkerHandler = null;
|
||||
if (config.serviceWorker && "serviceWorker" in navigator) {
|
||||
this._serviceWorkerHandler = new ServiceWorkerHandler();
|
||||
this._serviceWorkerHandler.registerAndStart(config.serviceWorker);
|
|
@ -22,7 +22,7 @@
|
|||
</script>
|
||||
<script id="main" type="module">
|
||||
import {main} from "./src/main.js";
|
||||
import {Platform} from "./src/platform/web/Platform.js";
|
||||
import {Platform} from "./src/platform/web/Platform";
|
||||
main(new Platform(document.body, {
|
||||
worker: "src/worker.js",
|
||||
downloadSandbox: "assets/download-sandbox.html",
|
||||
|
|
Loading…
Reference in a new issue