this repo has no description
1import { Patch } from "@moonlight-mod/types"; 2 3const logger = moonlight.getLogger("rocketship"); 4const getDisplayMediaOrig = navigator.mediaDevices.getDisplayMedia; 5 6async function getVenmicStream() { 7 try { 8 const devices = await navigator.mediaDevices.enumerateDevices(); 9 logger.debug("Devices:", devices); 10 11 // This isn't vencord :( 12 const id = devices.find((device) => device.label === "vencord-screen-share") 13 ?.deviceId; 14 if (!id) return null; 15 logger.debug("Got venmic device ID:", id); 16 17 const stream = await navigator.mediaDevices.getUserMedia({ 18 audio: { 19 deviceId: { 20 exact: id 21 }, 22 autoGainControl: false, 23 echoCancellation: false, 24 noiseSuppression: false 25 } 26 }); 27 28 return stream.getAudioTracks(); 29 } catch (error) { 30 logger.warn("Failed to get venmic stream:", error); 31 return null; 32 } 33} 34 35navigator.mediaDevices.getDisplayMedia = async function getDisplayMediaRedirect( 36 options 37) { 38 const orig = await getDisplayMediaOrig.call(this, options); 39 40 const venmic = await getVenmicStream(); 41 logger.debug("venmic", venmic); 42 if (venmic != null) { 43 // venmic will be proxying all audio, so we need to remove the original 44 // tracks to not cause overlap 45 for (const track of orig.getAudioTracks()) { 46 orig.removeTrack(track); 47 } 48 49 for (const track of venmic) { 50 orig.addTrack(track); 51 } 52 } 53 54 return orig; 55}; 56 57export const patches: Patch[] = [ 58 // "Ensure discord_voice is happy" 59 { 60 find: "RustAudioDeviceModule", 61 replace: [ 62 { 63 match: /static supported\(\)\{.+?\}/, 64 replacement: "static supported(){return true}" 65 }, 66 { 67 match: "supported(){return!0}", 68 replacement: "supported(){return true}" 69 } 70 ] 71 }, 72 // Remove Native media engine from list of choices 73 { 74 find: '.CAMERA_BACKGROUND_LIVE="cameraBackgroundLive"', 75 replace: { 76 match: /.\..{1,2}\.NATIVE,/, 77 replacement: "" 78 } 79 }, 80 // Stub out browser checks to allow us to use WebRTC voice on Embedded 81 { 82 find: "Using Unified Plan (", 83 replace: { 84 match: /return .\..{1,2}\?\((.)\.info/, 85 replacement: (_, logger) => `return true?(${logger}.info` 86 } 87 }, 88 { 89 find: '"UnifiedConnection("', 90 replace: { 91 match: /this\.videoSupported=.\..{1,2};/, 92 replacement: "this.videoSupported=true;" 93 } 94 }, 95 { 96 find: "OculusBrowser", 97 replace: [ 98 { 99 match: /"Firefox"===(.)\(\)\.name/g, 100 replacement: (orig, info) => `true||${orig}` 101 } 102 ] 103 }, 104 { 105 find: ".getMediaEngine().getDesktopSource", 106 replace: { 107 match: /.\.isPlatformEmbedded/, 108 replacement: "false" 109 } 110 }, 111 { 112 // Matching MediaEngineStore 113 find: '"displayName","MediaEngineStore")', 114 replace: [ 115 // Prevent loading of krisp native module by stubbing out desktop checks 116 { 117 match: 118 /\(\(0,.\.isWindows\)\(\)\|\|\(0,.\.isLinux\)\(\)\|\|.+?&&!__OVERLAY__/, 119 replacement: (orig, macosPlatformCheck) => `false&&!__OVERLAY__` 120 }, 121 // Enable loading of web krisp equivelant by replacing isWeb with true 122 { 123 match: 124 /\(0,.\.isWeb\)\(\)&&(.{1,2}\.supports\(.{1,2}\..{1,2}.NOISE_CANCELLATION)/, 125 replacement: (orig, supportsNoiseCancellation) => 126 `true&&${supportsNoiseCancellation}` 127 } 128 ] 129 } 130];