Files
element-call/src/settings/submit-rageshake.ts

349 lines
10 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022 New Vector Ltd
2022-05-04 17:09:48 +01:00
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 { ComponentProps, useCallback, useEffect, useState } from "react";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2022-04-07 14:22:36 -07:00
import pako from "pako";
2022-08-12 16:46:53 -04:00
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
2022-06-06 22:42:48 +02:00
import { getLogsForReport } from "./rageshake";
2022-04-07 14:22:36 -07:00
import { useClient } from "../ClientContext";
import { Config } from "../config/Config";
import { ElementCallOpenTelemetry } from "../otel/otel";
import { RageshakeRequestModal } from "../room/RageshakeRequestModal";
const gzip = (text: string): Blob => {
// encode as UTF-8
const buf = new TextEncoder().encode(text);
// compress
return new Blob([pako.gzip(buf)]);
};
2022-04-07 14:22:36 -07:00
2022-06-06 22:42:48 +02:00
interface RageShakeSubmitOptions {
sendLogs: boolean;
rageshakeRequestId?: string;
2022-08-02 00:46:16 +02:00
description?: string;
roomId?: string;
label?: string;
2022-06-06 22:42:48 +02:00
}
export function useSubmitRageshake(): {
submitRageshake: (opts: RageShakeSubmitOptions) => Promise<void>;
sending: boolean;
sent: boolean;
error?: Error;
2022-06-06 22:42:48 +02:00
} {
const { client } = useClient();
const [{ sending, sent, error }, setState] = useState<{
sending: boolean;
sent: boolean;
error?: Error;
}>({
2022-04-07 14:22:36 -07:00
sending: false,
sent: false,
error: undefined,
2022-04-07 14:22:36 -07:00
});
const submitRageshake = useCallback(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2022-04-07 14:22:36 -07:00
async (opts) => {
if (!Config.get().rageshake?.submit_url) {
throw new Error("No rageshake URL is configured");
}
2022-04-07 14:22:36 -07:00
if (sending) {
return;
}
try {
setState({ sending: true, sent: false, error: undefined });
2022-04-07 14:22:36 -07:00
let userAgent = "UNKNOWN";
if (window.navigator && window.navigator.userAgent) {
userAgent = window.navigator.userAgent;
}
let touchInput = "UNKNOWN";
try {
// MDN claims broad support across browsers
touchInput = String(window.matchMedia("(pointer: coarse)").matches);
} catch (e) {}
let description = opts.rageshakeRequestId
? `Rageshake ${opts.rageshakeRequestId}`
: "";
if (opts.description) description += `: ${opts.description}`;
2022-04-07 14:22:36 -07:00
const body = new FormData();
body.append(
"text",
2023-10-11 10:42:04 -04:00
description ?? "User did not supply any additional text.",
2022-04-07 14:22:36 -07:00
);
body.append("app", "matrix-video-chat");
2022-06-06 22:42:48 +02:00
body.append(
"version",
2023-10-11 10:42:04 -04:00
(import.meta.env.VITE_APP_VERSION as string) || "dev",
2022-06-06 22:42:48 +02:00
);
2022-04-07 14:22:36 -07:00
body.append("user_agent", userAgent);
2022-06-06 22:42:48 +02:00
body.append("installed_pwa", "false");
2022-04-07 14:22:36 -07:00
body.append("touch_input", touchInput);
body.append("call_backend", "livekit");
2022-04-07 14:22:36 -07:00
if (client) {
const userId = client.getUserId()!;
2022-04-07 14:22:36 -07:00
const user = client.getUser(userId);
body.append("display_name", user?.displayName ?? "");
body.append("user_id", client.credentials.userId ?? "");
body.append("device_id", client.deviceId ?? "");
2022-04-07 14:22:36 -07:00
if (opts.roomId) {
body.append("room_id", opts.roomId);
}
if (client.isCryptoEnabled()) {
const keys = [`ed25519:${client.getDeviceEd25519Key()}`];
if (client.getDeviceCurve25519Key) {
keys.push(`curve25519:${client.getDeviceCurve25519Key()}`);
}
body.append("device_keys", keys.join(", "));
body.append("cross_signing_key", client.getCrossSigningId()!);
2022-04-07 14:22:36 -07:00
// add cross-signing status information
const crossSigning = client.crypto!.crossSigningInfo;
const secretStorage = client.crypto!.secretStorage;
2022-04-07 14:22:36 -07:00
body.append(
"cross_signing_ready",
2023-10-11 10:42:04 -04:00
String(await client.isCrossSigningReady()),
2022-04-07 14:22:36 -07:00
);
body.append(
"cross_signing_supported_by_hs",
String(
await client.doesServerSupportUnstableFeature(
2023-10-11 10:42:04 -04:00
"org.matrix.e2e_cross_signing",
),
),
2022-04-07 14:22:36 -07:00
);
body.append("cross_signing_key", crossSigning.getId()!);
2022-04-07 14:22:36 -07:00
body.append(
"cross_signing_privkey_in_secret_storage",
String(
2023-10-11 10:42:04 -04:00
!!(await crossSigning.isStoredInSecretStorage(secretStorage)),
),
2022-04-07 14:22:36 -07:00
);
const pkCache = client.getCrossSigningCacheCallbacks();
body.append(
"cross_signing_master_privkey_cached",
String(
!!(
pkCache?.getCrossSigningKeyCache &&
(await pkCache.getCrossSigningKeyCache("master"))
2023-10-11 10:42:04 -04:00
),
),
2022-04-07 14:22:36 -07:00
);
body.append(
"cross_signing_self_signing_privkey_cached",
String(
!!(
pkCache?.getCrossSigningKeyCache &&
2022-04-07 14:22:36 -07:00
(await pkCache.getCrossSigningKeyCache("self_signing"))
2023-10-11 10:42:04 -04:00
),
),
2022-04-07 14:22:36 -07:00
);
body.append(
"cross_signing_user_signing_privkey_cached",
String(
!!(
pkCache?.getCrossSigningKeyCache &&
2022-04-07 14:22:36 -07:00
(await pkCache.getCrossSigningKeyCache("user_signing"))
2023-10-11 10:42:04 -04:00
),
),
2022-04-07 14:22:36 -07:00
);
body.append(
"secret_storage_ready",
2023-10-11 10:42:04 -04:00
String(await client.isSecretStorageReady()),
2022-04-07 14:22:36 -07:00
);
body.append(
"secret_storage_key_in_account",
2023-10-11 10:42:04 -04:00
String(!!(await secretStorage.hasKey())),
2022-04-07 14:22:36 -07:00
);
body.append(
"session_backup_key_in_secret_storage",
2023-10-11 10:42:04 -04:00
String(!!(await client.isKeyBackupKeyStored())),
2022-04-07 14:22:36 -07:00
);
const sessionBackupKeyFromCache =
await client.crypto!.getSessionBackupPrivateKey();
2022-04-07 14:22:36 -07:00
body.append(
"session_backup_key_cached",
2023-10-11 10:42:04 -04:00
String(!!sessionBackupKeyFromCache),
2022-04-07 14:22:36 -07:00
);
body.append(
"session_backup_key_well_formed",
2023-10-11 10:42:04 -04:00
String(sessionBackupKeyFromCache instanceof Uint8Array),
2022-04-07 14:22:36 -07:00
);
}
}
if (opts.label) {
body.append("label", opts.label);
}
// add storage persistence/quota information
if (navigator.storage && navigator.storage.persisted) {
try {
body.append(
"storageManager_persisted",
2023-10-11 10:42:04 -04:00
String(await navigator.storage.persisted()),
2022-04-07 14:22:36 -07:00
);
} catch (e) {}
} else if (document.hasStorageAccess) {
// Safari
try {
body.append(
"storageManager_persisted",
2023-10-11 10:42:04 -04:00
String(await document.hasStorageAccess()),
2022-04-07 14:22:36 -07:00
);
} catch (e) {}
}
if (navigator.storage && navigator.storage.estimate) {
try {
2022-06-06 22:42:48 +02:00
const estimate: {
quota?: number;
usage?: number;
usageDetails?: { [x: string]: unknown };
} = await navigator.storage.estimate();
2022-04-07 14:22:36 -07:00
body.append("storageManager_quota", String(estimate.quota));
body.append("storageManager_usage", String(estimate.usage));
if (estimate.usageDetails) {
Object.keys(estimate.usageDetails).forEach((k) => {
body.append(
`storageManager_usage_${k}`,
2023-10-11 10:42:04 -04:00
String(estimate.usageDetails![k]),
2022-04-07 14:22:36 -07:00
);
});
}
} catch (e) {}
}
if (opts.sendLogs) {
const logs = await getLogsForReport();
for (const entry of logs) {
body.append("compressed-log", gzip(entry.lines), entry.id);
2022-04-07 14:22:36 -07:00
}
body.append(
"file",
gzip(ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump()),
2023-10-11 10:42:04 -04:00
"traces.json.gz",
);
2022-04-07 14:22:36 -07:00
}
if (opts.rageshakeRequestId) {
body.append(
"group_call_rageshake_request_id",
2023-10-11 10:42:04 -04:00
opts.rageshakeRequestId,
2022-04-07 14:22:36 -07:00
);
}
await fetch(Config.get().rageshake!.submit_url, {
method: "POST",
body,
});
2022-04-07 14:22:36 -07:00
setState({ sending: false, sent: true, error: undefined });
2022-04-07 14:22:36 -07:00
} catch (error) {
setState({ sending: false, sent: false, error: error as Error });
logger.error(error);
2022-04-07 14:22:36 -07:00
}
},
2023-10-11 10:42:04 -04:00
[client, sending],
2022-04-07 14:22:36 -07:00
);
return {
submitRageshake,
sending,
sent,
error,
};
}
2022-06-06 22:42:48 +02:00
export function useRageshakeRequest(): (
roomId: string,
2023-10-11 10:42:04 -04:00
rageshakeRequestId: string,
2022-06-06 22:42:48 +02:00
) => void {
2022-04-07 14:22:36 -07:00
const { client } = useClient();
const sendRageshakeRequest = useCallback(
(roomId: string, rageshakeRequestId: string) => {
Knocking support (#2281) * 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>
2024-04-23 15:15:13 +02:00
// @ts-expect-error - org.matrix.rageshake_request is not part of `keyof TimelineEvents` but it is okay to sent a custom event.
client!.sendEvent(roomId, "org.matrix.rageshake_request", {
2022-04-07 14:22:36 -07:00
request_id: rageshakeRequestId,
});
},
2023-10-11 10:42:04 -04:00
[client],
2022-04-07 14:22:36 -07:00
);
return sendRageshakeRequest;
}
export function useRageshakeRequestModal(
2023-10-11 10:42:04 -04:00
roomId: string,
): ComponentProps<typeof RageshakeRequestModal> {
const [open, setOpen] = useState(false);
const onDismiss = useCallback(() => setOpen(false), [setOpen]);
const { client } = useClient();
const [rageshakeRequestId, setRageshakeRequestId] = useState<string>();
2022-04-07 14:22:36 -07:00
useEffect(() => {
if (!client) return;
const onEvent = (event: MatrixEvent): void => {
2022-04-07 14:22:36 -07:00
const type = event.getType();
if (
type === "org.matrix.rageshake_request" &&
roomId === event.getRoomId() &&
client.getUserId() !== event.getSender()
) {
setRageshakeRequestId(event.getContent().request_id);
setOpen(true);
2022-04-07 14:22:36 -07:00
}
};
2022-06-06 22:42:48 +02:00
client.on(ClientEvent.Event, onEvent);
2022-04-07 14:22:36 -07:00
2024-06-04 11:20:25 -04:00
return (): void => {
2022-06-06 22:42:48 +02:00
client.removeListener(ClientEvent.Event, onEvent);
2022-04-07 14:22:36 -07:00
};
}, [setOpen, roomId, client]);
2022-04-07 14:22:36 -07:00
return {
rageshakeRequestId: rageshakeRequestId ?? "",
roomId,
open,
onDismiss,
};
2022-04-07 14:22:36 -07:00
}