Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref: Convert some class components to function components (#13107)

Robert Pintiliic307a819f65c
diff --git a/react/features/base/avatar/components/AbstractStatelessAvatar.tsx b/react/features/base/avatar/components/AbstractStatelessAvatar.tsx
deleted file mode 100644
index 6b10cb34df..0000000000
--- a/react/features/base/avatar/components/AbstractStatelessAvatar.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { PureComponent } from 'react';
-
-export interface IProps {
-
- /**
- * Color of the (initials based) avatar, if needed.
- */
- color?: string;
-
- /**
- * Initials to be used to render the initials based avatars.
- */
- initials?: string;
-
- /**
- * Callback to signal the failure of the loading of the URL.
- */
- onAvatarLoadError?: Function;
-
- /**
- * Additional parameters to be passed to onAvatarLoadError function.
- */
- onAvatarLoadErrorParams?: Object;
-
- /**
- * Expected size of the avatar.
- */
- size?: number;
-
- /**
- * The URL of the avatar to render.
- */
- url?: string | Function;
-}
-
-/**
- * Implements an abstract stateless avatar component that renders an avatar purely from what gets passed through
- * props.
- */
-export default class AbstractStatelessAvatar<P extends IProps> extends PureComponent<P> {
- /**
- * Checks if the passed prop is a loaded icon or not.
- *
- * @param {string? | Object?} iconProp - The prop to check.
- * @returns {boolean}
- */
- _isIcon(iconProp?: string | Function): iconProp is Function {
- return Boolean(iconProp) && (typeof iconProp === 'object' || typeof iconProp === 'function');
- }
-}
diff --git a/react/features/base/avatar/components/Avatar.tsx b/react/features/base/avatar/components/Avatar.tsx
index 6690dcf57b..944e748cde 100644
--- a/react/features/base/avatar/components/Avatar.tsx
+++ b/react/features/base/avatar/components/Avatar.tsx
@@ -5,8 +5,7 @@ import { IReduxState } from '../../../app/types';
import { getParticipantById } from '../../participants/functions';
import { IParticipant } from '../../participants/types';
import { getAvatarColor, getInitials, isCORSAvatarURL } from '../functions';
-
-import { IProps as AbstractProps } from './AbstractStatelessAvatar';
+import { IAvatarProps as AbstractProps } from '../types';
import { StatelessAvatar } from './';
diff --git a/react/features/base/avatar/components/native/StatelessAvatar.js b/react/features/base/avatar/components/native/StatelessAvatar.tsx
similarity index 87%
rename from react/features/base/avatar/components/native/StatelessAvatar.js
rename to react/features/base/avatar/components/native/StatelessAvatar.tsx
index bc944b492d..901137fbdf 100644
--- a/react/features/base/avatar/components/native/StatelessAvatar.js
+++ b/react/features/base/avatar/components/native/StatelessAvatar.tsx
@@ -1,41 +1,44 @@
-// @flow
-
-import React from 'react';
+import React, { Component } from 'react';
import { Image, Text, View } from 'react-native';
-import { Icon } from '../../../icons';
+import Icon from '../../../icons/components/Icon';
+// eslint-disable-next-line lines-around-comment
+// @ts-ignore
import { type StyleType } from '../../../styles';
-import AbstractStatelessAvatar, { type IProps as AbstractProps } from '../AbstractStatelessAvatar';
+import { isIcon } from '../../functions';
+import { IAvatarProps } from '../../types';
+// @ts-ignore
import styles from './styles';
+// eslint-disable-next-line @typescript-eslint/no-var-requires
const DEFAULT_AVATAR = require('../../../../../../images/avatar.png');
-type Props = AbstractProps & {
+interface IProps extends IAvatarProps {
/**
* One of the expected status strings (e.g. 'available') to render a badge on the avatar, if necessary.
*/
- status?: ?string,
+ status?: string;
/**
* External style passed to the component.
*/
- style?: StyleType
-};
+ style?: StyleType;
+}
/**
* Implements a stateless avatar component that renders an avatar purely from what gets passed through
* props.
*/
-export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
+export default class StatelessAvatar extends Component<IProps> {
/**
* Instantiates a new {@code Component}.
*
* @inheritdoc
*/
- constructor(props: Props) {
+ constructor(props: IProps) {
super(props);
this._onAvatarLoadError = this._onAvatarLoadError.bind(this);
@@ -51,7 +54,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
let avatar;
- if (this._isIcon(url)) {
+ if (isIcon(url)) {
avatar = this._renderIconAvatar(url);
} else if (url) {
avatar = this._renderURLAvatar();
@@ -75,8 +78,6 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
);
}
- _isIcon: (?string | ?Object) => boolean;
-
/**
* Renders a badge representing the avatar status.
*
@@ -120,7 +121,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
* @param {Object} icon - The icon component to render.
* @returns {React$Element<*>}
*/
- _renderIconAvatar(icon) {
+ _renderIconAvatar(icon: Function) {
const { color, size } = this.props;
return (
@@ -167,7 +168,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
_renderURLAvatar() {
const { onAvatarLoadError, size, url } = this.props;
- return (
+ return ( // @ts-ignore
<Image
defaultSource = { DEFAULT_AVATAR }
onError = { onAvatarLoadError }
@@ -177,8 +178,6 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
);
}
- _onAvatarLoadError: () => void;
-
/**
* Handles avatar load errors.
*
diff --git a/react/features/base/avatar/components/web/StatelessAvatar.tsx b/react/features/base/avatar/components/web/StatelessAvatar.tsx
index 8673e9ef27..4f74d4e7d4 100644
--- a/react/features/base/avatar/components/web/StatelessAvatar.tsx
+++ b/react/features/base/avatar/components/web/StatelessAvatar.tsx
@@ -1,26 +1,20 @@
-import { Theme } from '@mui/material';
-import { withStyles } from '@mui/styles';
-import clsx from 'clsx';
-import React from 'react';
+import React, { useCallback } from 'react';
+import { makeStyles } from 'tss-react/mui';
import Icon from '../../../icons/components/Icon';
import { IconUser } from '../../../icons/svg';
import { withPixelLineHeight } from '../../../styles/functions.web';
-import AbstractStatelessAvatar, { type IProps as AbstractProps } from '../AbstractStatelessAvatar';
+import { isIcon } from '../../functions';
+import { IAvatarProps } from '../../types';
import { PRESENCE_AVAILABLE_COLOR, PRESENCE_AWAY_COLOR, PRESENCE_BUSY_COLOR, PRESENCE_IDLE_COLOR } from '../styles';
-interface IProps extends AbstractProps {
+interface IProps extends IAvatarProps {
/**
* External class name passed through props.
*/
className?: string;
- /**
- * An object containing the CSS classes.
- */
- classes: any;
-
/**
* The default avatar URL if we want to override the app bundled one (e.g. AlwaysOnTop).
*/
@@ -47,13 +41,7 @@ interface IProps extends AbstractProps {
useCORS?: boolean;
}
-/**
- * Creates the styles for the component.
- *
- * @param {Theme} theme - The MUI theme.
- * @returns {Object}
- */
-const styles = (theme: Theme) => {
+const useStyles = makeStyles()(theme => {
return {
avatar: {
backgroundColor: '#AAA',
@@ -62,8 +50,8 @@ const styles = (theme: Theme) => {
color: theme.palette?.text01 || '#fff',
...withPixelLineHeight(theme.typography?.heading1 ?? {}),
fontSize: 'inherit',
- objectFit: 'cover' as const,
- textAlign: 'center' as const,
+ objectFit: 'cover',
+ textAlign: 'center',
overflow: 'hidden',
'&.avatar-small': {
@@ -95,7 +83,7 @@ const styles = (theme: Theme) => {
},
badge: {
- position: 'relative' as const,
+ position: 'relative',
'&.avatar-badge:after': {
borderRadius: '50%',
@@ -124,145 +112,105 @@ const styles = (theme: Theme) => {
}
}
};
-};
-
-/**
- * Implements a stateless avatar component that renders an avatar purely from what gets passed through
- * props.
- */
-class StatelessAvatar extends AbstractStatelessAvatar<IProps> {
-
- /**
- * Instantiates a new {@code Component}.
- *
- * @inheritdoc
- */
- constructor(props: IProps) {
- super(props);
+});
+
+const StatelessAvatar = ({
+ className,
+ color,
+ id,
+ initials,
+ onAvatarLoadError,
+ onAvatarLoadErrorParams,
+ size,
+ status,
+ testId,
+ url,
+ useCORS
+}: IProps) => {
+ const { classes, cx } = useStyles();
+
+ const _getAvatarStyle = (backgroundColor?: string) => {
+ return {
+ background: backgroundColor || undefined,
+ fontSize: size ? size * 0.4 : '180%',
+ height: size || '100%',
+ width: size || '100%'
+ };
+ };
- this._onAvatarLoadError = this._onAvatarLoadError.bind(this);
- }
+ const _getAvatarClassName = (additional?: string) => cx('avatar', additional, className, classes.avatar);
- /**
- * Implements {@code Component#render}.
- *
- * @inheritdoc
- */
- render() {
- const { initials, url, useCORS } = this.props;
-
- if (this._isIcon(url)) {
- return (
- <div
- className = { clsx(this._getAvatarClassName(), this._getBadgeClassName()) }
- data-testid = { this.props.testId }
- id = { this.props.id }
- style = { this._getAvatarStyle(this.props.color) }>
- <Icon
- size = '50%'
- src = { url } />
- </div>
- );
+ const _getBadgeClassName = () => {
+ if (status) {
+ return cx('avatar-badge', `avatar-badge-${status}`, classes.badge);
}
- if (url) {
- return (
- <div className = { this._getBadgeClassName() }>
- <img
- alt = 'avatar'
- className = { this._getAvatarClassName() }
- crossOrigin = { useCORS ? '' : undefined }
- data-testid = { this.props.testId }
- id = { this.props.id }
- onError = { this._onAvatarLoadError }
- src = { url }
- style = { this._getAvatarStyle() } />
- </div>
- );
- }
+ return '';
+ };
- if (initials) {
- return (
- <div
- className = { clsx(this._getAvatarClassName(), this._getBadgeClassName()) }
- data-testid = { this.props.testId }
- id = { this.props.id }
- style = { this._getAvatarStyle(this.props.color) }>
- <div className = { this.props.classes.initialsContainer }>
- {initials}
- </div>
- </div>
- );
+ const _onAvatarLoadError = useCallback(() => {
+ if (typeof onAvatarLoadError === 'function') {
+ onAvatarLoadError(onAvatarLoadErrorParams);
}
+ }, [ onAvatarLoadError, onAvatarLoadErrorParams ]);
- // default avatar
+ if (isIcon(url)) {
return (
<div
- className = { clsx(this._getAvatarClassName('defaultAvatar'), this._getBadgeClassName()) }
- data-testid = { this.props.testId }
- id = { this.props.id }
- style = { this._getAvatarStyle() }>
+ className = { cx(_getAvatarClassName(), _getBadgeClassName()) }
+ data-testid = { testId }
+ id = { id }
+ style = { _getAvatarStyle(color) }>
<Icon
- size = { '50%' }
- src = { IconUser } />
+ size = '50%'
+ src = { url } />
</div>
);
}
- /**
- * Constructs a style object to be used on the avatars.
- *
- * @param {string} color - The desired background color.
- * @returns {Object}
- */
- _getAvatarStyle(color?: string) {
- const { size } = this.props;
-
- return {
- background: color || undefined,
- fontSize: size ? size * 0.4 : '180%',
- height: size || '100%',
- width: size || '100%'
- };
- }
-
- /**
- * Constructs a list of class names required for the avatar component.
- *
- * @param {string} additional - Any additional class to add.
- * @returns {string}
- */
- _getAvatarClassName(additional?: string) {
- return clsx('avatar', additional, this.props.className, this.props.classes.avatar);
+ if (url) {
+ return (
+ <div className = { _getBadgeClassName() }>
+ <img
+ alt = 'avatar'
+ className = { _getAvatarClassName() }
+ crossOrigin = { useCORS ? '' : undefined }
+ data-testid = { testId }
+ id = { id }
+ onError = { _onAvatarLoadError }
+ src = { url }
+ style = { _getAvatarStyle() } />
+ </div>
+ );
}
- /**
- * Generates a class name to render a badge on the avatar, if necessary.
- *
- * @returns {string}
- */
- _getBadgeClassName() {
- const { status } = this.props;
-
- if (status) {
- return clsx('avatar-badge', `avatar-badge-${status}`, this.props.classes.badge);
- }
-
- return '';
+ if (initials) {
+ return (
+ <div
+ className = { cx(_getAvatarClassName(), _getBadgeClassName()) }
+ data-testid = { testId }
+ id = { id }
+ style = { _getAvatarStyle(color) }>
+ <div className = { classes.initialsContainer }>
+ {initials}
+ </div>
+ </div>
+ );
}
- /**
- * Handles avatar load errors.
- *
- * @returns {void}
- */
- _onAvatarLoadError() {
- const { onAvatarLoadError, onAvatarLoadErrorParams } = this.props;
+ // default avatar
+ return (
+ <div
+ className = { cx(_getAvatarClassName('defaultAvatar'), _getBadgeClassName()) }
+ data-testid = { testId }
+ id = { id }
+ style = { _getAvatarStyle() }>
+ <Icon
+ size = { '50%' }
+ src = { IconUser } />
+ </div>
+ );
+};
- if (typeof onAvatarLoadError === 'function') {
- onAvatarLoadError(onAvatarLoadErrorParams);
- }
- }
-}
-export default withStyles(styles)(StatelessAvatar);
+export default StatelessAvatar;
diff --git a/react/features/base/avatar/functions.ts b/react/features/base/avatar/functions.ts
index accecd4d2b..e39078f4b4 100644
--- a/react/features/base/avatar/functions.ts
+++ b/react/features/base/avatar/functions.ts
@@ -79,3 +79,13 @@ export function getInitials(s?: string) {
export function isCORSAvatarURL(url: string, corsURLs: Array<string> = []): boolean {
return corsURLs.some(pattern => url.startsWith(pattern));
}
+
+/**
+ * Checks if the passed prop is a loaded icon or not.
+ *
+ * @param {string? | Object?} iconProp - The prop to check.
+ * @returns {boolean}
+ */
+export function isIcon(iconProp?: string | Function): iconProp is Function {
+ return Boolean(iconProp) && (typeof iconProp === 'object' || typeof iconProp === 'function');
+}
diff --git a/react/features/base/avatar/types.ts b/react/features/base/avatar/types.ts
new file mode 100644
index 0000000000..38cc4fcea5
--- /dev/null
+++ b/react/features/base/avatar/types.ts
@@ -0,0 +1,32 @@
+export interface IAvatarProps {
+
+ /**
+ * Color of the (initials based) avatar, if needed.
+ */
+ color?: string;
+
+ /**
+ * Initials to be used to render the initials based avatars.
+ */
+ initials?: string;
+
+ /**
+ * Callback to signal the failure of the loading of the URL.
+ */
+ onAvatarLoadError?: Function;
+
+ /**
+ * Additional parameters to be passed to onAvatarLoadError function.
+ */
+ onAvatarLoadErrorParams?: Object;
+
+ /**
+ * Expected size of the avatar.
+ */
+ size?: number;
+
+ /**
+ * The URL of the avatar to render.
+ */
+ url?: string | Function;
+}
diff --git a/react/features/connection-stats/components/ConnectionStatsTable.tsx b/react/features/connection-stats/components/ConnectionStatsTable.tsx
index e54bdf8e95..24118e0139 100644
--- a/react/features/connection-stats/components/ConnectionStatsTable.tsx
+++ b/react/features/connection-stats/components/ConnectionStatsTable.tsx
@@ -1,11 +1,9 @@
-import { Theme } from '@mui/material';
-import { withStyles } from '@mui/styles';
-import clsx from 'clsx';
-import React, { Component } from 'react';
-import { WithTranslation } from 'react-i18next';
+/* eslint-disable react/no-multi-comp */
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+import { makeStyles } from 'tss-react/mui';
import { isMobileBrowser } from '../../base/environment/utils';
-import { translate } from '../../base/i18n/functions';
import ContextMenu from '../../base/ui/components/web/ContextMenu';
type DownloadUpload = {
@@ -17,7 +15,7 @@ type DownloadUpload = {
* The type of the React {@code Component} props of
* {@link ConnectionStatsTable}.
*/
-interface IProps extends WithTranslation {
+interface IProps {
/**
* The audio SSRC of this client.
@@ -48,11 +46,6 @@ interface IProps extends WithTranslation {
*/
bridgeCount: number;
- /**
- * An object containing the CSS classes.
- */
- classes: any;
-
/**
* Audio/video codecs in use for the connection.
*/
@@ -201,16 +194,16 @@ function onClick(event: React.MouseEvent) {
event.stopPropagation();
}
-const styles = (theme: Theme) => {
+const useStyles = makeStyles()(theme => {
return {
actions: {
margin: '10px auto',
- textAlign: 'center' as const
+ textAlign: 'center'
},
connectionStatsTable: {
'&, & > table': {
fontSize: '12px',
- fontWeight: '400',
+ fontWeight: 400,
'& td': {
padding: '2px 0'
@@ -229,7 +222,7 @@ const styles = (theme: Theme) => {
}
},
contextMenu: {
- position: 'relative' as const,
+ position: 'relative',
margin: 0,
right: 'auto',
padding: `${theme.spacing(2)} ${theme.spacing(1)}`
@@ -243,543 +236,145 @@ const styles = (theme: Theme) => {
},
upload: {}
};
-};
-
-/**
- * React {@code Component} for displaying connection statistics.
- *
- * @augments Component
- */
-class ConnectionStatsTable extends Component<IProps> {
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- * @returns {ReactElement}
- */
- render() {
- const {
- classes,
- disableShowMoreStats,
- enableSaveLogs,
- isVirtualScreenshareParticipant,
- isLocalVideo,
- isNarrowLayout
- } = this.props;
- const className = clsx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() || isNarrowLayout });
-
- if (isVirtualScreenshareParticipant) {
- return this._renderScreenShareStatus();
- }
-
- return (
- <ContextMenu
- className = { classes.contextMenu }
- hidden = { false }
- inDrawer = { true }>
- <div
- className = { className }
- onClick = { onClick }>
- { this._renderStatistics() }
- <div className = { classes.actions }>
- { isLocalVideo && enableSaveLogs ? this._renderSaveLogs() : null}
- { !disableShowMoreStats && this._renderShowMoreLink() }
- </div>
- { this.props.shouldShowMore ? this._renderAdditionalStats() : null }
- </div>
- </ContextMenu>
- );
- }
-
- /**
- * Creates a ReactElement that will display connection statistics for a screen share thumbnail.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderScreenShareStatus() {
- const { classes } = this.props;
- const className = clsx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() });
-
- return (<ContextMenu
- className = { classes.contextMenu }
- hidden = { false }
- inDrawer = { true }>
- <div
- className = { className }
- onClick = { onClick }>
- <tbody>
- { this._renderResolution() }
- { this._renderFrameRate() }
- </tbody>
- </div>
- </ContextMenu>);
- }
-
- /**
- * Creates a table as ReactElement that will display additional statistics
- * related to bandwidth and transport for the local user.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderAdditionalStats() {
- const { isLocalVideo } = this.props;
-
- return (
- <table>
- <tbody>
- { isLocalVideo ? this._renderBandwidth() : null }
- { isLocalVideo ? this._renderTransport() : null }
- { this._renderRegion() }
- { isLocalVideo ? this._renderBridgeCount() : null }
- { this._renderAudioSsrc() }
- { this._renderVideoSsrc() }
- { this._renderParticipantId() }
- </tbody>
- </table>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying bandwidth related
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderBandwidth() {
- const { classes } = this.props;
- const { download, upload } = this.props.bandwidth || {};
-
- return (
- <tr>
- <td>
- { this.props.t('connectionindicator.bandwidth') }
- </td>
- <td>
- <span className = { classes.download }>
- &darr;
- </span>
- { download ? `${download} Kbps` : 'N/A' }
- <span className = { classes.upload }>
- &uarr;
- </span>
- { upload ? `${upload} Kbps` : 'N/A' }
- </td>
- </tr>
- );
- }
-
- /**
- * Creates a a table row as a ReactElement for displaying bitrate related
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderBitrate() {
- const { classes } = this.props;
- const { download, upload } = this.props.bitrate || {};
-
- return (
- <tr>
- <td>
- <span>
- { this.props.t('connectionindicator.bitrate') }
- </span>
- </td>
- <td>
- <span className = { classes.download }>
- &darr;
- </span>
- { download ? `${download} Kbps` : 'N/A' }
- <span className = { classes.upload }>
- &uarr;
- </span>
- { upload ? `${upload} Kbps` : 'N/A' }
- </td>
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying the audio ssrc.
- * This will typically be something like "Audio SSRC: 12345".
- *
- * @returns {JSX.Element}
- * @private
- */
- _renderAudioSsrc() {
- const { audioSsrc, t } = this.props;
-
- return (
- <tr>
- <td>
- <span>{ t('connectionindicator.audio_ssrc') }</span>
- </td>
- <td>{ audioSsrc || 'N/A' }</td>
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying the video ssrc.
- * This will typically be something like "Video SSRC: 12345".
- *
- * @returns {JSX.Element}
- * @private
- */
- _renderVideoSsrc() {
- const { videoSsrc, t } = this.props;
-
- return (
- <tr>
- <td>
- <span>{ t('connectionindicator.video_ssrc') }</span>
- </td>
- <td>{ videoSsrc || 'N/A' }</td>
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying the endpoint id.
- * This will typically be something like "Endpoint id: 1e8fbg".
- *
- * @returns {JSX.Element}
- * @private
- */
- _renderParticipantId() {
- const { participantId, t } = this.props;
-
- return (
- <tr>
- <td>
- <span>{ t('connectionindicator.participant_id') }</span>
- </td>
- <td>{ participantId || 'N/A' }</td>
- </tr>
- );
- }
+});
+
+const ConnectionStatsTable = ({
+ audioSsrc,
+ bandwidth,
+ bitrate,
+ bridgeCount,
+ codec,
+ connectionSummary,
+ disableShowMoreStats,
+ e2eeVerified,
+ enableSaveLogs,
+ framerate,
+ isVirtualScreenshareParticipant,
+ isLocalVideo,
+ isNarrowLayout,
+ maxEnabledResolution,
+ onSaveLogs,
+ onShowMore,
+ packetLoss,
+ participantId,
+ region,
+ resolution,
+ serverRegion,
+ shouldShowMore,
+ transport,
+ videoSsrc
+}: IProps) => {
+ const { classes, cx } = useStyles();
+ const { t } = useTranslation();
+
+ const _renderResolution = () => {
+ let resolutionString = 'N/A';
- /**
- * Creates a a table row as a ReactElement for displaying codec, if present.
- * This will typically be something like "Codecs (A/V): Opus, vp8".
- *
- * @private
- * @returns {ReactElement}
- */
- _renderCodecs() {
- const { audioSsrc, codec, t, videoSsrc } = this.props;
+ if (resolution && videoSsrc) {
+ const { width, height } = resolution[videoSsrc] ?? {};
- let codecString = 'N/A';
+ if (width && height) {
+ resolutionString = `${width}x${height}`;
- if (codec) {
- const audioCodec = codec[audioSsrc]?.audio;
- const videoCodec = codec[videoSsrc]?.video;
+ if (maxEnabledResolution && maxEnabledResolution < 720 && !isVirtualScreenshareParticipant) {
+ const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
- if (audioCodec || videoCodec) {
- codecString = [ audioCodec, videoCodec ].filter(Boolean).join(', ');
+ resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
+ }
}
}
return (
<tr>
<td>
- <span>{ t('connectionindicator.codecs') }</span>
- </td>
- <td>{ codecString }</td>
- </tr>
- );
- }
-
- /**
- * Creates a a table row as a ReactElement for displaying e2ee verication status, if present.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderE2EEVerified() {
- const { e2eeVerified, t } = this.props;
-
- if (e2eeVerified === undefined) {
- return;
- }
-
- const status = e2eeVerified ? '\u{2705}' : '\u{274C}';
-
- return (
- <tr>
- <td>
- <span>{ t('connectionindicator.e2eeVerified') }</span>
+ <span>{t('connectionindicator.resolution')}</span>
</td>
- <td>{ status }</td>
+ <td>{resolutionString}</td>
</tr>
);
- }
-
-
- /**
- * Creates a table row as a ReactElement for displaying a summary message
- * about the current connection status.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderConnectionSummary() {
- const { classes } = this.props;
-
- return (
- <tr className = { classes.status }>
- <td>
- <span>{ this.props.t('connectionindicator.status') }</span>
- </td>
- <td>{ this.props.connectionSummary }</td>
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying the "connected to"
- * information.
- *
- * @returns {ReactElement}
- * @private
- */
- _renderRegion() {
- const { region, serverRegion, t } = this.props;
- let str = serverRegion;
-
- if (!serverRegion) {
- return;
- }
+ };
+ const _renderFrameRate = () => {
+ let frameRateString = 'N/A';
- if (region && serverRegion && region !== serverRegion) {
- str += ` from ${region}`;
+ if (framerate) {
+ frameRateString = String(framerate[videoSsrc] ?? 'N/A');
}
return (
<tr>
<td>
- <span>{ t('connectionindicator.connectedTo') }</span>
+ <span>{t('connectionindicator.framerate')}</span>
</td>
- <td>{ str }</td>
+ <td>{frameRateString}</td>
</tr>
);
- }
-
- /**
- * Creates a table row as a ReactElement for displaying the "bridge count"
- * information.
- *
- * @returns {*}
- * @private
- */
- _renderBridgeCount() {
- const { bridgeCount, t } = this.props;
+ };
- // 0 is valid, but undefined/null/NaN aren't.
- if (!bridgeCount && bridgeCount !== 0) {
- return;
- }
+ const _renderScreenShareStatus = () => {
+ const className = cx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() });
- return (
- <tr>
- <td>
- <span>{ t('connectionindicator.bridgeCount') }</span>
- </td>
- <td>{ bridgeCount }</td>
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying frame rate related
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderFrameRate() {
- const { framerate, t, videoSsrc } = this.props;
- let frameRateString = 'N/A';
+ return (<ContextMenu
+ className = { classes.contextMenu }
+ hidden = { false }
+ inDrawer = { true }>
+ <div
+ className = { className }
+ onClick = { onClick }>
+ <tbody>
+ {_renderResolution()}
+ {_renderFrameRate()}
+ </tbody>
+ </div>
+ </ContextMenu>);
+ };
- if (framerate) {
- frameRateString = String(framerate[videoSsrc] ?? 'N/A');
- }
+ const _renderBandwidth = () => {
+ const { download, upload } = bandwidth || {};
return (
<tr>
<td>
- <span>{ t('connectionindicator.framerate') }</span>
+ {t('connectionindicator.bandwidth')}
</td>
- <td>{ frameRateString }</td>
- </tr>
- );
- }
-
- /**
- * Creates a tables row as a ReactElement for displaying packet loss related
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderPacketLoss() {
- const { classes, packetLoss, t } = this.props;
- let packetLossTableData;
-
- if (packetLoss) {
- const { download, upload } = packetLoss;
-
- packetLossTableData = (
<td>
<span className = { classes.download }>
&darr;
</span>
- { download === null ? 'N/A' : `${download}%` }
+ {download ? `${download} Kbps` : 'N/A'}
<span className = { classes.upload }>
&uarr;
</span>
- { upload === null ? 'N/A' : `${upload}%` }
+ {upload ? `${upload} Kbps` : 'N/A'}
</td>
- );
- } else {
- packetLossTableData = <td>N/A</td>;
- }
+ </tr>
+ );
+ };
+
+ const _renderTransportTableRow = (config: any) => {
+ const { additionalData, data, key, label } = config;
return (
- <tr>
+ <tr key = { key }>
<td>
<span>
- { t('connectionindicator.packetloss') }
+ {label}
</span>
</td>
- { packetLossTableData }
- </tr>
- );
- }
-
- /**
- * Creates a table row as a ReactElement for displaying resolution related
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderResolution() {
- const { isVirtualScreenshareParticipant, maxEnabledResolution, resolution, t, videoSsrc } = this.props;
- let resolutionString = 'N/A';
-
- if (resolution && videoSsrc) {
- const { width, height } = resolution[videoSsrc] ?? { };
-
- if (width && height) {
- resolutionString = `${width}x${height}`;
-
- if (maxEnabledResolution && maxEnabledResolution < 720 && !isVirtualScreenshareParticipant) {
- const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
-
- resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
- }
- }
- }
-
- return (
- <tr>
<td>
- <span>{ t('connectionindicator.resolution') }</span>
+ {getStringFromArray(data)}
+ {additionalData || null}
</td>
- <td>{ resolutionString }</td>
</tr>
);
- }
-
- /**
- * Creates a ReactElement for display a link to save the logs.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderSaveLogs() {
- return (
- <span>
- <a
- className = 'savelogs link'
- onClick = { this.props.onSaveLogs }
- role = 'button'
- tabIndex = { 0 }>
- { this.props.t('connectionindicator.savelogs') }
- </a>
- <span> | </span>
- </span>
- );
- }
-
-
- /**
- * Creates a ReactElement for display a link to toggle showing additional
- * statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderShowMoreLink() {
- const translationKey
- = this.props.shouldShowMore
- ? 'connectionindicator.less'
- : 'connectionindicator.more';
-
- return (
- <a
- className = 'showmore link'
- onClick = { this.props.onShowMore }
- role = 'button'
- tabIndex = { 0 }>
- { this.props.t(translationKey) }
- </a>
- );
- }
-
- /**
- * Creates a table as a ReactElement for displaying connection statistics.
- *
- * @private
- * @returns {ReactElement}
- */
- _renderStatistics() {
- return (
- <table>
- <tbody>
- { this._renderConnectionSummary() }
- { this._renderBitrate() }
- { this._renderPacketLoss() }
- { this._renderResolution() }
- { this._renderFrameRate() }
- { this._renderCodecs() }
- { this._renderE2EEVerified() }
- </tbody>
- </table>
- );
- }
-
- /**
- * Creates table rows as ReactElements for displaying transport related
- * statistics.
- *
- * @private
- * @returns {ReactElement[]}
- */
- _renderTransport() {
- const { t, transport } = this.props;
+ };
+ const _renderTransport = () => {
if (!transport || transport.length === 0) {
const NA = (
<tr key = 'address'>
<td>
- <span>{ t('connectionindicator.address') }</span>
+ <span>{t('connectionindicator.address')}</span>
</td>
<td>
N/A
@@ -863,7 +458,7 @@ class ConnectionStatsTable extends Component<IProps> {
data: data.remotePort,
key: 'remoteport',
label: t('connectionindicator.remoteport',
- { count: transport.length })
+ { count: transport.length })
},
{
data: data.localIP,
@@ -885,41 +480,261 @@ class ConnectionStatsTable extends Component<IProps> {
}
];
- return tableRowConfigurations.map(this._renderTransportTableRow);
- }
+ return tableRowConfigurations.map(_renderTransportTableRow);
+ };
- /**
- * Creates a table row as a ReactElement for displaying a transport related
- * statistic.
- *
- * @param {Object} config - Describes the contents of the row.
- * @param {ReactElement} config.additionalData - Extra data to display next
- * to the passed in config.data.
- * @param {Array} config.data - The transport statistics to display.
- * @param {string} config.key - The ReactElement's key. Must be unique for
- * iterating over multiple child rows.
- * @param {string} config.label - The text to display describing the data.
- * @private
- * @returns {ReactElement}
- */
- _renderTransportTableRow(config: any) {
- const { additionalData, data, key, label } = config;
+ const _renderRegion = () => {
+ let str = serverRegion;
+
+ if (!serverRegion) {
+ return;
+ }
+
+
+ if (region && serverRegion && region !== serverRegion) {
+ str += ` from ${region}`;
+ }
return (
- <tr key = { key }>
+ <tr>
+ <td>
+ <span>{t('connectionindicator.connectedTo')}</span>
+ </td>
+ <td>{str}</td>
+ </tr>
+ );
+ };
+
+ const _renderBridgeCount = () => {
+ // 0 is valid, but undefined/null/NaN aren't.
+ if (!bridgeCount && bridgeCount !== 0) {
+ return;
+ }
+
+ return (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.bridgeCount')}</span>
+ </td>
+ <td>{bridgeCount}</td>
+ </tr>
+ );
+ };
+
+ const _renderAudioSsrc = () => (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.audio_ssrc')}</span>
+ </td>
+ <td>{audioSsrc || 'N/A'}</td>
+ </tr>
+ );
+
+ const _renderVideoSsrc = () => (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.video_ssrc')}</span>
+ </td>
+ <td>{videoSsrc || 'N/A'}</td>
+ </tr>
+ );
+
+ const _renderParticipantId = () => (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.participant_id')}</span>
+ </td>
+ <td>{participantId || 'N/A'}</td>
+ </tr>
+ );
+
+ const _renderAdditionalStats = () => (
+ <table>
+ <tbody>
+ {isLocalVideo ? _renderBandwidth() : null}
+ {isLocalVideo ? _renderTransport() : null}
+ {_renderRegion()}
+ {isLocalVideo ? _renderBridgeCount() : null}
+ {_renderAudioSsrc()}
+ {_renderVideoSsrc()}
+ {_renderParticipantId()}
+ </tbody>
+ </table>
+ );
+
+ const _renderBitrate = () => {
+ const { download, upload } = bitrate || {};
+
+ return (
+ <tr>
<td>
<span>
- { label }
+ {t('connectionindicator.bitrate')}
</span>
</td>
<td>
- { getStringFromArray(data) }
- { additionalData || null }
+ <span className = { classes.download }>
+ &darr;
+ </span>
+ {download ? `${download} Kbps` : 'N/A'}
+ <span className = { classes.upload }>
+ &uarr;
+ </span>
+ {upload ? `${upload} Kbps` : 'N/A'}
+ </td>
+ </tr>
+ );
+ };
+
+ const _renderCodecs = () => {
+ let codecString = 'N/A';
+
+ if (codec) {
+ const audioCodec = codec[audioSsrc]?.audio;
+ const videoCodec = codec[videoSsrc]?.video;
+
+ if (audioCodec || videoCodec) {
+ codecString = [ audioCodec, videoCodec ].filter(Boolean).join(', ');
+ }
+ }
+
+ return (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.codecs')}</span>
+ </td>
+ <td>{codecString}</td>
+ </tr>
+ );
+ };
+
+ const _renderE2EEVerified = () => {
+ if (e2eeVerified === undefined) {
+ return;
+ }
+
+ const status = e2eeVerified ? '\u{2705}' : '\u{274C}';
+
+ return (
+ <tr>
+ <td>
+ <span>{t('connectionindicator.e2eeVerified')}</span>
</td>
+ <td>{status}</td>
</tr>
);
+ };
+
+ const _renderConnectionSummary = () => (
+ <tr className = { classes.status }>
+ <td>
+ <span>{t('connectionindicator.status')}</span>
+ </td>
+ <td>{connectionSummary}</td>
+ </tr>
+ );
+
+ const _renderPacketLoss = () => {
+ let packetLossTableData;
+
+ if (packetLoss) {
+ const { download, upload } = packetLoss;
+
+ packetLossTableData = (
+ <td>
+ <span className = { classes.download }>
+ &darr;
+ </span>
+ {download === null ? 'N/A' : `${download}%`}
+ <span className = { classes.upload }>
+ &uarr;
+ </span>
+ {upload === null ? 'N/A' : `${upload}%`}
+ </td>
+ );
+ } else {
+ packetLossTableData = <td>N/A</td>;
+ }
+
+ return (
+ <tr>
+ <td>
+ <span>
+ {t('connectionindicator.packetloss')}
+ </span>
+ </td>
+ {packetLossTableData}
+ </tr>
+ );
+ };
+
+ const _renderSaveLogs = () => (
+ <span>
+ <a
+ className = 'savelogs link'
+ onClick = { onSaveLogs }
+ role = 'button'
+ tabIndex = { 0 }>
+ {t('connectionindicator.savelogs')}
+ </a>
+ <span> | </span>
+ </span>
+ );
+
+ const _renderShowMoreLink = () => {
+ const translationKey
+ = shouldShowMore
+ ? 'connectionindicator.less'
+ : 'connectionindicator.more';
+
+ return (
+ <a
+ className = 'showmore link'
+ onClick = { onShowMore }
+ role = 'button'
+ tabIndex = { 0 }>
+ {t(translationKey)}
+ </a>
+ );
+ };
+
+ const _renderStatistics = () => (
+ <table>
+ <tbody>
+ {_renderConnectionSummary()}
+ {_renderBitrate()}
+ {_renderPacketLoss()}
+ {_renderResolution()}
+ {_renderFrameRate()}
+ {_renderCodecs()}
+ {_renderE2EEVerified()}
+ </tbody>
+ </table>
+ );
+
+ if (isVirtualScreenshareParticipant) {
+ return _renderScreenShareStatus();
}
-}
+
+ return (
+ <ContextMenu
+ className = { classes.contextMenu }
+ hidden = { false }
+ inDrawer = { true }>
+ <div
+ className = { cx(classes.connectionStatsTable, {
+ [classes.mobile]: isMobileBrowser() || isNarrowLayout }) }
+ onClick = { onClick }>
+ {_renderStatistics()}
+ <div className = { classes.actions }>
+ {isLocalVideo && enableSaveLogs ? _renderSaveLogs() : null}
+ {!disableShowMoreStats && _renderShowMoreLink()}
+ </div>
+ {shouldShowMore ? _renderAdditionalStats() : null}
+ </div>
+ </ContextMenu>
+ );
+};
/**
* Utility for getting the IP from a transport statistics object's
@@ -970,4 +785,4 @@ function getStringFromArray(array: string[]) {
return res;
}
-export default translate(withStyles(styles)(ConnectionStatsTable));
+export default ConnectionStatsTable;
diff --git a/react/features/video-menu/components/web/VolumeSlider.tsx b/react/features/video-menu/components/web/VolumeSlider.tsx
index 0464c1e0af..0dc0e8c8ec 100644
--- a/react/features/video-menu/components/web/VolumeSlider.tsx
+++ b/react/features/video-menu/components/web/VolumeSlider.tsx
@@ -1,10 +1,7 @@
-import { Theme } from '@mui/material';
-import { withStyles } from '@mui/styles';
-import clsx from 'clsx';
-import React, { Component } from 'react';
-import { WithTranslation } from 'react-i18next';
+import React, { useCallback, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { makeStyles } from 'tss-react/mui';
-import { translate } from '../../../base/i18n/functions';
import Icon from '../../../base/icons/components/Icon';
import { IconVolumeUp } from '../../../base/icons/svg';
import { VOLUME_SLIDER_SCALE } from '../../constants';
@@ -12,12 +9,7 @@ import { VOLUME_SLIDER_SCALE } from '../../constants';
/**
* The type of the React {@code Component} props of {@link VolumeSlider}.
*/
-interface IProps extends WithTranslation {
-
- /**
- * An object containing the CSS classes.
- */
- classes: any;
+interface IProps {
/**
* The value of the audio slider should display at when the component first
@@ -32,25 +24,13 @@ interface IProps extends WithTranslation {
onChange: Function;
}
-/**
- * The type of the React {@code Component} state of {@link VolumeSlider}.
- */
-interface IState {
-
- /**
- * The volume of the participant's audio element. The value will
- * be represented by a slider.
- */
- volumeLevel: number;
-}
-
-const styles = (theme: Theme) => {
+const useStyles = makeStyles()(theme => {
return {
container: {
minHeight: '40px',
minWidth: '180px',
width: '100%',
- boxSizing: 'border-box' as const,
+ boxSizing: 'border-box',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
@@ -64,107 +44,68 @@ const styles = (theme: Theme) => {
icon: {
minWidth: '20px',
marginRight: '16px',
- position: 'relative' as const
+ position: 'relative'
},
sliderContainer: {
- position: 'relative' as const,
+ position: 'relative',
width: '100%'
},
slider: {
- position: 'absolute' as const,
+ position: 'absolute',
width: '100%',
top: '50%',
transform: 'translate(0, -50%)'
}
};
-};
+});
-/**
- * Implements a React {@link Component} which displays an input slider for
- * adjusting the local volume of a remote participant.
- *
- * @augments Component
- */
-class VolumeSlider extends Component<IProps, IState> {
- /**
- * Initializes a new {@code VolumeSlider} instance.
- *
- * @param {Object} props - The read-only properties with which the new
- * instance is to be initialized.
- */
- constructor(props: IProps) {
- super(props);
-
- this.state = {
- volumeLevel: (props.initialValue || 0) * VOLUME_SLIDER_SCALE
- };
-
- // Bind event handlers so they are only bound once for every instance.
- this._onVolumeChange = this._onVolumeChange.bind(this);
- }
-
- /**
- * Click handler.
- *
- * @param {MouseEvent} e - Click event.
- * @returns {void}
- */
- _onClick(e: React.MouseEvent) {
- e.stopPropagation();
- }
+const _onClick = (e: React.MouseEvent) => {
+ e.stopPropagation();
+};
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- * @returns {ReactElement}
- */
- render() {
- const { classes } = this.props;
-
- return (
- <div
- aria-label = { this.props.t('volumeSlider') }
- className = { clsx('popupmenu__contents', classes.container) }
- onClick = { this._onClick }>
- <span className = { classes.icon }>
- <Icon
- size = { 22 }
- src = { IconVolumeUp } />
- </span>
- <div className = { classes.sliderContainer }>
- <input
- aria-valuemax = { VOLUME_SLIDER_SCALE }
- aria-valuemin = { 0 }
- aria-valuenow = { this.state.volumeLevel }
- className = { clsx('popupmenu__volume-slider', classes.slider) }
- max = { VOLUME_SLIDER_SCALE }
- min = { 0 }
- onChange = { this._onVolumeChange }
- tabIndex = { 0 }
- type = 'range'
- value = { this.state.volumeLevel } />
- </div>
+const VolumeSlider = ({
+ initialValue,
+ onChange
+}: IProps) => {
+ const { classes, cx } = useStyles();
+ const { t } = useTranslation();
+
+ const [ volumeLevel, setVolumeLevel ] = useState((initialValue || 0) * VOLUME_SLIDER_SCALE);
+
+ const _onVolumeChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
+ const newVolumeLevel = Number(event.currentTarget.value);
+
+ onChange(newVolumeLevel / VOLUME_SLIDER_SCALE);
+ setVolumeLevel(newVolumeLevel);
+ }, [ onChange ]);
+
+ return (
+ <div
+ aria-label = { t('volumeSlider') }
+ className = { cx('popupmenu__contents', classes.container) }
+ onClick = { _onClick }>
+ <span className = { classes.icon }>
+ <Icon
+ size = { 22 }
+ src = { IconVolumeUp } />
+ </span>
+ <div className = { classes.sliderContainer }>
+ <input
+ aria-valuemax = { VOLUME_SLIDER_SCALE }
+ aria-valuemin = { 0 }
+ aria-valuenow = { volumeLevel }
+ className = { cx('popupmenu__volume-slider', classes.slider) }
+ max = { VOLUME_SLIDER_SCALE }
+ min = { 0 }
+ onChange = { _onVolumeChange }
+ tabIndex = { 0 }
+ type = 'range'
+ value = { volumeLevel } />
</div>
- );
- }
-
- /**
- * Sets the internal state of the volume level for the volume slider.
- * Invokes the prop onVolumeChange to notify of volume changes.
- *
- * @param {Object} event - DOM Event for slider change.
- * @private
- * @returns {void}
- */
- _onVolumeChange(event: React.ChangeEvent<HTMLInputElement>) {
- const volumeLevel = Number(event.currentTarget.value);
-
- this.props.onChange(volumeLevel / VOLUME_SLIDER_SCALE);
- this.setState({ volumeLevel });
- }
-}
+ </div>
+ );
+};
-export default translate(withStyles(styles)(VolumeSlider));
+export default VolumeSlider;