UNPKG

application-loopback

Version:
2 lines 1.25 kB
import{spawn as e}from"node:child_process";import{arch as t,platform as n}from"node:os";import r from"node:path";(n()!==`win32`||t()!==`x64`)&&console.warn(`This package is currently only available for Windows 10 x64 and later`);let i=r.resolve(__dirname,`../`,`bin`);function a(e){i=e}function o(){return r.resolve(i,`${n()}-${t()}`,`ApplicationLoopback.exe`)}function s(){return r.resolve(i,`${n()}-${t()}`,`ProcessList.exe`)}async function c(){let t=e(s(),{detached:!0,stdio:`pipe`});return t.stdout.setEncoding(`utf8`),new Promise(e=>{let n=[];t.stdout.on(`data`,e=>n.push(...e.split(` `).map(e=>{let[t,n,r]=e.replace(`\r`,``).split(`;`);if(t!==void 0&&n!==void 0&&r!==void 0)return{processId:t,hwnd:n,title:r}}).filter(e=>e!==void 0))),t.stdout.on(`close`,()=>{e(n)})})}const l=new Map;function u(t,n){if(l.has(t))throw Error(`An audio capture with process id of ${t} is already started`);let i=e(`${r.resolve(__dirname,o())}`,[t],{detached:!0,stdio:`pipe`});return l.set(t,i),i.stdout.on(`data`,e=>{n.onData?.(e)}),t}function d(e){let t=l.get(e);return t?(t.kill(),l.delete(e),!0):!1}export{c as getActiveWindowProcessIds,o as getLoopbackBinaryPath,s as getProcessListBinaryPath,a as setExecutablesRoot,u as startAudioCapture,d as stopAudioCapture};