Change devices in room setup screen
This commit is contained in:
55
src/Room.jsx
55
src/Room.jsx
@@ -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}>
|
||||||
<MicButton
|
<DropdownButton
|
||||||
muted={microphoneMuted}
|
value={audioInput}
|
||||||
onClick={toggleMicrophoneMuted}
|
onChange={({ value }) => setAudioInput(value)}
|
||||||
/>
|
options={audioInputs.map(({ label, deviceId }) => ({
|
||||||
<VideoButton
|
label,
|
||||||
enabled={localVideoMuted}
|
value: deviceId,
|
||||||
onClick={toggleLocalVideoMuted}
|
}))}
|
||||||
/>
|
>
|
||||||
|
<MicButton
|
||||||
|
muted={microphoneMuted}
|
||||||
|
onClick={toggleMicrophoneMuted}
|
||||||
|
/>
|
||||||
|
</DropdownButton>
|
||||||
|
<DropdownButton
|
||||||
|
value={videoInput}
|
||||||
|
onChange={({ value }) => setVideoInput(value)}
|
||||||
|
options={videoInputs.map(({ label, deviceId }) => ({
|
||||||
|
label,
|
||||||
|
value: deviceId,
|
||||||
|
}))}
|
||||||
|
>
|
||||||
|
<VideoButton
|
||||||
|
enabled={localVideoMuted}
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user