2021-05-20 21:54:03 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
import React, { useMemo } from 'react';
|
2020-10-08 01:25:33 +00:00
|
|
|
import classNames from 'classnames';
|
2021-08-17 21:45:18 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2020-12-04 23:03:01 +00:00
|
|
|
import { Tooltip, TooltipPlacement } from './Tooltip';
|
|
|
|
import { Theme } from '../util/theme';
|
2020-10-08 01:25:33 +00:00
|
|
|
import { LocalizerType } from '../types/Util';
|
|
|
|
|
|
|
|
export enum CallingButtonType {
|
2020-10-14 16:30:50 +00:00
|
|
|
AUDIO_DISABLED = 'AUDIO_DISABLED',
|
2020-10-08 01:25:33 +00:00
|
|
|
AUDIO_OFF = 'AUDIO_OFF',
|
|
|
|
AUDIO_ON = 'AUDIO_ON',
|
|
|
|
HANG_UP = 'HANG_UP',
|
2021-05-20 21:54:03 +00:00
|
|
|
PRESENTING_DISABLED = 'PRESENTING_DISABLED',
|
|
|
|
PRESENTING_OFF = 'PRESENTING_OFF',
|
|
|
|
PRESENTING_ON = 'PRESENTING_ON',
|
2021-08-25 21:42:51 +00:00
|
|
|
RING_DISABLED = 'RING_DISABLED',
|
|
|
|
RING_OFF = 'RING_OFF',
|
|
|
|
RING_ON = 'RING_ON',
|
2020-10-14 16:30:50 +00:00
|
|
|
VIDEO_DISABLED = 'VIDEO_DISABLED',
|
2020-10-08 01:25:33 +00:00
|
|
|
VIDEO_OFF = 'VIDEO_OFF',
|
|
|
|
VIDEO_ON = 'VIDEO_ON',
|
|
|
|
}
|
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
buttonType: CallingButtonType;
|
|
|
|
i18n: LocalizerType;
|
2021-08-25 21:42:51 +00:00
|
|
|
isVisible?: boolean;
|
2020-10-08 01:25:33 +00:00
|
|
|
onClick: () => void;
|
2020-11-19 18:11:35 +00:00
|
|
|
tooltipDirection?: TooltipPlacement;
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const CallingButton = ({
|
|
|
|
buttonType,
|
|
|
|
i18n,
|
2021-08-25 21:42:51 +00:00
|
|
|
isVisible = true,
|
2020-10-08 01:25:33 +00:00
|
|
|
onClick,
|
2020-11-19 18:11:35 +00:00
|
|
|
tooltipDirection,
|
2020-10-08 01:25:33 +00:00
|
|
|
}: PropsType): JSX.Element => {
|
2021-08-17 21:45:18 +00:00
|
|
|
const uniqueButtonId = useMemo(() => uuid(), []);
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
let classNameSuffix = '';
|
|
|
|
let tooltipContent = '';
|
2021-08-17 21:45:18 +00:00
|
|
|
let label = '';
|
2021-05-20 21:54:03 +00:00
|
|
|
let disabled = false;
|
2020-10-14 16:30:50 +00:00
|
|
|
if (buttonType === CallingButtonType.AUDIO_DISABLED) {
|
2020-10-08 01:25:33 +00:00
|
|
|
classNameSuffix = 'audio--disabled';
|
2020-10-14 16:30:50 +00:00
|
|
|
tooltipContent = i18n('calling__button--audio-disabled');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--audio__label');
|
2021-05-20 21:54:03 +00:00
|
|
|
disabled = true;
|
2020-10-14 16:30:50 +00:00
|
|
|
} else if (buttonType === CallingButtonType.AUDIO_OFF) {
|
|
|
|
classNameSuffix = 'audio--off';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--audio-on');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--audio__label');
|
2020-10-08 01:25:33 +00:00
|
|
|
} else if (buttonType === CallingButtonType.AUDIO_ON) {
|
2020-10-14 16:30:50 +00:00
|
|
|
classNameSuffix = 'audio--on';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--audio-off');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--audio__label');
|
2020-10-14 16:30:50 +00:00
|
|
|
} else if (buttonType === CallingButtonType.VIDEO_DISABLED) {
|
2020-10-08 01:25:33 +00:00
|
|
|
classNameSuffix = 'video--disabled';
|
2020-10-14 16:30:50 +00:00
|
|
|
tooltipContent = i18n('calling__button--video-disabled');
|
2021-05-20 21:54:03 +00:00
|
|
|
disabled = true;
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--video__label');
|
2020-10-14 16:30:50 +00:00
|
|
|
} else if (buttonType === CallingButtonType.VIDEO_OFF) {
|
|
|
|
classNameSuffix = 'video--off';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--video-on');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--video__label');
|
2020-10-08 01:25:33 +00:00
|
|
|
} else if (buttonType === CallingButtonType.VIDEO_ON) {
|
2020-10-14 16:30:50 +00:00
|
|
|
classNameSuffix = 'video--on';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--video-off');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--video__label');
|
2020-10-08 01:25:33 +00:00
|
|
|
} else if (buttonType === CallingButtonType.HANG_UP) {
|
|
|
|
classNameSuffix = 'hangup';
|
|
|
|
tooltipContent = i18n('calling__hangup');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__hangup');
|
2021-08-25 21:42:51 +00:00
|
|
|
} else if (buttonType === CallingButtonType.RING_DISABLED) {
|
|
|
|
classNameSuffix = 'ring--disabled';
|
|
|
|
disabled = true;
|
|
|
|
tooltipContent = i18n(
|
|
|
|
'calling__button--ring__disabled-because-group-is-too-large'
|
|
|
|
);
|
|
|
|
label = i18n('calling__button--ring__label');
|
|
|
|
} else if (buttonType === CallingButtonType.RING_OFF) {
|
|
|
|
classNameSuffix = 'ring--off';
|
|
|
|
tooltipContent = i18n('calling__button--ring__on');
|
|
|
|
label = i18n('calling__button--ring__label');
|
|
|
|
} else if (buttonType === CallingButtonType.RING_ON) {
|
|
|
|
classNameSuffix = 'ring--on';
|
|
|
|
tooltipContent = i18n('calling__button--ring__off');
|
|
|
|
label = i18n('calling__button--ring__label');
|
2021-05-20 21:54:03 +00:00
|
|
|
} else if (buttonType === CallingButtonType.PRESENTING_DISABLED) {
|
|
|
|
classNameSuffix = 'presenting--disabled';
|
|
|
|
tooltipContent = i18n('calling__button--presenting-disabled');
|
|
|
|
disabled = true;
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--presenting__label');
|
2021-05-20 21:54:03 +00:00
|
|
|
} else if (buttonType === CallingButtonType.PRESENTING_ON) {
|
|
|
|
classNameSuffix = 'presenting--on';
|
|
|
|
tooltipContent = i18n('calling__button--presenting-off');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--presenting__label');
|
2021-05-20 21:54:03 +00:00
|
|
|
} else if (buttonType === CallingButtonType.PRESENTING_OFF) {
|
|
|
|
classNameSuffix = 'presenting--off';
|
|
|
|
tooltipContent = i18n('calling__button--presenting-on');
|
2021-08-17 21:45:18 +00:00
|
|
|
label = i18n('calling__button--presenting__label');
|
2020-10-08 01:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const className = classNames(
|
|
|
|
'module-calling-button__icon',
|
|
|
|
`module-calling-button__icon--${classNameSuffix}`
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2020-11-19 23:38:59 +00:00
|
|
|
<Tooltip
|
|
|
|
content={tooltipContent}
|
|
|
|
direction={tooltipDirection}
|
2020-12-04 23:03:01 +00:00
|
|
|
theme={Theme.Dark}
|
2020-11-19 23:38:59 +00:00
|
|
|
>
|
2021-08-25 21:42:51 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-calling-button__container',
|
|
|
|
!isVisible && 'module-calling-button__container--hidden'
|
|
|
|
)}
|
|
|
|
>
|
2021-08-17 21:45:18 +00:00
|
|
|
<button
|
|
|
|
aria-label={tooltipContent}
|
|
|
|
className={className}
|
|
|
|
disabled={disabled}
|
|
|
|
id={uniqueButtonId}
|
|
|
|
onClick={onClick}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<div />
|
|
|
|
</button>
|
|
|
|
<label
|
|
|
|
className="module-calling-button__label"
|
|
|
|
htmlFor={uniqueButtonId}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-11-19 18:11:35 +00:00
|
|
|
</Tooltip>
|
2020-10-08 01:25:33 +00:00
|
|
|
);
|
|
|
|
};
|