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

Tweak broadcast pre recording state #10029

Closed
wants to merge 1 commit into from
Closed
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,33 +28,19 @@ 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 [state, setState] = useState<State>({
showDeviceSelect: false,
disableStartButton: false,
});
const [disableStartButton, setDisableStartButton] = useState<boolean>(false);
const [showDeviceSelect, setShowDeviceSelect] = useState<boolean>(false);

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

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

setDisableStartButton(() => true);
voiceBroadcastPreRecording.start();
};

Expand All @@ -63,7 +49,7 @@ export const VoiceBroadcastPreRecordingPip: React.FC<Props> = ({ voiceBroadcastP
<VoiceBroadcastHeader
linkToRoom={true}
onCloseClick={voiceBroadcastPreRecording.cancel}
onMicrophoneLineClick={(): void => setState({ ...state, showDeviceSelect: true })}
onMicrophoneLineClick={(): void => setShowDeviceSelect(() => true)}
room={voiceBroadcastPreRecording.room}
microphoneLabel={currentDeviceLabel}
showClose={true}
Expand All @@ -72,12 +58,12 @@ export const VoiceBroadcastPreRecordingPip: React.FC<Props> = ({ voiceBroadcastP
className="mx_VoiceBroadcastBody_blockButton"
kind="danger"
onClick={onStartBroadcastClick}
disabled={state.disableStartButton}
disabled={disableStartButton}
>
<LiveIcon className="mx_Icon mx_Icon_16" />
{_t("Go live")}
</AccessibleButton>
{state.showDeviceSelect && (
{showDeviceSelect && (
<DevicesContextMenu
containerRef={pipRef}
currentDevice={currentDevice}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ describe("VoiceBroadcastPreRecordingPip", () => {
});
});

it("should call start once", () => {
it("should dissable the button and call start once", () => {
expect(screen.getByText("Go live")).toHaveAttribute("disabled");
expect(preRecording.start).toHaveBeenCalledTimes(1);
});
});
Expand Down