2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
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',
|
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;
|
|
|
|
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,
|
|
|
|
onClick,
|
2020-11-19 18:11:35 +00:00
|
|
|
tooltipDirection,
|
2020-10-08 01:25:33 +00:00
|
|
|
}: PropsType): JSX.Element => {
|
|
|
|
let classNameSuffix = '';
|
|
|
|
let tooltipContent = '';
|
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');
|
|
|
|
} else if (buttonType === CallingButtonType.AUDIO_OFF) {
|
|
|
|
classNameSuffix = 'audio--off';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--audio-on');
|
|
|
|
} 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');
|
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');
|
|
|
|
} else if (buttonType === CallingButtonType.VIDEO_OFF) {
|
|
|
|
classNameSuffix = 'video--off';
|
2020-10-08 01:25:33 +00:00
|
|
|
tooltipContent = i18n('calling__button--video-on');
|
|
|
|
} 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');
|
|
|
|
} else if (buttonType === CallingButtonType.HANG_UP) {
|
|
|
|
classNameSuffix = 'hangup';
|
|
|
|
tooltipContent = i18n('calling__hangup');
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
>
|
2020-11-19 18:11:35 +00:00
|
|
|
<button
|
|
|
|
aria-label={tooltipContent}
|
|
|
|
type="button"
|
|
|
|
className={className}
|
|
|
|
onClick={onClick}
|
2020-10-13 22:20:08 +00:00
|
|
|
>
|
|
|
|
<div />
|
2020-11-19 18:11:35 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2020-10-08 01:25:33 +00:00
|
|
|
);
|
|
|
|
};
|