Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/53e00c6765aa256362fb52c08e82d189 to your computer and use it in GitHub Desktop.
Save guest271314/53e00c6765aa256362fb52c08e82d189 to your computer and use it in GitHub Desktop.
Capture monitor devices with navigator.mediaDevices.getUsermedia() at Chromium and Chrome on Linux

Chromium and Chrome refus to list or capture monitor devices on Linux

Virtual microphone using GStreamer and PulseAudio includes a section that describes a workaround using PulseAudio to create a virtual microphone where the source is a monitor device

Remap source

While the null sink automatically includes a "monitor" source, many programs know to exclude monitors when listing microphones. To work around that, the module-remap-source module lets us clone that source to another one not labeled as being a monitor:

pactl load-module module-remap-source \ master=virtmic.monitor source_name=virtmic \ source_properties=device.description=Virtual_Microphone

After we run

$ pactl load-module module-remap-source master="$(pactl list | grep -A2 '^Source #' |  grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1)" source_name=virtmic source_properties=device.description=Virtual_Microphone

we can call navigator.mediaDevices.getUserMedia({audio: true}) to get permission to access device labels, filter the devices from navigator.mediaDevices.enumerateDevices() to get the device 'Virtual_Microphone' then call navigator.mediaDevices.getUserMedia({audio: {deviceId: {exact: deviceId}}}) again, deviceId is the deviceId of 'Virtual_Microphone' with the source of theat virtual microphone set to the monitor device that we want to capture.

@guest271314
Copy link
Author

@hasrack I have no experience using Discord, see https://github.com/Lightcord/Lightcord/issues/31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment