/* Copyright 2022 The 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. */ import React from "react"; import { Room } from "matrix-js-sdk/src/matrix"; import classNames from "classnames"; import { LiveBadge, VoiceBroadcastLiveness } from "../.."; import { Icon as LiveIcon } from "../../../../res/img/compound/live-16px.svg"; import { Icon as MicrophoneIcon } from "../../../../res/img/compound/mic-16px.svg"; import { Icon as TimerIcon } from "../../../../res/img/compound/timer-16px.svg"; import { Icon as XIcon } from "../../../../res/img/compound/close-16px.svg"; import { _t } from "../../../languageHandler"; import RoomAvatar from "../../../components/views/avatars/RoomAvatar"; import AccessibleButton, { ButtonEvent } from "../../../components/views/elements/AccessibleButton"; import Clock from "../../../components/views/audio_messages/Clock"; import { formatTimeLeft } from "../../../DateUtils"; import Spinner from "../../../components/views/elements/Spinner"; import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; import { Action } from "../../../dispatcher/actions"; import dis from "../../../dispatcher/dispatcher"; import AccessibleTooltipButton from "../../../components/views/elements/AccessibleTooltipButton"; interface VoiceBroadcastHeaderProps { linkToRoom?: boolean; live?: VoiceBroadcastLiveness; liveBadgePosition?: "middle" | "right"; onCloseClick?: () => void; onMicrophoneLineClick?: ((e: ButtonEvent) => void | Promise) | null; room: Room; microphoneLabel?: string; showBroadcast?: boolean; showBuffering?: boolean; bufferingPosition?: "line" | "title"; timeLeft?: number; showClose?: boolean; } export const VoiceBroadcastHeader: React.FC = ({ linkToRoom = false, live = "not-live", liveBadgePosition = "right", onCloseClick = (): void => {}, onMicrophoneLineClick = null, room, microphoneLabel, showBroadcast = false, showBuffering = false, bufferingPosition = "line", showClose = false, timeLeft, }) => { const broadcast = showBroadcast && (
{_t("Voice broadcast")}
); const liveBadge = live !== "not-live" && ; const closeButton = showClose && ( ); const timeLeftLine = timeLeft && (
); const bufferingLine = showBuffering && bufferingPosition === "line" && (
{_t("Buffering…")}
); const microphoneLineClasses = classNames({ mx_VoiceBroadcastHeader_line: true, ["mx_VoiceBroadcastHeader_mic--clickable"]: onMicrophoneLineClick, }); const microphoneLine = microphoneLabel && ( {microphoneLabel} ); const onRoomAvatarOrNameClick = (): void => { dis.dispatch({ action: Action.ViewRoom, room_id: room.roomId, metricsTrigger: undefined, // other }); }; let roomAvatar = ; let roomName = (
{room.name}
{showBuffering && bufferingPosition === "title" && }
); if (linkToRoom) { roomAvatar = {roomAvatar}; roomName = {roomName}; } return (
{roomAvatar}
{roomName} {microphoneLine} {timeLeftLine} {broadcast} {bufferingLine} {liveBadgePosition === "middle" && liveBadge}
{liveBadgePosition === "right" && liveBadge} {closeButton}
); };