Add audio tab and ability to change audio input device

This commit is contained in:
Ryan Alexander 2021-08-20 02:11:02 +10:00 committed by Paul Makles
parent 6842bdc4a5
commit a6846192de
3 changed files with 75 additions and 1 deletions

View file

@ -152,8 +152,10 @@ class VoiceStateReference {
if (navigator.mediaDevices === undefined) if (navigator.mediaDevices === undefined)
return console.log("No media devices."); // ! TODO: let the user know return console.log("No media devices."); // ! TODO: let the user know
const mediaDevice = window.localStorage.getItem("audioInputDevice");
const mediaStream = await navigator.mediaDevices.getUserMedia({ const mediaStream = await navigator.mediaDevices.getUserMedia({
audio: true, audio: mediaDevice?{deviceId: mediaDevice}:true
}); });
await this.client?.startProduce( await this.client?.startProduce(

View file

@ -15,6 +15,7 @@ import {
Flask, Flask,
User, User,
Megaphone, Megaphone,
Speaker,
} from "@styled-icons/boxicons-solid"; } from "@styled-icons/boxicons-solid";
import { Route, Switch, useHistory } from "react-router-dom"; import { Route, Switch, useHistory } from "react-router-dom";
import { LIBRARY_VERSION } from "revolt.js"; import { LIBRARY_VERSION } from "revolt.js";
@ -37,6 +38,7 @@ import { APP_VERSION } from "../../version";
import { GenericSettings } from "./GenericSettings"; import { GenericSettings } from "./GenericSettings";
import { Account } from "./panes/Account"; import { Account } from "./panes/Account";
import { Appearance } from "./panes/Appearance"; import { Appearance } from "./panes/Appearance";
import { Audio } from "./panes/Audio";
import { ExperimentsPage } from "./panes/Experiments"; import { ExperimentsPage } from "./panes/Experiments";
import { Feedback } from "./panes/Feedback"; import { Feedback } from "./panes/Feedback";
import { Languages } from "./panes/Languages"; import { Languages } from "./panes/Languages";
@ -85,6 +87,12 @@ export default function Settings() {
category: ( category: (
<Text id="app.settings.categories.client_settings" /> <Text id="app.settings.categories.client_settings" />
), ),
id: "audio",
icon: <Speaker size={20} />,
title: <Text id="app.settings.pages.audio.title" />,
},
{
id: "appearance", id: "appearance",
icon: <Palette size={20} />, icon: <Palette size={20} />,
title: <Text id="app.settings.pages.appearance.title" />, title: <Text id="app.settings.pages.appearance.title" />,
@ -141,6 +149,9 @@ export default function Settings() {
<Route path="/settings/appearance"> <Route path="/settings/appearance">
<Appearance /> <Appearance />
</Route> </Route>
<Route path="/settings/audio">
<Audio />
</Route>
<Route path="/settings/notifications"> <Route path="/settings/notifications">
<Notifications /> <Notifications />
</Route> </Route>

View file

@ -0,0 +1,61 @@
import styles from "./Panes.module.scss";
import { Text } from "preact-i18n";
import { connectState } from "../../../redux/connector";
import { voiceState, VoiceStatus } from "../../../lib/vortex/VoiceState";
import ComboBox from "../../../components/ui/ComboBox";
import {useEffect, useState} from "preact/hooks";
export function Component() {
const [mediaDevices, setMediaDevices] = useState<MediaDeviceInfo[] | undefined>(undefined);
useEffect(() => {
navigator
.mediaDevices
.enumerateDevices()
.then( devices => {
setMediaDevices(devices)
})
}, []);
return (
<>
<div>
<h3>
<Text id="app.settings.pages.audio.input_device" />
</h3>
<ComboBox
value={window.localStorage.getItem("audioInputDevice") ?? 0}
onChange={(e) => changeAudioDevice(e.currentTarget.value, "input")}>
{
mediaDevices?.filter(device => device.kind === "audioinput").map(device => {
return (
<option value={device.deviceId} key={device.deviceId}>
{device.label}
</option>
)
})
}
</ComboBox>
</div>
</>
);
}
function changeAudioDevice(deviceId: string, deviceType: string) {
if(deviceType === "input") {
window.localStorage.setItem("audioInputDevice", deviceId)
if(voiceState.isProducing("audio")) {
voiceState.stopProducing("audio");
voiceState.startProducing("audio");
}
}else if(deviceType === "output") {
window.localStorage.setItem("audioOutputDevice", deviceId)
}
}
export const Audio = connectState(Component, () => {
return;
});