adapt to latest venmic

This commit is contained in:
Vendicated 2023-10-14 02:09:02 +02:00
parent 44aa861359
commit ed215cb518
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
3 changed files with 34 additions and 16 deletions

View file

@ -9,16 +9,28 @@ import { join } from "path";
import { IpcEvents } from "shared/IpcEvents"; import { IpcEvents } from "shared/IpcEvents";
import { STATIC_DIR } from "shared/paths"; import { STATIC_DIR } from "shared/paths";
const importVenmic = () => require(join(STATIC_DIR, "dist/venmic.node")) as typeof import("venmic"); let initialized = false;
let patchBay: import("venmic").PatchBay | undefined;
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, async () => function obtainVenmic() {
importVenmic() if (!initialized) {
.list() initialized = true;
.map(m => m.name) try {
const { PatchBay } = require(join(STATIC_DIR, "dist/venmic.node")) as typeof import("venmic");
patchBay = new PatchBay();
} catch (e) {
console.error("Failed to initialise venmic. Make sure you're using pipewire", e);
}
}
return patchBay;
}
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, () => obtainVenmic()?.list() ?? []);
ipcMain.handle(
IpcEvents.VIRT_MIC_START,
(_, target: string, mode: "include" | "exclude") => obtainVenmic()?.link(target, mode)
); );
ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, target: string) => { ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => obtainVenmic()?.unlink());
importVenmic().link(target);
});
ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => importVenmic().unlink());

View file

@ -63,7 +63,7 @@ export const VesktopNative = {
/** only available on Linux. */ /** only available on Linux. */
virtmic: { virtmic: {
list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST), list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST),
start: (target: string) => invoke<void>(IpcEvents.VIRT_MIC_START, target), start: (target: string, mode: "include" | "exclude") => invoke<void>(IpcEvents.VIRT_MIC_START, target, mode),
kill: () => invoke<void>(IpcEvents.VIRT_MIC_KILL) kill: () => invoke<void>(IpcEvents.VIRT_MIC_KILL)
}, },
arrpc: { arrpc: {

View file

@ -81,7 +81,13 @@ export function openScreenSharePicker(screens: Source[], skipPicker: boolean) {
modalProps={props} modalProps={props}
submit={async v => { submit={async v => {
didSubmit = true; didSubmit = true;
if (v.audioSource && v.audioSource !== "None") await VesktopNative.virtmic.start(v.audioSource); if (v.audioSource && v.audioSource !== "None") {
if (v.audioSource === "Entire System") {
await VesktopNative.virtmic.start("Chromium", "exclude");
} else {
await VesktopNative.virtmic.start(v.audioSource, "include");
}
}
resolve(v); resolve(v);
}} }}
close={() => { close={() => {
@ -214,22 +220,22 @@ function AudioSourcePickerLinux({
setAudioSource(s: string): void; setAudioSource(s: string): void;
}) { }) {
const [sources, _, loading] = useAwaiter(() => VesktopNative.virtmic.list(), { fallbackValue: [] }); const [sources, _, loading] = useAwaiter(() => VesktopNative.virtmic.list(), { fallbackValue: [] });
const sourcesWithNone = sources ? ["None", ...sources] : null; const allSources = sources ? ["None", "Entire System", ...sources] : null;
return ( return (
<section> <section>
<Forms.FormTitle>Audio</Forms.FormTitle> <Forms.FormTitle>Audio</Forms.FormTitle>
{loading && <Forms.FormTitle>Loading Audio sources...</Forms.FormTitle>} {loading && <Forms.FormTitle>Loading Audio sources...</Forms.FormTitle>}
{sourcesWithNone === null && ( {allSources === null && (
<Forms.FormTitle> <Forms.FormTitle>
Failed to retrieve Audio Sources. If you would like to stream with Audio, make sure you're using Failed to retrieve Audio Sources. If you would like to stream with Audio, make sure you're using
Pipewire, not Pulseaudio Pipewire, not Pulseaudio
</Forms.FormTitle> </Forms.FormTitle>
)} )}
{sourcesWithNone && ( {allSources && (
<Select <Select
options={sourcesWithNone.map(s => ({ label: s, value: s, default: s === "None" }))} options={allSources.map(s => ({ label: s, value: s, default: s === "None" }))}
isSelected={s => s === audioSource} isSelected={s => s === audioSource}
select={setAudioSource} select={setAudioSource}
serialize={String} serialize={String}