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";
|
import { Config } from "./config/Config";
|
||||||
|
|
||||||
export const PASSWORD_STRING = "?password=";
|
export const PASSWORD_STRING = "password=";
|
||||||
|
|
||||||
interface UrlParams {
|
interface UrlParams {
|
||||||
roomAlias: string | null;
|
roomAlias: string | null;
|
||||||
@@ -109,17 +109,8 @@ export const getUrlParams = (
|
|||||||
hash = window.location.hash
|
hash = window.location.hash
|
||||||
): UrlParams => {
|
): UrlParams => {
|
||||||
let roomAlias: string | null = null;
|
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 (!ignoreRoomAlias) {
|
||||||
if (hash === "" || hash.startsWith("#" + PASSWORD_STRING)) {
|
if (hash === "" || hash.startsWith("#?")) {
|
||||||
roomAlias = pathname.substring(1); // Strip the "/"
|
roomAlias = pathname.substring(1); // Strip the "/"
|
||||||
|
|
||||||
// Delete "/room/", if present
|
// Delete "/room/", if present
|
||||||
@@ -179,7 +170,7 @@ export const getUrlParams = (
|
|||||||
return {
|
return {
|
||||||
roomAlias,
|
roomAlias,
|
||||||
roomId,
|
roomId,
|
||||||
password,
|
password: getParam("password"),
|
||||||
viaServers: getAllParams("via"),
|
viaServers: getAllParams("via"),
|
||||||
isEmbedded: hasParam("embed"),
|
isEmbedded: hasParam("embed"),
|
||||||
preload: hasParam("preload"),
|
preload: hasParam("preload"),
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ export function getRoomUrl(
|
|||||||
roomIdOrAlias: string,
|
roomIdOrAlias: string,
|
||||||
password: string = ""
|
password: string = ""
|
||||||
): string {
|
): string {
|
||||||
password = password === "" ? "" : "#" + PASSWORD_STRING + password;
|
password = password === "" ? "" : "#?" + PASSWORD_STRING + password;
|
||||||
|
|
||||||
if (roomIdOrAlias.startsWith("#")) {
|
if (roomIdOrAlias.startsWith("#")) {
|
||||||
return `${window.location.protocol}//${window.location.host}/${
|
return `${window.location.protocol}//${window.location.host}/${
|
||||||
|
|||||||
@@ -257,13 +257,15 @@ export function GroupCallView({
|
|||||||
}, [password, e2eeSharedKey, setE2EESharedKey]);
|
}, [password, e2eeSharedKey, setE2EESharedKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const originalHash = location.hash;
|
const hash = location.hash;
|
||||||
const hash = originalHash === "" ? "#" : originalHash;
|
if (!hash.includes("?")) return;
|
||||||
const [hashStart, password] = hash.split(PASSWORD_STRING);
|
|
||||||
|
const [hashStart, passwordStart] = hash.split(PASSWORD_STRING);
|
||||||
|
const [password, hashEnd] = passwordStart ? passwordStart.split("&") : [];
|
||||||
|
|
||||||
if (password !== e2eeSharedKey) return;
|
if (password !== e2eeSharedKey) return;
|
||||||
|
|
||||||
location.replace(hashStart);
|
location.replace((hashStart ?? "") + (hashEnd ?? ""));
|
||||||
}, [password, e2eeSharedKey]);
|
}, [password, e2eeSharedKey]);
|
||||||
|
|
||||||
const e2eeConfig = useMemo(
|
const e2eeConfig = useMemo(
|
||||||
|
|||||||
Reference in New Issue
Block a user