From 2c1676be4166998ddb3567487ff5521ee80a3eeb Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 18 Dec 2024 17:28:24 +0000 Subject: [PATCH] Use modal to show detailed stats instead of alert --- src/RTCConnectionStats.module.css | 14 +++++++++ src/RTCConnectionStats.tsx | 49 ++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/RTCConnectionStats.module.css diff --git a/src/RTCConnectionStats.module.css b/src/RTCConnectionStats.module.css new file mode 100644 index 000000000..d663577cb --- /dev/null +++ b/src/RTCConnectionStats.module.css @@ -0,0 +1,14 @@ +/* +Copyright 2024 New Vector Ltd. + +SPDX-License-Identifier: AGPL-3.0-only +Please see LICENSE in the repository root for full details. +*/ + +.modal pre { + font-size: var(--font-size-micro); +} + +.icon { + color: var(--cpd-color-text-primary); +} diff --git a/src/RTCConnectionStats.tsx b/src/RTCConnectionStats.tsx index b230141d5..eedce04da 100644 --- a/src/RTCConnectionStats.tsx +++ b/src/RTCConnectionStats.tsx @@ -5,13 +5,16 @@ SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ -import { type FC } from "react"; +import { useState, type FC } from "react"; import { IconButton, Text } from "@vector-im/compound-web"; import { MicOnSolidIcon, VideoCallSolidIcon, } from "@vector-im/compound-design-tokens/assets/web/icons"; +import { Modal } from "./Modal"; +import styles from "./RTCConnectionStats.module.css"; + interface Props { audio?: RTCInboundRtpStreamStats | RTCOutboundRtpStreamStats; video?: RTCInboundRtpStreamStats | RTCOutboundRtpStreamStats; @@ -19,15 +22,42 @@ interface Props { // This is only used in developer mode for debugging purposes, so we don't need full localization export const RTCConnectionStats: FC = ({ audio, video, ...rest }) => { + const [showModal, setShowModal] = useState(false); + const [modalContents, setModalContents] = useState< + "video" | "audio" | "none" + >("none"); + + const showFullModal = (contents: "video" | "audio"): void => { + setShowModal(true); + setModalContents(contents); + }; + + const onDismissModal = (): void => { + setShowModal(false); + setModalContents("none"); + }; return (
+ +
+
+            {modalContents !== "none" &&
+              JSON.stringify(
+                modalContents === "video" ? video : audio,
+                null,
+                2,
+              )}
+          
+
+
{audio && (
- alert(JSON.stringify(audio, null, 2))} - size="sm" - > - + showFullModal("audio")} size="sm"> + {"jitter" in audio && typeof audio.jitter === "number" && ( @@ -38,11 +68,8 @@ export const RTCConnectionStats: FC = ({ audio, video, ...rest }) => { )} {video && (
- alert(JSON.stringify(video, null, 2))} - size="sm" - > - + showFullModal("video")} size="sm"> + {video?.framesPerSecond && (