venmic migration
This commit is contained in:
parent
56dd9ea2c8
commit
27f1f14fc7
8 changed files with 16 additions and 45 deletions
|
@ -23,7 +23,8 @@
|
||||||
"watch": "pnpm build --watch"
|
"watch": "pnpm build --watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"arrpc": "github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d"
|
"arrpc": "github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d",
|
||||||
|
"venmic": "link:../linux-virtmic"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
||||||
|
|
|
@ -8,6 +8,9 @@ dependencies:
|
||||||
arrpc:
|
arrpc:
|
||||||
specifier: github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d
|
specifier: github:OpenAsar/arrpc#89f4da610ccfac93f461826a446a17cd3b23953d
|
||||||
version: github.com/OpenAsar/arrpc/89f4da610ccfac93f461826a446a17cd3b23953d
|
version: github.com/OpenAsar/arrpc/89f4da610ccfac93f461826a446a17cd3b23953d
|
||||||
|
venmic:
|
||||||
|
specifier: link:../linux-virtmic
|
||||||
|
version: link:../linux-virtmic
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@fal-works/esbuild-plugin-global-externals':
|
'@fal-works/esbuild-plugin-global-externals':
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BuildContext, BuildOptions, context } from "esbuild";
|
import { BuildContext, BuildOptions, context } from "esbuild";
|
||||||
|
import { copyFile } from "fs/promises";
|
||||||
|
|
||||||
import vencordDep from "./vencordDep.mjs";
|
import vencordDep from "./vencordDep.mjs";
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ async function createContext(options: BuildOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
copyFile("./node_modules/venmic/build/Release/venmic-addon.node", "./static/dist/venmic.node"),
|
||||||
createContext({
|
createContext({
|
||||||
...NodeCommonOpts,
|
...NodeCommonOpts,
|
||||||
entryPoints: ["src/main/index.ts"],
|
entryPoints: ["src/main/index.ts"],
|
||||||
|
|
|
@ -4,51 +4,21 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ChildProcess, execFile } from "child_process";
|
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import { join } from "path";
|
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";
|
||||||
import { promisify } from "util";
|
|
||||||
|
|
||||||
const BIN = join(STATIC_DIR, "virtmic/vencord-virtmic");
|
const importVenmic = () => require(join(STATIC_DIR, "dist/venmic.node")) as typeof import("venmic");
|
||||||
const execFileP = promisify(execFile);
|
|
||||||
|
|
||||||
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, async () => {
|
ipcMain.handle(IpcEvents.VIRT_MIC_LIST, async () =>
|
||||||
return execFileP(BIN, ["--list-targets"])
|
importVenmic()
|
||||||
.then(res =>
|
.list()
|
||||||
res.stdout
|
.map(m => m.name)
|
||||||
.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_START, (_, target: string) => {
|
ipcMain.handle(IpcEvents.VIRT_MIC_START, (_, target: string) => {
|
||||||
kill();
|
importVenmic().link(target);
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => kill());
|
ipcMain.handle(IpcEvents.VIRT_MIC_KILL, () => importVenmic().unlink());
|
||||||
|
|
|
@ -12,7 +12,7 @@ if (isLinux) {
|
||||||
async function getVirtmic() {
|
async function getVirtmic() {
|
||||||
try {
|
try {
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
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;
|
return audioDevice?.deviceId;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
return null;
|
||||||
|
|
BIN
static/venmic.node
Executable file
BIN
static/venmic.node
Executable file
Binary file not shown.
|
@ -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.
Reference in a new issue