Change devices in room setup screen

This commit is contained in:
Robert Long
2021-11-29 14:35:32 -08:00
parent 4588cca2b8
commit 9a5f40baa0

View File

@@ -182,6 +182,7 @@ export function GroupCallView({ client, groupCall, simpleGrid }) {
} else { } else {
return ( return (
<RoomSetupView <RoomSetupView
client={client}
hasLocalParticipant={hasLocalParticipant} hasLocalParticipant={hasLocalParticipant}
roomName={groupCall.room.name} roomName={groupCall.room.name}
state={state} state={state}
@@ -218,6 +219,7 @@ export function EnteringRoomView() {
} }
function RoomSetupView({ function RoomSetupView({
client,
roomName, roomName,
state, state,
onInitLocalCallFeed, onInitLocalCallFeed,
@@ -232,6 +234,15 @@ function RoomSetupView({
const { stream } = useCallFeed(localCallFeed); const { stream } = useCallFeed(localCallFeed);
const videoRef = useMediaStream(stream, true); const videoRef = useMediaStream(stream, true);
const {
audioInput,
audioInputs,
setAudioInput,
videoInput,
videoInputs,
setVideoInput,
} = useMediaHandler(client);
useEffect(() => { useEffect(() => {
onInitLocalCallFeed(); onInitLocalCallFeed();
}, [onInitLocalCallFeed]); }, [onInitLocalCallFeed]);
@@ -263,14 +274,32 @@ function RoomSetupView({
</div> </div>
{state === GroupCallState.LocalCallFeedInitialized && ( {state === GroupCallState.LocalCallFeedInitialized && (
<div className={styles.previewButtons}> <div className={styles.previewButtons}>
<DropdownButton
value={audioInput}
onChange={({ value }) => setAudioInput(value)}
options={audioInputs.map(({ label, deviceId }) => ({
label,
value: deviceId,
}))}
>
<MicButton <MicButton
muted={microphoneMuted} muted={microphoneMuted}
onClick={toggleMicrophoneMuted} onClick={toggleMicrophoneMuted}
/> />
</DropdownButton>
<DropdownButton
value={videoInput}
onChange={({ value }) => setVideoInput(value)}
options={videoInputs.map(({ label, deviceId }) => ({
label,
value: deviceId,
}))}
>
<VideoButton <VideoButton
enabled={localVideoMuted} enabled={localVideoMuted}
onClick={toggleLocalVideoMuted} onClick={toggleLocalVideoMuted}
/> />
</DropdownButton>
</div> </div>
)} )}
<Button <Button
@@ -298,6 +327,8 @@ function useMediaHandler(client) {
}); });
useEffect(() => { useEffect(() => {
const mediaHandler = client.getMediaHandler();
function updateDevices() { function updateDevices() {
navigator.mediaDevices.enumerateDevices().then((devices) => { navigator.mediaDevices.enumerateDevices().then((devices) => {
const audioInputs = devices.filter( const audioInputs = devices.filter(
@@ -308,7 +339,8 @@ function useMediaHandler(client) {
); );
setState((prevState) => ({ setState((prevState) => ({
...prevState, audioInput: mediaHandler.audioInput,
videoInput: mediaHandler.videoInput,
audioInputs, audioInputs,
videoInputs, videoInputs,
})); }));
@@ -317,9 +349,14 @@ function useMediaHandler(client) {
updateDevices(); updateDevices();
mediaHandler.on("MediaHandler.localStreamsChanged", updateDevices);
navigator.mediaDevices.addEventListener("devicechange", updateDevices); navigator.mediaDevices.addEventListener("devicechange", updateDevices);
return () => { return () => {
mediaHandler.removeListener(
"MediaHandler.localStreamsChanged",
updateDevices
);
navigator.mediaDevices.removeEventListener("devicechange", updateDevices); navigator.mediaDevices.removeEventListener("devicechange", updateDevices);
}; };
}, []); }, []);