Improve URL handling
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import { useLocation } from "react-router-dom";
|
||||
|
||||
import { Config } from "./config/Config";
|
||||
|
||||
export const PASSWORD_STRING = "?password=";
|
||||
export const PASSWORD_STRING = "password=";
|
||||
|
||||
interface UrlParams {
|
||||
roomAlias: string | null;
|
||||
@@ -109,17 +109,8 @@ export const getUrlParams = (
|
||||
hash = window.location.hash
|
||||
): UrlParams => {
|
||||
let roomAlias: string | null = null;
|
||||
let password: string | null = null;
|
||||
|
||||
const passwordIndex = hash.indexOf(PASSWORD_STRING);
|
||||
const passwordStart =
|
||||
passwordIndex === -1 ? null : passwordIndex + PASSWORD_STRING.length;
|
||||
if (passwordStart) {
|
||||
password = hash.substring(passwordStart);
|
||||
}
|
||||
|
||||
if (!ignoreRoomAlias) {
|
||||
if (hash === "" || hash.startsWith("#" + PASSWORD_STRING)) {
|
||||
if (hash === "" || hash.startsWith("#?")) {
|
||||
roomAlias = pathname.substring(1); // Strip the "/"
|
||||
|
||||
// Delete "/room/", if present
|
||||
@@ -179,7 +170,7 @@ export const getUrlParams = (
|
||||
return {
|
||||
roomAlias,
|
||||
roomId,
|
||||
password,
|
||||
password: getParam("password"),
|
||||
viaServers: getAllParams("via"),
|
||||
isEmbedded: hasParam("embed"),
|
||||
preload: hasParam("preload"),
|
||||
|
||||
@@ -347,7 +347,7 @@ export function getRoomUrl(
|
||||
roomIdOrAlias: string,
|
||||
password: string = ""
|
||||
): string {
|
||||
password = password === "" ? "" : "#" + PASSWORD_STRING + password;
|
||||
password = password === "" ? "" : "#?" + PASSWORD_STRING + password;
|
||||
|
||||
if (roomIdOrAlias.startsWith("#")) {
|
||||
return `${window.location.protocol}//${window.location.host}/${
|
||||
|
||||
@@ -257,13 +257,15 @@ export function GroupCallView({
|
||||
}, [password, e2eeSharedKey, setE2EESharedKey]);
|
||||
|
||||
useEffect(() => {
|
||||
const originalHash = location.hash;
|
||||
const hash = originalHash === "" ? "#" : originalHash;
|
||||
const [hashStart, password] = hash.split(PASSWORD_STRING);
|
||||
const hash = location.hash;
|
||||
if (!hash.includes("?")) return;
|
||||
|
||||
const [hashStart, passwordStart] = hash.split(PASSWORD_STRING);
|
||||
const [password, hashEnd] = passwordStart ? passwordStart.split("&") : [];
|
||||
|
||||
if (password !== e2eeSharedKey) return;
|
||||
|
||||
location.replace(hashStart);
|
||||
location.replace((hashStart ?? "") + (hashEnd ?? ""));
|
||||
}, [password, e2eeSharedKey]);
|
||||
|
||||
const e2eeConfig = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user