Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Implement small broadcast PiP (#9755)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 authored Dec 15, 2022
1 parent 9f795a4 commit ab560bb
Show file tree
Hide file tree
Showing 21 changed files with 938 additions and 74 deletions.
2 changes: 1 addition & 1 deletion res/css/voice-broadcast/atoms/_LiveBadge.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
background-color: $alert;
border-radius: 2px;
color: $live-badge-color;
display: flex;
display: inline-flex;
font-size: $font-12px;
font-weight: $font-semi-bold;
gap: $spacing-4;
Expand Down
1 change: 1 addition & 0 deletions res/css/voice-broadcast/atoms/_VoiceBroadcastControl.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
border-radius: 50%;
color: $secondary-content;
display: flex;
flex: 0 0 32px;
height: 32px;
justify-content: center;
width: 32px;
Expand Down
10 changes: 9 additions & 1 deletion res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ limitations under the License.
gap: $spacing-8;
line-height: 20px;
margin-bottom: $spacing-16;
width: 266px;
min-width: 0;
}

.mx_VoiceBroadcastHeader_content {
flex-grow: 1;
min-width: 0;
}

.mx_VoiceBroadcastHeader_room_wrapper {
align-items: center;
display: flex;
gap: 4px;
justify-content: flex-start;
}

.mx_VoiceBroadcastHeader_room {
font-size: $font-12px;
font-weight: $font-semi-bold;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
25 changes: 25 additions & 0 deletions res/css/voice-broadcast/molecules/_VoiceBroadcastBody.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
display: inline-block;
font-size: $font-12px;
padding: $spacing-12;
width: 271px;

.mx_Clock {
line-height: 1;
Expand All @@ -32,6 +33,24 @@ limitations under the License.
box-shadow: 0 2px 8px 0 #0000004a;
}

.mx_VoiceBroadcastBody--small {
display: flex;
gap: $spacing-8;
width: 192px;

.mx_VoiceBroadcastHeader {
margin-bottom: 0;
}

.mx_VoiceBroadcastControl {
align-self: center;
}

.mx_LiveBadge {
margin-top: 4px;
}
}

.mx_VoiceBroadcastBody_divider {
background-color: $quinary-content;
border: 0;
Expand All @@ -56,3 +75,9 @@ limitations under the License.
display: flex;
gap: $spacing-8;
}

.mx_VoiceBroadcastBody__small-close {
right: 8px;
position: absolute;
top: 8px;
}
11 changes: 10 additions & 1 deletion src/components/views/voip/PipView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
VoiceBroadcastPreRecordingPip,
VoiceBroadcastRecording,
VoiceBroadcastRecordingPip,
VoiceBroadcastSmallPlaybackBody,
} from "../../../voice-broadcast";
import { useCurrentVoiceBroadcastPlayback } from "../../../voice-broadcast/hooks/useCurrentVoiceBroadcastPlayback";

Expand Down Expand Up @@ -335,9 +336,17 @@ class PipView extends React.Component<IProps, IState> {
}

private createVoiceBroadcastPlaybackPipContent(voiceBroadcastPlayback: VoiceBroadcastPlayback): CreatePipChildren {
if (this.state.viewedRoomId === voiceBroadcastPlayback.infoEvent.getRoomId()) {
return ({ onStartMoving }) => (
<div onMouseDown={onStartMoving}>
<VoiceBroadcastPlaybackBody playback={voiceBroadcastPlayback} pip={true} />
</div>
);
}

return ({ onStartMoving }) => (
<div onMouseDown={onStartMoving}>
<VoiceBroadcastPlaybackBody playback={voiceBroadcastPlayback} pip={true} />
<VoiceBroadcastSmallPlaybackBody playback={voiceBroadcastPlayback} />
</div>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,16 @@
"Stop live broadcasting?": "Stop live broadcasting?",
"Are you sure you want to stop your live broadcast?This will end the broadcast and the full recording will be available in the room.": "Are you sure you want to stop your live broadcast?This will end the broadcast and the full recording will be available in the room.",
"Yes, stop broadcast": "Yes, stop broadcast",
"play voice broadcast": "play voice broadcast",
"resume voice broadcast": "resume voice broadcast",
"pause voice broadcast": "pause voice broadcast",
"30s backward": "30s backward",
"30s forward": "30s forward",
"Go live": "Go live",
"resume voice broadcast": "resume voice broadcast",
"pause voice broadcast": "pause voice broadcast",
"Change input device": "Change input device",
"Live": "Live",
"Voice broadcast": "Voice broadcast",
"Buffering…": "Buffering…",
"play voice broadcast": "play voice broadcast",
"Cannot reach homeserver": "Cannot reach homeserver",
"Ensure you have a stable internet connection, or get in touch with the server admin": "Ensure you have a stable internet connection, or get in touch with the server admin",
"Your %(brand)s is misconfigured": "Your %(brand)s is misconfigured",
Expand Down
18 changes: 14 additions & 4 deletions src/voice-broadcast/components/atoms/VoiceBroadcastHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,29 @@ import AccessibleTooltipButton from "../../../components/views/elements/Accessib
interface VoiceBroadcastHeaderProps {
linkToRoom?: boolean;
live?: VoiceBroadcastLiveness;
liveBadgePosition?: "middle" | "right";
onCloseClick?: () => void;
onMicrophoneLineClick?: ((e: ButtonEvent) => void | Promise<void>) | null;
room: Room;
microphoneLabel?: string;
showBroadcast?: boolean;
showBuffering?: boolean;
bufferingPosition?: "line" | "title";
timeLeft?: number;
showClose?: boolean;
}

export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
linkToRoom = false,
live = "not-live",
liveBadgePosition = "right",
onCloseClick = () => {},
onMicrophoneLineClick = null,
room,
microphoneLabel,
showBroadcast = false,
showBuffering = false,
bufferingPosition = "line",
showClose = false,
timeLeft,
}) => {
Expand All @@ -78,7 +82,7 @@ export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
</div>
);

const buffering = showBuffering && (
const bufferingLine = showBuffering && bufferingPosition === "line" && (
<div className="mx_VoiceBroadcastHeader_line">
<Spinner w={14} h={14} />
{_t("Buffering…")}
Expand Down Expand Up @@ -110,7 +114,12 @@ export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
};

let roomAvatar = <RoomAvatar room={room} width={32} height={32} />;
let roomName = <div className="mx_VoiceBroadcastHeader_room">{room.name}</div>;
let roomName = (
<div className="mx_VoiceBroadcastHeader_room_wrapper">
<div className="mx_VoiceBroadcastHeader_room">{room.name}</div>
{showBuffering && bufferingPosition === "title" && <Spinner w={12} h={12} />}
</div>
);

if (linkToRoom) {
roomAvatar = <AccessibleButton onClick={onRoomAvatarOrNameClick}>{roomAvatar}</AccessibleButton>;
Expand All @@ -126,9 +135,10 @@ export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
{microphoneLine}
{timeLeftLine}
{broadcast}
{buffering}
{bufferingLine}
{liveBadgePosition === "middle" && liveBadge}
</div>
{liveBadge}
{liveBadgePosition === "right" && liveBadge}
{closeButton}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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 { Icon as PlayIcon } from "../../../../res/img/element-icons/play.svg";
import { Icon as PauseIcon } from "../../../../res/img/element-icons/pause.svg";
import { _t } from "../../../languageHandler";
import { VoiceBroadcastControl, VoiceBroadcastPlaybackState } from "../..";

interface Props {
onClick: () => void;
state: VoiceBroadcastPlaybackState;
}

export const VoiceBroadcastPlaybackControl: React.FC<Props> = ({ onClick, state }) => {
let controlIcon: React.FC<React.SVGProps<SVGSVGElement>>;
let controlLabel: string;
let className = "";

switch (state) {
case VoiceBroadcastPlaybackState.Stopped:
controlIcon = PlayIcon;
className = "mx_VoiceBroadcastControl-play";
controlLabel = _t("play voice broadcast");
break;
case VoiceBroadcastPlaybackState.Paused:
controlIcon = PlayIcon;
className = "mx_VoiceBroadcastControl-play";
controlLabel = _t("resume voice broadcast");
break;
case VoiceBroadcastPlaybackState.Buffering:
case VoiceBroadcastPlaybackState.Playing:
controlIcon = PauseIcon;
controlLabel = _t("pause voice broadcast");
break;
}

return <VoiceBroadcastControl className={className} label={controlLabel} icon={controlIcon} onClick={onClick} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import React, { ReactElement } from "react";
import classNames from "classnames";

import {
VoiceBroadcastControl,
VoiceBroadcastHeader,
VoiceBroadcastPlayback,
VoiceBroadcastPlaybackControl,
VoiceBroadcastPlaybackState,
} from "../..";
import { useVoiceBroadcastPlayback } from "../../hooks/useVoiceBroadcastPlayback";
import { Icon as PlayIcon } from "../../../../res/img/element-icons/play.svg";
import { Icon as PauseIcon } from "../../../../res/img/element-icons/pause.svg";
import { Icon as Back30sIcon } from "../../../../res/img/element-icons/Back30s.svg";
import { Icon as Forward30sIcon } from "../../../../res/img/element-icons/Forward30s.svg";
import { _t } from "../../../languageHandler";
Expand All @@ -43,32 +41,6 @@ interface VoiceBroadcastPlaybackBodyProps {
export const VoiceBroadcastPlaybackBody: React.FC<VoiceBroadcastPlaybackBodyProps> = ({ pip = false, playback }) => {
const { times, liveness, playbackState, room, sender, toggle } = useVoiceBroadcastPlayback(playback);

let controlIcon: React.FC<React.SVGProps<SVGSVGElement>>;
let controlLabel: string;
let className = "";

switch (playbackState) {
case VoiceBroadcastPlaybackState.Stopped:
controlIcon = PlayIcon;
className = "mx_VoiceBroadcastControl-play";
controlLabel = _t("play voice broadcast");
break;
case VoiceBroadcastPlaybackState.Paused:
controlIcon = PlayIcon;
className = "mx_VoiceBroadcastControl-play";
controlLabel = _t("resume voice broadcast");
break;
case VoiceBroadcastPlaybackState.Buffering:
case VoiceBroadcastPlaybackState.Playing:
controlIcon = PauseIcon;
controlLabel = _t("pause voice broadcast");
break;
}

const control = (
<VoiceBroadcastControl className={className} label={controlLabel} icon={controlIcon} onClick={toggle} />
);

let seekBackwardButton: ReactElement | null = null;
let seekForwardButton: ReactElement | null = null;

Expand Down Expand Up @@ -107,7 +79,7 @@ export const VoiceBroadcastPlaybackBody: React.FC<VoiceBroadcastPlaybackBodyProp
/>
<div className="mx_VoiceBroadcastBody_controls">
{seekBackwardButton}
{control}
<VoiceBroadcastPlaybackControl state={playbackState} onClick={toggle} />
{seekForwardButton}
</div>
<SeekBar playback={playback} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
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 {
VoiceBroadcastHeader,
VoiceBroadcastPlayback,
VoiceBroadcastPlaybackControl,
VoiceBroadcastPlaybackState,
} from "../..";
import AccessibleButton from "../../../components/views/elements/AccessibleButton";
import { useVoiceBroadcastPlayback } from "../../hooks/useVoiceBroadcastPlayback";
import { Icon as XIcon } from "../../../../res/img/element-icons/cancel-rounded.svg";

interface VoiceBroadcastSmallPlaybackBodyProps {
playback: VoiceBroadcastPlayback;
}

export const VoiceBroadcastSmallPlaybackBody: React.FC<VoiceBroadcastSmallPlaybackBodyProps> = ({ playback }) => {
const { liveness, playbackState, room, sender, toggle } = useVoiceBroadcastPlayback(playback);
return (
<div className="mx_VoiceBroadcastBody mx_VoiceBroadcastBody--pip mx_VoiceBroadcastBody--small">
<VoiceBroadcastHeader
linkToRoom={true}
live={liveness}
liveBadgePosition="middle"
microphoneLabel={sender?.name}
room={room}
showBuffering={playbackState === VoiceBroadcastPlaybackState.Buffering}
bufferingPosition="title"
/>
<VoiceBroadcastPlaybackControl state={playbackState} onClick={toggle} />
<AccessibleButton onClick={() => playback.stop()}>
<XIcon className="mx_Icon mx_Icon_8 mx_VoiceBroadcastBody__small-close" />
</AccessibleButton>
</div>
);
};
2 changes: 2 additions & 0 deletions src/voice-broadcast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export * from "./components/VoiceBroadcastBody";
export * from "./components/atoms/LiveBadge";
export * from "./components/atoms/VoiceBroadcastControl";
export * from "./components/atoms/VoiceBroadcastHeader";
export * from "./components/atoms/VoiceBroadcastPlaybackControl";
export * from "./components/atoms/VoiceBroadcastRoomSubtitle";
export * from "./components/molecules/VoiceBroadcastPlaybackBody";
export * from "./components/molecules/VoiceBroadcastSmallPlaybackBody";
export * from "./components/molecules/VoiceBroadcastPreRecordingPip";
export * from "./components/molecules/VoiceBroadcastRecordingBody";
export * from "./components/molecules/VoiceBroadcastRecordingPip";
Expand Down
Loading

0 comments on commit ab560bb

Please sign in to comment.