* Add joining with knock room creation flow. Also add `WaitForInviteView` after knocking. And appropriate error views when knock failed or gets rejected. Signed-off-by: Timo K <toger5@hotmail.de> * Refactor encryption information. We had lots of enums and booleans to describe the encryption situation. Now we only use the `EncryptionSystem` "enum" which contains the additional information like sharedKey. (and we don't use the isRoomE2EE function that is somewhat confusing since it checks `return widget === null && !room.getCanonicalAlias();` which is only indirectly related to e2ee) Signed-off-by: Timo K <toger5@hotmail.de> * Update recent list. - Don't use deprecated `groupCallEventHander` anymore (it used the old `m.call` state event.) - make the recent list reactive (getting removed from a call removes the item from the list) - support having rooms without shared secret but actual matrix encryption in the recent list - change the share link creation button so that we create a link with pwd for sharedKey rooms and with `perParticipantE2EE=true` for matrix encrypted rooms. Signed-off-by: Timo K <toger5@hotmail.de> * fix types Signed-off-by: Timo K <toger5@hotmail.de> * patch js-sdk for linter Signed-off-by: Timo K <toger5@hotmail.de> * ignore ts expect error Signed-off-by: Timo K <toger5@hotmail.de> * Fix error in widget mode. We cannot call client.getRoomSummary in widget mode. The code path needs to throw before reaching this call. (In general we should never call getRoomSummary if getRoom returns a room) Signed-off-by: Timo K <toger5@hotmail.de> * tempDemo Signed-off-by: Timo K <toger5@hotmail.de> * remove wait for invite view Signed-off-by: Timo K <toger5@hotmail.de> * yarn i18n Signed-off-by: Timo K <toger5@hotmail.de> * reset back mute participant count * add logic to show error view when getting removed * include reason whenever someone gets removed from a call. * fix activeRoom not beeing early enough * fix lints * add comment about encryption situation Signed-off-by: Timo K <toger5@hotmail.de> * Fix lockfile * Use (unmerged!) RoomSummary type from the js-sdk Temporarily change the js-sdk dependency to the PR branch that provides that type * review Signed-off-by: Timo K <toger5@hotmail.de> * review (remove participant count unknown) Signed-off-by: Timo K <toger5@hotmail.de> * remove error for unencrypted calls (allow intentional unencrypted calls) Signed-off-by: Timo K <toger5@hotmail.de> * update js-sdk Signed-off-by: Timo K <toger5@hotmail.de> --------- Signed-off-by: Timo K <toger5@hotmail.de> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
104 lines
3.8 KiB
TypeScript
104 lines
3.8 KiB
TypeScript
/*
|
|
Copyright 2023 New Vector Ltd
|
|
|
|
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 { useEffect, useMemo } from "react";
|
|
|
|
import { setLocalStorageItem, useLocalStorage } from "../useLocalStorage";
|
|
import { UrlParams, getUrlParams, useUrlParams } from "../UrlParams";
|
|
import { E2eeType } from "./e2eeType";
|
|
import { useClient } from "../ClientContext";
|
|
|
|
export function saveKeyForRoom(roomId: string, password: string): void {
|
|
setLocalStorageItem(getRoomSharedKeyLocalStorageKey(roomId), password);
|
|
}
|
|
|
|
const getRoomSharedKeyLocalStorageKey = (roomId: string): string =>
|
|
`room-shared-key-${roomId}`;
|
|
|
|
const useInternalRoomSharedKey = (roomId: string): string | null => {
|
|
const key = getRoomSharedKeyLocalStorageKey(roomId);
|
|
const roomSharedKey = useLocalStorage(key)[0];
|
|
|
|
return roomSharedKey;
|
|
};
|
|
|
|
export function getKeyForRoom(roomId: string): string | null {
|
|
saveKeyFromUrlParams(getUrlParams());
|
|
const key = getRoomSharedKeyLocalStorageKey(roomId);
|
|
return localStorage.getItem(key);
|
|
}
|
|
|
|
function saveKeyFromUrlParams(urlParams: UrlParams): void {
|
|
if (!urlParams.password || !urlParams.roomId) return;
|
|
|
|
// Take the key from the URL and save it.
|
|
// It's important to always use the room ID specified in the URL
|
|
// when saving keys rather than whatever the current room ID might be,
|
|
// in case we've moved to a different room but the URL hasn't changed.
|
|
saveKeyForRoom(urlParams.roomId, urlParams.password);
|
|
}
|
|
|
|
/**
|
|
* Extracts the room password from the URL if one is present, saving it in localstorage
|
|
* and returning it in a tuple with the corresponding room ID from the URL.
|
|
* @returns A tuple of the roomId and password from the URL if the URL has both,
|
|
* otherwise [undefined, undefined]
|
|
*/
|
|
const useKeyFromUrl = (): [string, string] | [undefined, undefined] => {
|
|
const urlParams = useUrlParams();
|
|
|
|
useEffect(() => saveKeyFromUrlParams(urlParams), [urlParams]);
|
|
|
|
return urlParams.roomId && urlParams.password
|
|
? [urlParams.roomId, urlParams.password]
|
|
: [undefined, undefined];
|
|
};
|
|
|
|
export type Unencrypted = { kind: E2eeType.NONE };
|
|
export type SharedSecret = { kind: E2eeType.SHARED_KEY; secret: string };
|
|
export type PerParticipantE2EE = { kind: E2eeType.PER_PARTICIPANT };
|
|
export type EncryptionSystem = Unencrypted | SharedSecret | PerParticipantE2EE;
|
|
|
|
export function useRoomEncryptionSystem(roomId: string): EncryptionSystem {
|
|
const { client } = useClient();
|
|
|
|
// make sure we've extracted the key from the URL first
|
|
// (and we still need to take the value it returns because
|
|
// the effect won't run in time for it to save to localstorage in
|
|
// time for us to read it out again).
|
|
const [urlRoomId, passwordFromUrl] = useKeyFromUrl();
|
|
const storedPassword = useInternalRoomSharedKey(roomId);
|
|
const room = client?.getRoom(roomId);
|
|
const e2eeSystem = <EncryptionSystem>useMemo(() => {
|
|
if (!room) return { kind: E2eeType.NONE };
|
|
if (storedPassword)
|
|
return {
|
|
kind: E2eeType.SHARED_KEY,
|
|
secret: storedPassword,
|
|
};
|
|
if (urlRoomId === roomId)
|
|
return {
|
|
kind: E2eeType.SHARED_KEY,
|
|
secret: passwordFromUrl,
|
|
};
|
|
if (room.hasEncryptionStateEvent()) {
|
|
return { kind: E2eeType.PER_PARTICIPANT };
|
|
}
|
|
return { kind: E2eeType.NONE };
|
|
}, [passwordFromUrl, room, roomId, storedPassword, urlRoomId]);
|
|
return e2eeSystem;
|
|
}
|