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

Prevent to start two broadcasts at the same time #9744

Merged
merged 7 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,56 @@ interface Props {
voiceBroadcastPreRecording: VoiceBroadcastPreRecording;
}

interface State {
showDeviceSelect: boolean;
disableStartButton: boolean;
}

export const VoiceBroadcastPreRecordingPip: React.FC<Props> = ({ voiceBroadcastPreRecording }) => {
const pipRef = useRef<HTMLDivElement | null>(null);
const { currentDevice, currentDeviceLabel, devices, setDevice } = useAudioDeviceSelection();
const [showDeviceSelect, setShowDeviceSelect] = useState<boolean>(false);
const [state, setState] = useState<State>({
showDeviceSelect: false,
disableStartButton: false,
});

const onDeviceSelect = (device: MediaDeviceInfo | null) => {
setShowDeviceSelect(false);
const onDeviceSelect = (device: MediaDeviceInfo) => {
setState((state) => ({
...state,
showDeviceSelect: false,
}));
setDevice(device);
};

const onStartBroadcastClick = () => {
setState((state) => ({
...state,
disableStartButton: true,
}));

voiceBroadcastPreRecording.start();
};

return (
<div className="mx_VoiceBroadcastBody mx_VoiceBroadcastBody--pip" ref={pipRef}>
<VoiceBroadcastHeader
linkToRoom={true}
onCloseClick={voiceBroadcastPreRecording.cancel}
onMicrophoneLineClick={() => setShowDeviceSelect(true)}
onMicrophoneLineClick={() => setState({ ...state, showDeviceSelect: true })}
room={voiceBroadcastPreRecording.room}
microphoneLabel={currentDeviceLabel}
showClose={true}
/>
<AccessibleButton
className="mx_VoiceBroadcastBody_blockButton"
kind="danger"
onClick={voiceBroadcastPreRecording.start}
onClick={onStartBroadcastClick}
disabled={state.disableStartButton}
>
<LiveIcon className="mx_Icon mx_Icon_16" />
{_t("Go live")}
</AccessibleButton>
{showDeviceSelect && (
{state.showDeviceSelect && (
<DevicesContextMenu
containerRef={pipRef}
currentDevice={currentDevice}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("VoiceBroadcastPreRecordingPip", () => {
});
jest.spyOn(MediaDeviceHandler.instance, "setDevice").mockImplementation();
preRecording = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore);
jest.spyOn(preRecording, "start").mockResolvedValue();
});

afterAll(() => {
Expand All @@ -106,6 +107,19 @@ describe("VoiceBroadcastPreRecordingPip", () => {
expect(renderResult.container).toMatchSnapshot();
});

describe("and double clicking »Go live«", () => {
beforeEach(async () => {
await act(async () => {
await userEvent.click(screen.getByText("Go live"));
await userEvent.click(screen.getByText("Go live"));
});
});

it("should call start once", () => {
expect(preRecording.start).toHaveBeenCalledTimes(1);
});
});

describe("and clicking the room name", () => {
beforeEach(async () => {
await userEvent.click(screen.getByText(room.name));
Expand Down