Skip to content

Commit

Permalink
Fix device state (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx authored Sep 21, 2021
1 parent 0469697 commit e7e1649
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions streamlit_webrtc/frontend/src/WebRtcStreamer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ interface WebRtcStreamerInnerProps {
onComponentValueChange: (newComponentValue: ComponentValue) => void;
}
const WebRtcStreamerInner: React.VFC<WebRtcStreamerInnerProps> = (props) => {
const [videoInput, setVideoInput] = useState<MediaDeviceInfo | null>(null);
const [audioInput, setAudioInput] = useState<MediaDeviceInfo | null>(null);
const [devices, setDevices] = useState<{
video: MediaDeviceInfo | null;
audio: MediaDeviceInfo | null;
}>({ video: null, audio: null });
const { state, start, stop } = useWebRtc(
props,
videoInput,
audioInput,
devices.video,
devices.audio,
props.onComponentValueChange
);

Expand All @@ -52,9 +54,7 @@ const WebRtcStreamerInner: React.VFC<WebRtcStreamerInnerProps> = (props) => {

const handleDeviceSelect = useCallback(
(video: MediaDeviceInfo | null, audio: MediaDeviceInfo | null) => {
setVideoInput(video);
setAudioInput(audio);
// this.setState({ videoInput: video, audioInput: audio });
setDevices({ video, audio });
},
[]
);
Expand Down Expand Up @@ -100,10 +100,7 @@ const WebRtcStreamerInner: React.VFC<WebRtcStreamerInnerProps> = (props) => {
videoEnabled={videoEnabled}
audioEnabled={audioEnabled}
onSelect={handleDeviceSelect}
value={{
video: videoInput,
audio: audioInput,
}}
value={devices}
/>
)}
</Box>
Expand Down

0 comments on commit e7e1649

Please sign in to comment.