-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add developer mode option to show RTC connection statistics (#2904)
* Add developer mode option to show RTC connection statistics * Add note about localization * Add titles to help explain what the numbers are * Workaround horizontal scrolling * Use modal to show detailed stats instead of alert * Changed styling and fixed fps = 0 (#2916) (React rendered 0 instead of <Text /> for fps && <Text>{fps}</text>) --------- Co-authored-by: Timo <16718859+toger5@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
281 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
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); | ||
} | ||
|
||
.statsPill { | ||
border-radius: var(--media-view-border-radius); | ||
grid-area: none; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
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 { Button, Text } from "@vector-im/compound-web"; | ||
import { | ||
MicOnSolidIcon, | ||
VideoCallSolidIcon, | ||
} from "@vector-im/compound-design-tokens/assets/web/icons"; | ||
import classNames from "classnames"; | ||
|
||
import { Modal } from "./Modal"; | ||
import styles from "./RTCConnectionStats.module.css"; | ||
import mediaViewStyles from "../src/tile/MediaView.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<Props> = ({ 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 ( | ||
<div className={classNames(mediaViewStyles.nameTag, styles.statsPill)}> | ||
<Modal | ||
title="RTC Connection Stats" | ||
open={showModal} | ||
onDismiss={onDismissModal} | ||
> | ||
<div className={styles.modal}> | ||
<pre> | ||
{modalContents !== "none" && | ||
JSON.stringify( | ||
modalContents === "video" ? video : audio, | ||
null, | ||
2, | ||
)} | ||
</pre> | ||
</div> | ||
</Modal> | ||
{audio && ( | ||
<div> | ||
<Button | ||
onClick={() => showFullModal("audio")} | ||
size="sm" | ||
kind="tertiary" | ||
Icon={MicOnSolidIcon} | ||
> | ||
{"jitter" in audio && typeof audio.jitter === "number" && ( | ||
<Text as="span" size="xs" title="jitter"> | ||
{(audio.jitter * 1000).toFixed(0)}ms | ||
</Text> | ||
)} | ||
</Button> | ||
</div> | ||
)} | ||
{video && ( | ||
<div> | ||
<Button | ||
onClick={() => showFullModal("video")} | ||
size="sm" | ||
kind="tertiary" | ||
Icon={VideoCallSolidIcon} | ||
> | ||
{!!video?.framesPerSecond && ( | ||
<Text as="span" size="xs" title="frame rate"> | ||
{video.framesPerSecond.toFixed(0)}fps | ||
</Text> | ||
)} | ||
{"jitter" in video && typeof video.jitter === "number" && ( | ||
<Text as="span" size="xs" title="jitter"> | ||
{(video.jitter * 1000).toFixed(0)}ms | ||
</Text> | ||
)} | ||
{"frameHeight" in video && | ||
typeof video.frameHeight === "number" && | ||
"frameWidth" in video && | ||
typeof video.frameWidth === "number" && ( | ||
<Text as="span" size="xs" title="frame size"> | ||
{video.frameWidth}x{video.frameHeight} | ||
</Text> | ||
)} | ||
{"qualityLimitationReason" in video && | ||
typeof video.qualityLimitationReason === "string" && | ||
video.qualityLimitationReason !== "none" && ( | ||
<Text as="span" size="xs" title="quality limitation reason"> | ||
{video.qualityLimitationReason} | ||
</Text> | ||
)} | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.