mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 15:45:23 +00:00
fix(session-sharing): use the linked server for desktop meetings and links (#1507)
This commit is contained in:
1 parent
9801cc7fc7
commit
ec7c2c2835
15 files changed
+621
-210
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import type { TermixApp } from "@termix/plugin-sdk/frontend";
|
||||
import { createMeetingApi } from "./meeting-api";
|
||||
|
||||
export type MeetingBackend = Awaited<ReturnType<typeof connectMeetings>>;
|
||||
|
||||
/** A room, its hosts and its sockets must all belong to the same backend. */
|
||||
export async function connectMeetings(app: TermixApp) {
|
||||
const remoteUrl = app.desktop.available
|
||||
? await app.desktop.remoteServerUrl()
|
||||
: null;
|
||||
const key = remoteUrl?.replace(/\/+$/, "") || "local";
|
||||
const origin = remoteUrl ? ("remote" as const) : ("local" as const);
|
||||
const publicUrl =
|
||||
remoteUrl || (!app.desktop.available ? window.location.href : null);
|
||||
const assertCurrent = async () => {
|
||||
const current = app.desktop.available
|
||||
? await app.desktop.remoteServerUrl()
|
||||
: null;
|
||||
if ((current?.replace(/\/+$/, "") || "local") !== key) {
|
||||
throw new Error(app.t("collab.serverChanged"));
|
||||
}
|
||||
};
|
||||
return {
|
||||
key,
|
||||
origin,
|
||||
publicUrl,
|
||||
assertCurrent,
|
||||
api: createMeetingApi(app.apiFor(origin), assertCurrent),
|
||||
};
|
||||
}
|
||||
|
||||
export function meetingGuestUrl(
|
||||
publicUrl: string | null,
|
||||
token: string,
|
||||
): string | null {
|
||||
if (!publicUrl) return null;
|
||||
const url = new URL(publicUrl);
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
||||
url.search = "";
|
||||
url.hash = "";
|
||||
url.searchParams.set("view", "collab-guest");
|
||||
url.searchParams.set("token", token);
|
||||
return url.toString();
|
||||
}
|
||||
Reference in new issue
Block a user