Files
element-call/src/room/PTTButton.jsx

65 lines
1.8 KiB
React
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022 Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2022-04-22 18:05:48 -07:00
import React from "react";
2022-04-28 17:44:50 -07:00
import classNames from "classnames";
2022-04-22 18:05:48 -07:00
import styles from "./PTTButton.module.css";
import { ReactComponent as MicIcon } from "../icons/Mic.svg";
import { Avatar } from "../Avatar";
2022-04-28 17:44:50 -07:00
export function PTTButton({
showTalkOverError,
activeSpeakerUserId,
activeSpeakerDisplayName,
activeSpeakerAvatarUrl,
activeSpeakerIsLocalUser,
size,
startTalking,
stopTalking,
2022-04-28 17:44:50 -07:00
}) {
2022-04-22 18:05:48 -07:00
return (
<button
className={classNames(styles.pttButton, {
2022-04-28 17:44:50 -07:00
[styles.talking]: activeSpeakerUserId,
[styles.error]: showTalkOverError,
2022-04-22 18:05:48 -07:00
})}
onMouseDown={startTalking}
onMouseUp={stopTalking}
2022-04-22 18:05:48 -07:00
>
2022-04-28 17:44:50 -07:00
{activeSpeakerIsLocalUser || !activeSpeakerUserId ? (
2022-04-22 18:05:48 -07:00
<MicIcon
2022-04-28 17:44:50 -07:00
className={styles.micIcon}
2022-04-22 18:05:48 -07:00
width={size / 3}
height={size / 3}
/>
) : (
<Avatar
2022-04-28 17:44:50 -07:00
key={activeSpeakerUserId}
2022-04-22 18:05:48 -07:00
style={{
2022-04-28 17:44:50 -07:00
width: size - 12,
height: size - 12,
borderRadius: size - 12,
fontSize: Math.round((size - 12) / 2),
2022-04-22 18:05:48 -07:00
}}
2022-04-28 17:44:50 -07:00
src={activeSpeakerAvatarUrl}
fallback={activeSpeakerDisplayName.slice(0, 1).toUpperCase()}
2022-04-22 18:05:48 -07:00
className={styles.avatar}
/>
)}
</button>
);
}