/* Copyright 2023, 2024 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ 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; } // 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 && (
showFullModal("audio")} size="sm"> {"jitter" in audio && typeof audio.jitter === "number" && (  {(audio.jitter * 1000).toFixed(0)}ms )}
)} {video && (
showFullModal("video")} size="sm"> {video?.framesPerSecond && (  {video.framesPerSecond.toFixed(0)}fps )} {"jitter" in video && typeof video.jitter === "number" && (  {(video.jitter * 1000).toFixed(0)}ms )} {"frameHeight" in video && typeof video.frameHeight === "number" && "frameWidth" in video && typeof video.frameWidth === "number" && (  {video.frameWidth}x{video.frameHeight} )} {"qualityLimitationReason" in video && typeof video.qualityLimitationReason === "string" && video.qualityLimitationReason !== "none" && (  {video.qualityLimitationReason} )}
)}
); };