Created
September 11, 2021 23:16
-
-
Save edisionnano/d4d75ba4ab06910be5b9728a01a73cb2 to your computer and use it in GitHub Desktop.
screenshare.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Screenshare with Audio | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Screenshare with Audion on Discord | |
// @author Guest271314 | |
// @match https://discord.com/* | |
// @icon https://www.google.com/s2/favicons?domain=discord.com | |
// @grant none | |
// ==/UserScript== | |
navigator.mediaDevices.chromiumGetDisplayMedia = | |
navigator.mediaDevices.getDisplayMedia; | |
async function getDisplayMedia( | |
{ video: video, audio: audio } = { video: true, audio: true } | |
) { | |
let captureSystemAudioStream = await navigator.mediaDevices.getUserMedia({ | |
audio: true, | |
}); | |
let [track] = captureSystemAudioStream.getAudioTracks(); | |
const devices = await navigator.mediaDevices.enumerateDevices(); | |
const device = devices.find(({ label }) => label === 'virtmic'); | |
if (track.getSettings().deviceId !== device.deviceId) { | |
track.stop(); | |
captureSystemAudioStream = await navigator.mediaDevices.getUserMedia({ | |
audio: { deviceId: { exact: device.deviceId } }, | |
}); | |
[track] = captureSystemAudioStream.getAudioTracks(); | |
} | |
const gdm = await navigator.mediaDevices.chromiumGetDisplayMedia({ | |
video: true, | |
audio: true, | |
}); | |
gdm.addTrack(track); | |
return gdm; | |
} | |
navigator.mediaDevices.getDisplayMedia = getDisplayMedia; | |
var gdm = await navigator.mediaDevices.getDisplayMedia({ | |
audio: true, | |
video: true, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment