diff --git a/src/voice-broadcast/components/molecules/VoiceBroadcastPreRecordingPip.tsx b/src/voice-broadcast/components/molecules/VoiceBroadcastPreRecordingPip.tsx index c722df8c5c..9b8ed0529f 100644 --- a/src/voice-broadcast/components/molecules/VoiceBroadcastPreRecordingPip.tsx +++ b/src/voice-broadcast/components/molecules/VoiceBroadcastPreRecordingPip.tsx @@ -28,22 +28,42 @@ interface Props { voiceBroadcastPreRecording: VoiceBroadcastPreRecording; } +interface State { + showDeviceSelect: boolean; + disableStartButton: boolean; +} + export const VoiceBroadcastPreRecordingPip: React.FC = ({ voiceBroadcastPreRecording }) => { const pipRef = useRef(null); const { currentDevice, currentDeviceLabel, devices, setDevice } = useAudioDeviceSelection(); - const [showDeviceSelect, setShowDeviceSelect] = useState(false); + const [state, setState] = useState({ + 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 (
setShowDeviceSelect(true)} + onMicrophoneLineClick={() => setState({ ...state, showDeviceSelect: true })} room={voiceBroadcastPreRecording.room} microphoneLabel={currentDeviceLabel} showClose={true} @@ -51,12 +71,13 @@ export const VoiceBroadcastPreRecordingPip: React.FC = ({ voiceBroadcastP {_t("Go live")} - {showDeviceSelect && ( + {state.showDeviceSelect && ( { }); jest.spyOn(MediaDeviceHandler.instance, "setDevice").mockImplementation(); preRecording = new VoiceBroadcastPreRecording(room, sender, client, playbacksStore, recordingsStore); + jest.spyOn(preRecording, "start").mockResolvedValue(); }); afterAll(() => { @@ -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));