function AudioSetup(props) {
  const dispatch = useDispatch();
  const { audioStream, audioChoice, audioSettings } = useStudioState();

  const backToVideoSetup = () => props.previousStep();
  const enterStudio = () => props.nextStep();

  const selectNoAudio = () => enterStudio();
  const selectMicrophone = async () => {
    dispatch({ type: 'CHOOSE_AUDIO', payload: AUDIO_SOURCE_MICROPHONE });
    const deviceId = window.localStorage.getItem(LAST_AUDIO_DEVICE_KEY);
    await startAudioCapture(
      dispatch,
      deviceId ? { ideal: deviceId } : null,
      audioSettings.sampleRate
    );
    await queryMediaDevices(dispatch);
  };
  const reselectSource = () => {
    if (audioStream) {
      stopAudioCapture(audioStream, dispatch);
    }
    dispatch({ type: 'CHOOSE_AUDIO', payload: AUDIO_SOURCE_NONE });
  };

  const body = (() => {
    switch (audioChoice) {
      case AUDIO_SOURCE_NONE:
        return <SourceSelection {...{ selectNoAudio, selectMicrophone, backToVideoSetup }} />;
      case AUDIO_SOURCE_MICROPHONE:
        return <MicrophonePreview {...{ reselectSource, enterStudio }} />;
      default:
        return 'internal error :-(';
    }
  })();

  return <StepContainer>{body}</StepContainer>;
}
// selected' or 'microphone selected') and renders the correct component.
selected' or 'microphone selected') and renders the correct component.
selected ' or ' microphone selected ' ) and renders the correct component .
function AudioSetup(props) {
  const dispatch = useDispatch();
  const { audioStream, audioChoice, audioSettings } = useStudioState();
  const backToVideoSetup = () => props.previousStep();
  const enterStudio = () => props.nextStep();
  const selectNoAudio = () => enterStudio();
  const selectMicrophone = async () => {
    dispatch({ type: 'CHOOSE_AUDIO', payload: AUDIO_SOURCE_MICROPHONE });
    const deviceId = window.localStorage.getItem(LAST_AUDIO_DEVICE_KEY);
    await startAudioCapture(
      dispatch,
      deviceId ? { ideal: deviceId } : null,
      audioSettings.sampleRate
    );
    await queryMediaDevices(dispatch);
  };
  const reselectSource = () => {
    if (audioStream) {
      stopAudioCapture(audioStream, dispatch);
    }
    dispatch({ type: 'CHOOSE_AUDIO', payload: AUDIO_SOURCE_NONE });
  };
  const body = (() => {
    switch (audioChoice) {
      case AUDIO_SOURCE_NONE:
        return <SourceSelection {...{ selectNoAudio, selectMicrophone, backToVideoSetup }} />;
      case AUDIO_SOURCE_MICROPHONE:
        return <MicrophonePreview {...{ reselectSource, enterStudio }} />;
      default:
        return 'internal error :-(';
    }
  })();
  return <StepContainer>{body}</StepContainer>;
}
function AudioSetup ( props ) { const dispatch = useDispatch ( ) ; const { audioStream , audioChoice , audioSettings } = useStudioState ( ) ; const backToVideoSetup = ( ) => props . previousStep ( ) ; const enterStudio = ( ) => props . nextStep ( ) ; const selectNoAudio = ( ) => enterStudio ( ) ; const selectMicrophone = async ( ) => { dispatch ( { type : 'CHOOSE_AUDIO' , payload : AUDIO_SOURCE_MICROPHONE } ) ; const deviceId = window . localStorage . getItem ( LAST_AUDIO_DEVICE_KEY ) ; await startAudioCapture ( dispatch , deviceId ? { ideal : deviceId } : null , audioSettings . sampleRate ) ; await queryMediaDevices ( dispatch ) ; } ; const reselectSource = ( ) => { if ( audioStream ) { stopAudioCapture ( audioStream , dispatch ) ; } dispatch ( { type : 'CHOOSE_AUDIO' , payload : AUDIO_SOURCE_NONE } ) ; } ; const body = ( ( ) => { switch ( audioChoice ) { case AUDIO_SOURCE_NONE : return < SourceSelection { ... { selectNoAudio , selectMicrophone , backToVideoSetup } } / > ; case AUDIO_SOURCE_MICROPHONE : return < MicrophonePreview { ... { reselectSource , enterStudio } } / > ; default : return 'internal error :-(' ; } } ) ( ) ; return < StepContainer > { body } < / StepContainer > ; }
selected' or 'microphone selected') and renders the correct component.
selected ' or ' microphone selected ' ) and renders the correct component .