Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
ref(PasswordSection): Functional copmonents.
Hristo Terezovb3312b565076
diff --git a/react/features/security/components/security-dialog/web/PasswordForm.tsx b/react/features/security/components/security-dialog/web/PasswordForm.tsxindex 5fb2eb36c4..8fc92b7bad 100644--- a/react/features/security/components/security-dialog/web/PasswordForm.tsx+++ b/react/features/security/components/security-dialog/web/PasswordForm.tsx@@ -1,14 +1,13 @@-import React, { Component } from 'react';-import { WithTranslation } from 'react-i18next';+import React, { useCallback, useState } from 'react';+import { useTranslation } from 'react-i18next';-import { translate } from '../../../../base/i18n/functions';import Input from '../../../../base/ui/components/web/Input';import { LOCKED_LOCALLY } from '../../../../room-lock/constants';/*** The type of the React {@code Component} props of {@link PasswordForm}.*/-interface IProps extends WithTranslation {+interface IProps {/*** Whether or not to show the password editing field.@@ -43,119 +42,60 @@ interface IProps extends WithTranslation {visible: boolean;}-/**- * The type of the React {@code Component} state of {@link PasswordForm}.- */-interface IState {-- /**- * The value of the password being entered by the local participant.- */- enteredPassword: string;-}-/*** React {@code Component} for displaying and editing the conference password.*- * @augments Component+ * @returns {ReactElement}*/-class PasswordForm extends Component<IProps, IState> {- /**- * Implements React's {@link Component#getDerivedStateFromProps()}.- *- * @inheritdoc- */- static getDerivedStateFromProps(props: IProps, state: IState) {- return {- enteredPassword: props.editEnabled ? state.enteredPassword : ''- };- }-- state = {- enteredPassword: ''- };-- /**- * Initializes a new {@code PasswordForm} instance.- *- * @param {IProps} props - The React {@code Component} props to initialize- * the new {@code PasswordForm} instance with.- */- constructor(props: IProps) {- super(props);-- // Bind event handlers so they are only bound once per instance.- this._onEnteredPasswordChange = this._onEnteredPasswordChange.bind(this);- this._onKeyPress = this._onKeyPress.bind(this);- }-- /**- * Implements React's {@link Component#render()}.- *- * @inheritdoc- * @returns {ReactElement}- */- render() {- return (- <div className = 'info-password'>- {this._renderPassword()}- {this._renderPasswordField()}- </div>- );- }+export default function PasswordForm({+ editEnabled,+ locked,+ onSubmit,+ password,+ passwordNumberOfDigits,+ visible+}: IProps) {+ const { t } = useTranslation();+ const [ enteredPassword, setEnteredPassword ] = useState('');+ const onKeyPress = useCallback(event => {+ if (event.key === 'Enter') {+ event.preventDefault();+ event.stopPropagation();- /** .........- * Renders the password if there is any.- *- * @returns {ReactElement}- */- _renderPassword() {- const { locked, t } = this.props;+ onSubmit(enteredPassword);+ }+ }, [ onSubmit, enteredPassword ]);- return locked && <>- <span className = 'info-label'>- {t('info.password')}- </span>- <span className = 'spacer'> </span>- <span className = 'info-password-field info-value'>- {locked === LOCKED_LOCALLY ? (- <div className = 'info-password-local'>- {this.props.visible ? this.props.password : '******' }- </div>- ) : (- <div className = 'info-password-remote'>- {this.props.t('passwordSetRemotely')}- </div>- ) }- {this._renderPasswordField()}- </span>- </>;+ if (!editEnabled && enteredPassword && enteredPassword !== '') {+ setEnteredPassword('');}- /**- * Returns a ReactElement for showing the current state of the password or- * for editing the current password.- *- * @private- * @returns {ReactElement}- */- _renderPasswordField() {- const {- editEnabled,- passwordNumberOfDigits,- t- } = this.props;-- if (editEnabled) {- let placeHolderText = t('dialog.password');-- if (passwordNumberOfDigits) {- placeHolderText = this.props.t('passwordDigitsOnly', {- number: passwordNumberOfDigits });+ const placeHolderText+ = passwordNumberOfDigits ? t('passwordDigitsOnly', { number: passwordNumberOfDigits }) : t('dialog.password');+++ return (+ <div className = 'info-password'>+ { locked && <>+ <span className = 'info-label'>+ {t('info.password')}+ </span>+ <span className = 'spacer'> </span>+ <span className = 'info-password-field info-value'>+ {locked === LOCKED_LOCALLY ? (+ <div className = 'info-password-local'>+ { visible ? password : '******' }+ </div>+ ) : (+ <div className = 'info-password-remote'>+ { t('passwordSetRemotely') }+ </div>+ ) }+ </span>+ </>}-- return (- <div+ {+ editEnabled && <divclassName = 'info-password-form'><InputaccessibilityLabel = { t('info.addPassword') }@@ -163,43 +103,13 @@ class PasswordForm extends Component<IProps, IState> {id = 'info-password-input'maxLength = { passwordNumberOfDigits }mode = { passwordNumberOfDigits ? 'numeric' : undefined }- onChange = { this._onEnteredPasswordChange }- onKeyPress = { this._onKeyPress }+ onChange = { setEnteredPassword }+ onKeyPress = { onKeyPress }placeholder = { placeHolderText }type = 'password'- value = { this.state.enteredPassword } />+ value = { enteredPassword } /></div>- );- }- }-- /**- * Updates the internal state of entered password.- *- * @param {string} value - DOM Event for value change.- * @private- * @returns {void}- */- _onEnteredPasswordChange(value: string) {- this.setState({ enteredPassword: value });- }-- /**- * Stops the the EnterKey for propagation in order to prevent the dialog- * to close.- *- * @param {Object} event - The key event.- * @private- * @returns {void}- */- _onKeyPress(event: React.KeyboardEvent) {- if (event.key === 'Enter') {- event.preventDefault();- event.stopPropagation();-- this.props.onSubmit(this.state.enteredPassword);- }- }+ }+ </div>+ );}--export default translate(PasswordForm);diff --git a/react/features/security/components/security-dialog/web/PasswordSection.tsx b/react/features/security/components/security-dialog/web/PasswordSection.tsxindex f6e88a3101..37e1cc29fe 100644--- a/react/features/security/components/security-dialog/web/PasswordSection.tsx+++ b/react/features/security/components/security-dialog/web/PasswordSection.tsx@@ -1,10 +1,11 @@/* eslint-disable react/jsx-no-bind */import React, { useCallback, useRef, useState } from 'react';-import { WithTranslation } from 'react-i18next';-import { useSelector } from 'react-redux';+import { useTranslation } from 'react-i18next';+import { useDispatch, useSelector } from 'react-redux';import { IReduxState } from '../../../../app/types';-import { translate } from '../../../../base/i18n/functions';+import { setPassword } from '../../../../base/conference/actions';+import { isLocalParticipantModerator } from '../../../../base/participants/functions';import { copyText } from '../../../../base/util/copyText.web';import { LOCKED_LOCALLY } from '../../../../room-lock/constants';import { NOTIFY_CLICK_MODE } from '../../../../toolbox/types';@@ -14,95 +15,38 @@ import PasswordForm from './PasswordForm';const DIGITS_ONLY = /^\d+$/;const KEY = 'add-passcode';-interface IProps extends WithTranslation {-- /**- * Whether or not the current user can modify the current password.- */- canEditPassword: boolean;-- /**- * The JitsiConference for which to display a lock state and change the- * password.- */- conference: any;-- /**- * The value for how the conference is locked (or undefined if not locked)- * as defined by room-lock constants.- */- locked?: string;-- /**- * The current known password for the JitsiConference.- */- password?: string;-- /**- * Whether or not to show the password in editing mode.- */- passwordEditEnabled: boolean;-- /**- * The number of digits to be used in the password.- */- passwordNumberOfDigits?: number;-- /**- * Action that sets the conference password.- */- setPassword: Function;-- /**- * Method that sets whether the password editing is enabled or not.- */- setPasswordEditEnabled: Function;-}-/*** Component that handles the password manipulation from the invite dialog.** @returns {React$Element<any>}*/-function PasswordSection({- canEditPassword,- conference,- locked,- password,- passwordEditEnabled,- passwordNumberOfDigits,- setPassword,- setPasswordEditEnabled,- t }: IProps) {-+function PasswordSection() {+ const { t } = useTranslation();+ const dispatch = useDispatch();+ const canEditPassword = useSelector(isLocalParticipantModerator);+ const passwordNumberOfDigits = useSelector(+ (state: IReduxState) => state['features/base/config'].roomPasswordNumberOfDigits);+ const conference = useSelector((state: IReduxState) => state['features/base/conference'].conference);+ const locked = useSelector((state: IReduxState) => state['features/base/conference'].locked);+ const password = useSelector((state: IReduxState) => state['features/base/conference'].password);const formRef = useRef<HTMLDivElement>(null);const [ passwordVisible, setPasswordVisible ] = useState(false);const buttonsWithNotifyClick = useSelector((state: IReduxState) => state['features/toolbox'].buttonsWithNotifyClick);+ const [ passwordEditEnabled, setPasswordEditEnabled ] = useState(false);++ if (passwordEditEnabled && (password || locked)) {+ setPasswordEditEnabled(false);+ }- /**- * Callback invoked to set a password on the current JitsiConference.- *- * @param {string} enteredPassword - The new password to be used to lock the- * current JitsiConference.- * @private- * @returns {void}- */- function onPasswordSubmit(enteredPassword: string) {+ const onPasswordSubmit = useCallback((enteredPassword: string) => {if (enteredPassword && passwordNumberOfDigits && !DIGITS_ONLY.test(enteredPassword)) {// Don't set the password.return;}- setPassword(conference, conference.lock, enteredPassword);- }+ dispatch(setPassword(conference, conference?.lock, enteredPassword));+ }, [ dispatch, passwordNumberOfDigits, conference?.lock ]);- /**- * Toggles whether or not the password should currently be shown as being- * edited locally.- *- * @private- * @returns {void}- */const onTogglePasswordEditState = useCallback(() => {if (typeof APP === 'undefined' || !buttonsWithNotifyClick?.size) {setPasswordEditEnabled(!passwordEditEnabled);@@ -123,12 +67,7 @@ function PasswordSection({}}, [ buttonsWithNotifyClick, setPasswordEditEnabled, passwordEditEnabled ]);- /**- * Method to remotely submit the password from outside of the password form.- *- * @returns {void}- */- function onPasswordSave() {+ const onPasswordSave = useCallback(() => {if (formRef.current) {// @ts-ignoreconst { value } = formRef.current.querySelector('div > input');@@ -137,57 +76,30 @@ function PasswordSection({onPasswordSubmit(value);}}- }+ }, [ formRef.current, onPasswordSubmit ]);- /**- * Callback invoked to unlock the current JitsiConference.- *- * @returns {void}- */- function onPasswordRemove() {+ const onPasswordRemove = useCallback(() => {onPasswordSubmit('');- }+ }, [ onPasswordSubmit ]);- /**- * Copies the password to the clipboard.- *- * @returns {void}- */- function onPasswordCopy() {++ const onPasswordCopy = useCallback(() => {copyText(password ?? '');- }+ }, [ password ]);- /**- * Callback invoked to show the current password.- *- * @returns {void}- */- function onPasswordShow() {+ const onPasswordShow = useCallback(() => {setPasswordVisible(true);- }+ }, [ setPasswordVisible ]);- /**- * Callback invoked to hide the current password.- *- * @returns {void}- */- function onPasswordHide() {+ const onPasswordHide = useCallback(() => {setPasswordVisible(false);- }+ }, [ setPasswordVisible ]);- /**- * Method that renders the password action(s) based on the current- * locked-status of the conference.- *- * @returns {React$Element<any>}- */- function renderPasswordActions() {- if (!canEditPassword) {- return null;- }+ let actions = null;+ if (canEditPassword) {if (passwordEditEnabled) {- return (+ actions = (<><buttonclassName = 'as-link'@@ -205,10 +117,8 @@ function PasswordSection({</button></>);- }-- if (locked) {- return (+ } else if (locked) {+ actions = (<><buttonclassName = 'remove-password as-link'@@ -241,14 +151,14 @@ function PasswordSection({)}</>);+ } else {+ actions = (+ <button+ className = 'add-password as-link'+ onClick = { onTogglePasswordEditState }+ type = 'button'>{ t('info.addPassword') }</button>+ );}-- return (- <button- className = 'add-password as-link'- onClick = { onTogglePasswordEditState }- type = 'button'>{ t('info.addPassword') }</button>- );}return (@@ -269,11 +179,11 @@ function PasswordSection({visible = { passwordVisible } /></div><div className = 'security-dialog password-actions'>- { renderPasswordActions() }+ { actions }</div></div></div>);}-export default translate(PasswordSection);+export default PasswordSection;diff --git a/react/features/security/components/security-dialog/web/SecurityDialog.tsx b/react/features/security/components/security-dialog/web/SecurityDialog.tsxindex 6c4af4e193..659c7a571c 100644--- a/react/features/security/components/security-dialog/web/SecurityDialog.tsx+++ b/react/features/security/components/security-dialog/web/SecurityDialog.tsx@@ -1,9 +1,7 @@-import React, { useEffect, useState } from 'react';-import { connect } from 'react-redux';+import React from 'react';+import { useSelector } from 'react-redux';import { IReduxState } from '../../../../app/types';-import { setPassword as setPass } from '../../../../base/conference/actions';-import { IJitsiConference } from '../../../../base/conference/reducer';import { getSecurityUiConfig } from '../../../../base/config/functions.any';import { isLocalParticipantModerator } from '../../../../base/participants/functions';import Dialog from '../../../../base/ui/components/web/Dialog';@@ -18,79 +16,17 @@ export interface INotifyClick {preventExecution: boolean;}-interface IProps {-- /**- * Whether or not the current user can modify the current password.- */- _canEditPassword: boolean;-- /**- * The JitsiConference for which to display a lock state and change the- * password.- */- _conference?: IJitsiConference;-- /**- * Whether to hide the lobby password section.- */- _disableLobbyPassword?: boolean;-- /**- * Whether to hide the lobby section.- */- _isEnablingLobbyAllowed: boolean;-- /**- * The value for how the conference is locked (or undefined if not locked)- * as defined by room-lock constants.- */- _locked?: string;-- /**- * The current known password for the JitsiConference.- */- _password?: string;-- /**- * The number of digits to be used in the password.- */- _passwordNumberOfDigits?: number;-- /**- * Indicates whether e2ee will be displayed or not.- */- _showE2ee: boolean;-- /**- * Action that sets the conference password.- */- setPassword: Function;-}-/*** Component that renders the security options dialog.** @returns {React$Element<any>}*/-function SecurityDialog({- _canEditPassword,- _conference,- _disableLobbyPassword,- _isEnablingLobbyAllowed,- _locked,- _password,- _passwordNumberOfDigits,- _showE2ee,- setPassword-}: IProps) {- const [ passwordEditEnabled, setPasswordEditEnabled ] = useState(false);-- useEffect(() => {- if (passwordEditEnabled && _password) {- setPasswordEditEnabled(false);- }- }, [ _password ]);+export default function SecurityDialog() {+ const e2eeSupported = useSelector((state: IReduxState) => state['features/base/conference'].e2eeSupported);+ const disableLobbyPassword = useSelector((state: IReduxState) => getSecurityUiConfig(state)?.disableLobbyPassword);+ const _isEnablingLobbyAllowed = useSelector(isEnablingLobbyAllowed);+ const isModerator = useSelector(isLocalParticipantModerator);+ const showE2ee = Boolean(e2eeSupported) && isModerator;return (<Dialog@@ -102,24 +38,16 @@ function SecurityDialog({_isEnablingLobbyAllowed && <LobbySection />}{- !_disableLobbyPassword && (+ !disableLobbyPassword && (<>{ _isEnablingLobbyAllowed && <div className = 'separator-line' /> }- <PasswordSection- canEditPassword = { _canEditPassword }- conference = { _conference }- locked = { _locked }- password = { _password }- passwordEditEnabled = { passwordEditEnabled }- passwordNumberOfDigits = { _passwordNumberOfDigits }- setPassword = { setPassword }- setPasswordEditEnabled = { setPasswordEditEnabled } />+ <PasswordSection /></>)}{- _showE2ee ? <>- { (_isEnablingLobbyAllowed || !_disableLobbyPassword) && <div className = 'separator-line' /> }+ showE2ee ? <>+ { (_isEnablingLobbyAllowed || !disableLobbyPassword) && <div className = 'separator-line' /> }<E2EESection /></> : null}@@ -128,41 +56,3 @@ function SecurityDialog({</Dialog>);}--/**- * Maps (parts of) the Redux state to the associated props for the- * {@code SecurityDialog} component.- *- * @param {Object} state - The Redux state.- * @private- * @returns {IProps}- */-function mapStateToProps(state: IReduxState) {- const {- conference,- e2eeSupported,- locked,- password- } = state['features/base/conference'];- const { roomPasswordNumberOfDigits } = state['features/base/config'];- const { disableLobbyPassword } = getSecurityUiConfig(state);- const _isEnablingLobbyAllowed = isEnablingLobbyAllowed(state);-- const showE2ee = Boolean(e2eeSupported) && isLocalParticipantModerator(state);-- return {- _canEditPassword: isLocalParticipantModerator(state),- _conference: conference,- _dialIn: state['features/invite'],- _disableLobbyPassword: disableLobbyPassword,- _isEnablingLobbyAllowed,- _locked: locked,- _password: password,- _passwordNumberOfDigits: roomPasswordNumberOfDigits,- _showE2ee: showE2ee- };-}--const mapDispatchToProps = { setPassword: setPass };--export default connect(mapStateToProps, mapDispatchToProps)(SecurityDialog);