Skip to content

Commit

Permalink
Merge pull request #214 from Automattic/same-session-in-multiple-tabs
Browse files Browse the repository at this point in the history
Allow multiple Chatrix blocks on the same page or on different browser tabs
  • Loading branch information
psrpinto committed Apr 14, 2023
2 parents 855b904 + 6380a7d commit 689c324
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 127 deletions.
2 changes: 1 addition & 1 deletion frontend/iframe/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import olmJsPath from "@matrix-org/olm/olm.js?url";
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
import olmLegacyJsPath from "@matrix-org/olm/olm_legacy.js?url";
import downloadSandboxPath from "hydrogen-web/src/platform/web/assets/download-sandbox.html?url";
import workerPath from "hydrogen-web/src/platform/web/worker/main.js?url";
import workerPath from "hydrogen-web/src/platform/workers/olm/main.js?url";

const paths = {
downloadSandbox: downloadSandboxPath,
Expand Down
2 changes: 1 addition & 1 deletion frontend/iframe/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseUrlPath, stringifyPath } from "hydrogen-web/src/domain/navigation";
import { FeatureSet } from "hydrogen-web/src/features";
import { NullLogger } from "hydrogen-web/src/logging/NullLogger";
import assetPaths from "./assets";
import { ConfigFactory } from "./config/ConfigFactory";
Expand All @@ -7,7 +8,6 @@ import { Platform } from "./platform/Platform";
import { URLRouter } from "./platform/URLRouter";
import { RootViewModel } from "./viewmodels/RootViewModel";
import { RootView } from "./views/RootView";
import {FeatureSet} from "hydrogen-web/src/features";

export class Main {
private readonly _platform: Platform;
Expand Down
5 changes: 1 addition & 4 deletions frontend/iframe/platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { IConfig } from "../config/IConfig";
import { History } from "./History";
import { Navigation } from "./Navigation";
import { ServiceWorkerHandler } from "./ServiceWorkerHandler";
import { StorageFactory } from "./StorageFactory";

export class Platform extends BasePlatform {
constructor(options) {
Expand All @@ -23,9 +22,7 @@ export class Platform extends BasePlatform {
serviceWorkerHandler.registerAndStart(assetPaths.serviceWorker);
}

super.storageFactory = new StorageFactory(serviceWorkerHandler);
super._serviceWorkerHandler = serviceWorkerHandler;

super.settingsStorage = new SettingsStorage("chatrix_setting_v1_");
super.sessionInfoStorage = new SessionInfoStorage("chatrix_sessions_v1");
super.history = new History();
Expand All @@ -44,7 +41,7 @@ export class Platform extends BasePlatform {
}

async init() {
super.init();
return super.init();
}

get config(): IConfig {
Expand Down
112 changes: 0 additions & 112 deletions frontend/iframe/platform/StorageFactory.ts

This file was deleted.

10 changes: 5 additions & 5 deletions frontend/iframe/viewmodels/RootViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { ForcedLogoutViewModel } from "hydrogen-web/src/domain/ForcedLogoutViewM
import { LoginViewModel } from "hydrogen-web/src/domain/login/LoginViewModel";
import { LogoutViewModel } from "hydrogen-web/src/domain/LogoutViewModel";
import { SegmentType } from "hydrogen-web/src/domain/navigation";
import { UnknownRoomViewModel } from "hydrogen-web/src/domain/session/room/UnknownRoomViewModel";
import { SessionLoadViewModel } from "hydrogen-web/src/domain/SessionLoadViewModel";
import { SessionPickerViewModel } from "hydrogen-web/src/domain/SessionPickerViewModel";
import { UnknownRoomViewModel } from "hydrogen-web/src/domain/session/room/UnknownRoomViewModel";
import { Options as BaseOptions, ViewModel } from "hydrogen-web/src/domain/ViewModel";
import { Client } from "hydrogen-web/src/matrix/Client.js";
import { HomeServerApi } from "hydrogen-web/src/matrix/net/HomeServerApi";
import { allSections, Section } from "../platform/Navigation";
import { lookupHomeserver } from "hydrogen-web/src/matrix/well-known";
import { allSections, Section } from "../platform/Navigation";
import { Platform } from "../platform/Platform";
import { SessionViewModel } from "./SessionViewModel";

Expand Down Expand Up @@ -153,7 +153,7 @@ export class RootViewModel extends ViewModel<SegmentType, Options> {
this._pendingClient.dispose();
this._pendingClient = null;
}
this._showSessionLoader(sessionId);
await this._showSessionLoader(sessionId);
}
}
} else if (loginToken) {
Expand Down Expand Up @@ -282,9 +282,9 @@ export class RootViewModel extends ViewModel<SegmentType, Options> {
}
}

private _showSessionLoader(sessionId: string) {
private async _showSessionLoader(sessionId: string) {
const client = new Client(this.platform, this.features);
client.startWithExistingSession(sessionId);
await client.startWithExistingSession(sessionId);

this._setSection(() => {
this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineConfig(({mode}) => {
},
target: "esnext",
assetsInlineLimit: 0,
manifest: true,
manifest: false,
emptyOutDir: true,
},
css: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@wordpress/compose": "^5.17.0",
"bs58": "^5.0.0",
"hydrogen-web": "Automattic/hydrogen-web#chatrix-0.7.1",
"hydrogen-web": "Automattic/hydrogen-web#chatrix-0.8.0",
"node-html-parser": "^4.0.0"
},
"resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5720,9 +5720,9 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

hydrogen-web@Automattic/hydrogen-web#chatrix-0.7.1:
hydrogen-web@Automattic/hydrogen-web#chatrix-0.8.0:
version "0.3.8"
resolved "https://codeload.github.com/Automattic/hydrogen-web/tar.gz/061341d494e0f29bf22b988ff4b1d089be1e76b7"
resolved "https://codeload.github.com/Automattic/hydrogen-web/tar.gz/ded5651568465c594ada43fa2c75051073e45fa2"
dependencies:
"@matrix-org/olm" "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz"
another-json "^0.2.0"
Expand Down

0 comments on commit 689c324

Please sign in to comment.