clean up code
This commit is contained in:
		
							parent
							
								
									6c523503b6
								
							
						
					
					
						commit
						520b5d0a1e
					
				
					 2 changed files with 40 additions and 29 deletions
				
			
		|  | @ -6,7 +6,7 @@ | ||||||
| 
 | 
 | ||||||
| import "./screenSharePicker.css"; | import "./screenSharePicker.css"; | ||||||
| 
 | 
 | ||||||
| import { closeModal, Margins, Modals, ModalSize, openModal, useAwaiter } from "@vencord/types/utils"; | import { closeModal, Logger, Margins, Modals, ModalSize, openModal, useAwaiter } from "@vencord/types/utils"; | ||||||
| import { findStoreLazy, onceReady } from "@vencord/types/webpack"; | import { findStoreLazy, onceReady } from "@vencord/types/webpack"; | ||||||
| import { | import { | ||||||
|     Button, |     Button, | ||||||
|  | @ -53,7 +53,7 @@ interface Source { | ||||||
| 
 | 
 | ||||||
| export let currentSettings: StreamSettings | null = null; | export let currentSettings: StreamSettings | null = null; | ||||||
| 
 | 
 | ||||||
| const logger = new Vencord.Util.Logger("VesktopScreenShare"); | const logger = new Logger("VesktopScreenShare"); | ||||||
| 
 | 
 | ||||||
| addPatch({ | addPatch({ | ||||||
|     patches: [ |     patches: [ | ||||||
|  | @ -455,41 +455,48 @@ function ModalComponent({ | ||||||
|                             const frameRate = Number(settings.fps); |                             const frameRate = Number(settings.fps); | ||||||
|                             const height = Number(settings.resolution); |                             const height = Number(settings.resolution); | ||||||
|                             const width = Math.round(height * (16 / 9)); |                             const width = Math.round(height * (16 / 9)); | ||||||
|                             var conn = [...MediaEngineStore.getMediaEngine().connections].find( | 
 | ||||||
|  |                             const conn = [...MediaEngineStore.getMediaEngine().connections].find( | ||||||
|                                 connection => connection.streamUserId === UserStore.getCurrentUser().id |                                 connection => connection.streamUserId === UserStore.getCurrentUser().id | ||||||
|                             ); |                             ); | ||||||
|  | 
 | ||||||
|                             if (conn) { |                             if (conn) { | ||||||
|                                 conn.videoStreamParameters[0].maxFrameRate = frameRate; |                                 conn.videoStreamParameters[0].maxFrameRate = frameRate; | ||||||
|                                 conn.videoStreamParameters[0].maxResolution.height = height; |                                 conn.videoStreamParameters[0].maxResolution.height = height; | ||||||
|                                 conn.videoStreamParameters[0].maxResolution.width = width; |                                 conn.videoStreamParameters[0].maxResolution.width = width; | ||||||
|                             } |                             } | ||||||
|  | 
 | ||||||
|                             submit({ |                             submit({ | ||||||
|                                 id: selected!, |                                 id: selected!, | ||||||
|                                 ...settings |                                 ...settings | ||||||
|                             }); |                             }); | ||||||
| 
 | 
 | ||||||
|                             setTimeout(() => { |                             setTimeout(async () => { | ||||||
|                                 conn = [...MediaEngineStore.getMediaEngine().connections].find( |                                 const conn = [...MediaEngineStore.getMediaEngine().connections].find( | ||||||
|                                     connection => connection.streamUserId === UserStore.getCurrentUser().id |                                     connection => connection.streamUserId === UserStore.getCurrentUser().id | ||||||
|                                 ); |                                 ); | ||||||
|                                 if (conn) { |                                 if (!conn) return; | ||||||
|                                     const track = conn.input.stream.getVideoTracks()[0]; |  | ||||||
| 
 | 
 | ||||||
|                                     var constraints = track.getConstraints(); |                                 const track = conn.input.stream.getVideoTracks()[0]; | ||||||
|                                     const newConstraints = { | 
 | ||||||
|                                         ...constraints, |                                 const constraints = { | ||||||
|                                         frameRate, |                                     ...track.getConstraints(), | ||||||
|                                         width: { min: 640, ideal: width, max: width }, |                                     frameRate, | ||||||
|                                         height: { min: 480, ideal: height, max: height }, |                                     width: { min: 640, ideal: width, max: width }, | ||||||
|                                         advanced: [{ width: width, height: height }], |                                     height: { min: 480, ideal: height, max: height }, | ||||||
|                                         resizeMode: "none" |                                     advanced: [{ width: width, height: height }], | ||||||
|                                     }; |                                     resizeMode: "none" | ||||||
|                                     track.applyConstraints(newConstraints).then(() => { |                                 }; | ||||||
|                                         logger.log( | 
 | ||||||
|                                             "Applied constraints successfully. New constraints: ", |                                 try { | ||||||
|                                             track.getConstraints() |                                     await track.applyConstraints(constraints); | ||||||
|                                         ); | 
 | ||||||
|                                     }); |                                     logger.info( | ||||||
|  |                                         "Applied constraints successfully. New constraints:", | ||||||
|  |                                         track.getConstraints() | ||||||
|  |                                     ); | ||||||
|  |                                 } catch (e) { | ||||||
|  |                                     logger.error("Failed to apply constraints.", e); | ||||||
|                                 } |                                 } | ||||||
|                             }, 100); |                             }, 100); | ||||||
|                         } catch (error) { |                         } catch (error) { | ||||||
|  |  | ||||||
|  | @ -4,10 +4,11 @@ | ||||||
|  * Copyright (c) 2023 Vendicated and Vencord contributors |  * Copyright (c) 2023 Vendicated and Vencord contributors | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | import { Logger } from "@vencord/types/utils"; | ||||||
| import { currentSettings } from "renderer/components/ScreenSharePicker"; | import { currentSettings } from "renderer/components/ScreenSharePicker"; | ||||||
| import { isLinux } from "renderer/utils"; | import { isLinux } from "renderer/utils"; | ||||||
| 
 | 
 | ||||||
| const logger = new Vencord.Util.Logger("VesktopScreenFixes"); | const logger = new Logger("VesktopStreamFixes"); | ||||||
| 
 | 
 | ||||||
| if (isLinux) { | if (isLinux) { | ||||||
|     const original = navigator.mediaDevices.getDisplayMedia; |     const original = navigator.mediaDevices.getDisplayMedia; | ||||||
|  | @ -32,9 +33,9 @@ if (isLinux) { | ||||||
|         var track = stream.getVideoTracks()[0]; |         var track = stream.getVideoTracks()[0]; | ||||||
| 
 | 
 | ||||||
|         track.contentHint = String(currentSettings?.contentHint); |         track.contentHint = String(currentSettings?.contentHint); | ||||||
|         var constraints = track.getConstraints(); | 
 | ||||||
|         const newConstraints = { |         const constraints = { | ||||||
|             ...constraints, |             ...track.getConstraints(), | ||||||
|             frameRate, |             frameRate, | ||||||
|             width: { min: 640, ideal: width, max: width }, |             width: { min: 640, ideal: width, max: width }, | ||||||
|             height: { min: 480, ideal: height, max: height }, |             height: { min: 480, ideal: height, max: height }, | ||||||
|  | @ -42,9 +43,12 @@ if (isLinux) { | ||||||
|             resizeMode: "none" |             resizeMode: "none" | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         track.applyConstraints(newConstraints).then(() => { |         track | ||||||
|             logger.log("Applied constraints successfully. New constraints: ", track.getConstraints()); |             .applyConstraints(constraints) | ||||||
|         }); |             .then(() => { | ||||||
|  |                 logger.info("Applied constraints successfully. New constraints: ", track.getConstraints()); | ||||||
|  |             }) | ||||||
|  |             .catch(e => logger.error("Failed to apply constraints.", e)); | ||||||
| 
 | 
 | ||||||
|         if (id) { |         if (id) { | ||||||
|             const audio = await navigator.mediaDevices.getUserMedia({ |             const audio = await navigator.mediaDevices.getUserMedia({ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Vendicated
						Vendicated