2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// From v0.4
  
						 
					
						
							
								
									
										
										
										
											2022-07-07 13:11:51 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								navigator . mediaDevices . chromiumGetDisplayMedia  =  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  navigator . mediaDevices . getDisplayMedia ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-01 22:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  sleep ( ms )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return  new  Promise ( ( resolve )  =>  setTimeout ( resolve ,  ms ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 13:11:51 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const  getAudioDevice  =  async  ( nameOfAudioDevice )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await  navigator . mediaDevices . getUserMedia ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    audio :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 11:56:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  let  audioDevice ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  while  ( audioDevice  ===  undefined )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    let  devices  =  await  navigator . mediaDevices . enumerateDevices ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    audioDevice  =  devices . find ( ( {  label  } )  =>  label  ===  nameOfAudioDevice ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! audioDevice ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 12:41:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      console . log ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ` dsa: Did not find ' ${ nameOfAudioDevice } ', trying again in 100ms ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 11:56:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await  sleep ( 100 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 12:41:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  console . log ( ` dsa: Found ' ${ nameOfAudioDevice } ' ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 13:11:51 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  return  audioDevice ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  setGetDisplayMedia ( overrideArgs  =  undefined )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  getDisplayMedia  =  async  ( ... args )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var  id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      let  myDiscordAudioSink  =  await  getAudioDevice ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "discord-screenaudio-virtmic" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      id  =  myDiscordAudioSink . deviceId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  catch  ( error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      id  =  "default" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    let  captureSystemAudioStream  =  await  navigator . mediaDevices . getUserMedia ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      audio :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // We add our audio constraints here, to get a list of supported constraints use navigator.mediaDevices.getSupportedConstraints();
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // We must capture a microphone, we use default since its the only deviceId that is the same for every Chromium user
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        deviceId :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          exact :  id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // We want auto gain control, noise cancellation and noise suppression disabled so that our stream won't sound bad
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        autoGainControl :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echoCancellation :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        noiseSuppression :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // By default Chromium sets channel count for audio devices to 1, we want it to be stereo in case we find a way for Discord to accept stereo screenshare too
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        channelCount :  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // You can set more audio constraints here, bellow are some examples
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //latency: 0,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //sampleRate: 48000,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //sampleSize: 16,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //volume: 1.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    let  [ track ]  =  captureSystemAudioStream . getAudioTracks ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  gdm  =  await  navigator . mediaDevices . chromiumGetDisplayMedia ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ... ( overrideArgs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ?  [ overrideArgs ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        :  args  ||  [ {  video :  true ,  audio :  true  } ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 13:11:51 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    gdm . addTrack ( track ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  gdm ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  navigator . mediaDevices . getDisplayMedia  =  getDisplayMedia ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								setGetDisplayMedia ( ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  clonedElements  =  [ ] ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  hiddenElements  =  [ ] ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								let  wasStreamActive  =  false ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								setInterval ( ( )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  streamActive  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    document . getElementsByClassName ( "panel-2ZFCRb activityPanel-9icbyU" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      . length  >  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( ! streamActive  &&  wasStreamActive ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    console . log ( "!discord-screenaudio-stream-stopped" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  wasStreamActive  =  streamActive ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if  ( streamActive )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    clonedElements . forEach ( ( el )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . remove ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    clonedElements . length  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    hiddenElements . forEach ( ( el )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . style . display  =  "block" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    hiddenElements . length  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-28 15:09:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  ( const  el  of  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      document . getElementsByClassName ( "actionButtons-2vEOUh" ) ? . [ 0 ] ? . children [ 1 ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      document . querySelector ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ".wrapper-3t3Yqv > div > div > div > div > .controlButton-2PMNom" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( ! el )  continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if  ( el . classList . contains ( "discord-screenaudio-cloned" ) )  continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . classList . add ( "discord-screenaudio-cloned" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      elClone  =  el . cloneNode ( true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      elClone . title  =  "Share Your Screen with Audio" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      elClone . addEventListener ( "click" ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console . log ( "!discord-screenaudio-start-stream" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const  initialDisplay  =  el . style . display ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      window . discordScreenaudioStartStream  =  ( width ,  height ,  frameRate )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        setGetDisplayMedia ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          audio :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          video :  {  width ,  height ,  frameRate  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        el . click ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        el . style . display  =  initialDisplay ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        elClone . remove ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . style . display  =  "none" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . parentNode . insertBefore ( elClone ,  el ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      clonedElements . push ( elClone ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      hiddenElements . push ( el ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 13:11:51 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-14 14:43:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // Add about text in settings
 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  if  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    document . getElementsByClassName ( "dirscordScreenaudioAboutText" ) . length  ==  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  el  of  document . getElementsByClassName ( "info-3pQQBb" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const  aboutEl  =  document . createElement ( "div" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-28 17:34:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      aboutEl . innerText  =  ` discord-screenaudio  ${ window . discordScreenaudioVersion } ` ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      aboutEl . style . fontSize  =  "12px" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      aboutEl . style . color  =  "var(--text-muted)" ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-28 17:34:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      aboutEl . style . textTransform  =  "none" ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-09 22:07:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      aboutEl . classList . add ( "dirscordScreenaudioAboutText" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      el . appendChild ( aboutEl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-14 14:43:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Remove stream settings if stream is active
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  document . getElementById ( "manage-streams-change-windows" ) ? . remove ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  document . querySelector ( ` [aria-label="Stream Settings"] ` ) ? . remove ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-26 15:48:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ,  500 ) ;  
						 
					
						
							
								
									
										
										
										
											2022-07-27 15:02:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Fix for broken discord notifications after restart
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// (https://github.com/maltejur/discord-screenaudio/issues/17)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Notification . requestPermission ( ) ;