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

Commit

Permalink
Add small broadcast PiP
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Dec 14, 2022
1 parent e675ebd commit 7ceb9ad
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 11 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
2 changes: 1 addition & 1 deletion res/css/voice-broadcast/atoms/_VoiceBroadcastHeader.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
gap: $spacing-8;
line-height: 20px;
margin-bottom: $spacing-16;
width: 266px;
min-width: 0;
}

.mx_VoiceBroadcastHeader_content {
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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;
Expand All @@ -47,6 +48,7 @@ interface VoiceBroadcastHeaderProps {
export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
linkToRoom = false,
live = "not-live",
liveBadgePosition = "right",
onCloseClick = () => {},
onMicrophoneLineClick = null,
room,
Expand Down Expand Up @@ -127,8 +129,9 @@ export const VoiceBroadcastHeader: React.FC<VoiceBroadcastHeaderProps> = ({
{timeLeftLine}
{broadcast}
{buffering}
{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,49 @@
/*
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,
} 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}
/>
<VoiceBroadcastPlaybackControl state={playbackState} onClick={toggle} />
<AccessibleButton onClick={() => playback.stop()}>
<XIcon className="mx_Icon mx_Icon_8 mx_VoiceBroadcastBody__small-close" />
</AccessibleButton>
</div>
);
};
1 change: 1 addition & 0 deletions src/voice-broadcast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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
26 changes: 22 additions & 4 deletions test/components/views/voip/PipView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe("PipView", () => {
new RoomViewStore(defaultDispatcher, sdkContext);
};

const startVoiceBroadcastPlayback = (room: Room): MatrixEvent => {
const mkVoiceBroadcast = (room: Room): MatrixEvent => {
const infoEvent = makeVoiceBroadcastInfoStateEvent();
room.currentState.setStateEvents([infoEvent]);
defaultDispatcher.dispatch<IRoomStateEventsActionPayload>(
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("PipView", () => {

describe("when there is a voice broadcast playback and pre-recording", () => {
beforeEach(() => {
startVoiceBroadcastPlayback(room);
mkVoiceBroadcast(room);
setUpVoiceBroadcastPreRecording();
renderPip();
});
Expand All @@ -301,13 +301,31 @@ describe("PipView", () => {
});
});

describe("when listening to a voice broadcast in a room and then switching to another room", () => {
beforeEach(async () => {
setUpRoomViewStore();
viewRoom(room.roomId);
mkVoiceBroadcast(room);
await voiceBroadcastPlaybacksStore.getCurrent()?.start();
viewRoom(room2.roomId);
renderPip();
});

it("should render the small voice broadcast playback PiP", () => {
// check for the „pause voice broadcast“ button
expect(screen.getByLabelText("pause voice broadcast")).toBeInTheDocument();
// check for the absence of the „30s forward“ button
expect(screen.queryByLabelText("30s forward")).not.toBeInTheDocument();
});
});

describe("when viewing a room with a live voice broadcast", () => {
let startEvent: MatrixEvent | null = null;
let startEvent!: MatrixEvent;

beforeEach(() => {
setUpRoomViewStore();
viewRoom(room.roomId);
startEvent = startVoiceBroadcastPlayback(room);
startEvent = mkVoiceBroadcast(room);
renderPip();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
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 { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { render, RenderResult } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { mocked } from "jest-mock";

import {
VoiceBroadcastInfoState,
VoiceBroadcastLiveness,
VoiceBroadcastPlayback,
VoiceBroadcastSmallPlaybackBody,
VoiceBroadcastPlaybackState,
} from "../../../../src/voice-broadcast";
import { stubClient } from "../../../test-utils";
import { mkVoiceBroadcastInfoStateEvent } from "../../utils/test-utils";

// mock RoomAvatar, because it is doing too much fancy stuff
jest.mock("../../../../src/components/views/avatars/RoomAvatar", () => ({
__esModule: true,
default: jest.fn().mockImplementation(({ room }) => {
return <div data-testid="room-avatar">room avatar: {room.name}</div>;
}),
}));

describe("<VoiceBroadcastSmallPlaybackBody />", () => {
const userId = "@user:example.com";
const roomId = "!room:example.com";
let client: MatrixClient;
let infoEvent: MatrixEvent;
let playback: VoiceBroadcastPlayback;
let renderResult: RenderResult;

beforeAll(() => {
client = stubClient();
mocked(client.relations).mockClear();
mocked(client.relations).mockResolvedValue({ events: [] });

infoEvent = mkVoiceBroadcastInfoStateEvent(
roomId,
VoiceBroadcastInfoState.Stopped,
userId,
client.getDeviceId(),
);
});

beforeEach(() => {
playback = new VoiceBroadcastPlayback(infoEvent, client);
jest.spyOn(playback, "toggle").mockImplementation(() => Promise.resolve());
jest.spyOn(playback, "getLiveness");
jest.spyOn(playback, "getState");
});

describe("when rendering a playing broadcast", () => {
beforeEach(() => {
mocked(playback.getState).mockReturnValue(VoiceBroadcastPlaybackState.Playing);
mocked(playback.getLiveness).mockReturnValue("not-live");
renderResult = render(<VoiceBroadcastSmallPlaybackBody playback={playback} />);
});

it("should render as expected", () => {
expect(renderResult.container).toMatchSnapshot();
});
});

describe(`when rendering a stopped broadcast`, () => {
beforeEach(() => {
mocked(playback.getState).mockReturnValue(VoiceBroadcastPlaybackState.Stopped);
mocked(playback.getLiveness).mockReturnValue("not-live");
renderResult = render(<VoiceBroadcastSmallPlaybackBody playback={playback} />);
});

it("should render as expected", () => {
expect(renderResult.container).toMatchSnapshot();
});

describe("and clicking the play button", () => {
beforeEach(async () => {
await userEvent.click(renderResult.getByLabelText("play voice broadcast"));
});

it("should toggle the playback", () => {
expect(playback.toggle).toHaveBeenCalled();
});
});
});

describe.each([
[VoiceBroadcastPlaybackState.Paused, "not-live"],
[VoiceBroadcastPlaybackState.Playing, "live"],
])("when rendering a %s/%s broadcast", (state: VoiceBroadcastPlaybackState, liveness: VoiceBroadcastLiveness) => {
beforeEach(() => {
mocked(playback.getState).mockReturnValue(state);
mocked(playback.getLiveness).mockReturnValue(liveness);
renderResult = render(<VoiceBroadcastSmallPlaybackBody playback={playback} />);
});

it("should render as expected", () => {
expect(renderResult.container).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 7ceb9ad

Please sign in to comment.