venmic migration

This commit is contained in:
Vendicated 2023-10-12 02:30:58 +02:00
parent 56dd9ea2c8
commit 27f1f14fc7
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
8 changed files with 16 additions and 45 deletions

View file

@ -23,7 +23,8 @@
"watch": "pnpm build --watch"
},
"dependencies": {
"arrpc": "github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d"
"arrpc": "github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d",
"venmic": "link:../linux-virtmic"
},
"devDependencies": {
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",

View file

@ -8,6 +8,9 @@ dependencies:
arrpc:
specifier: github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d
version: github.com/OpenAsar/arrpc/89f4da610ccfac93f461826a446a17cd3b23953d
venmic:
specifier: link:../linux-virtmic
version: link:../linux-virtmic
devDependencies:
'@fal-works/esbuild-plugin-global-externals':

View file

@ -5,6 +5,7 @@
*/
import { BuildContext, BuildOptions, context } from "esbuild";
import { copyFile } from "fs/promises";
import vencordDep from "./vencordDep.mjs";
@ -34,6 +35,7 @@ async function createContext(options: BuildOptions) {
}
await Promise.all([
copyFile("./node_modules/venmic/build/Release/venmic-addon.node", "./static/dist/venmic.node"),
createContext({
...NodeCommonOpts,
entryPoints: ["src/main/index.ts"],

View file

@ -4,51 +4,21 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { ChildProcess, execFile } from "child_process";
import { ipcMain } from "electron";
import { join } from "path";
import { IpcEvents } from "shared/IpcEvents";
import { STATIC_DIR } from "shared/paths";
import { promisify } from "util";
const BIN = join(STATIC_DIR, "virtmic/vencord-virtmic");
const execFileP = promisify(execFile);
const importVenmic = () => require(join(STATIC_DIR, "dist/venmic.node")) as typeof import("venmic");
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, async () => {
return execFileP(BIN, ["--list-targets"])
.then(res =>
res.stdout
.trim()
.split("\n")
.map(s => s.trim())
.filter(Boolean)
)
.catch(e => {
console.error("virt-mic-list failed", e);
return null;
});
});
let virtMicProc: ChildProcess | null = null;
function kill() {
virtMicProc?.kill();
virtMicProc = null;
}
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, async () =>
importVenmic()
.list()
.map(m => m.name)
);
ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, target: string) => {
kill();
return new Promise<boolean>(resolve => {
virtMicProc = execFile(BIN, [target], { encoding: "utf-8" });
virtMicProc.stdout?.on("data", (chunk: string) => {
if (chunk.includes("vencord-virtmic")) resolve(true);
});
virtMicProc.on("error", () => resolve(false));
virtMicProc.on("exit", () => resolve(false));
setTimeout(() => resolve(false), 1000);
});
importVenmic().link(target);
});
ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => kill());
ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => importVenmic().unlink());

View file

@ -12,7 +12,7 @@ if (isLinux) {
async function getVirtmic() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
const audioDevice = devices.find(({ label }) => label === "vencord-virtmic");
const audioDevice = devices.find(({ label }) => label === "vencord-screen-share");
return audioDevice?.deviceId;
} catch (error) {
return null;

BIN
static/venmic.node Executable file

Binary file not shown.

View file

@ -1,5 +0,0 @@
# vencord virtmic
this is a prebuild of https://github.com/Vencord/linux-virtmic.
the source code and licensing information can be found there

Binary file not shown.