@@ -144,7 +144,7 @@ function stopRecording() {
144144
145145function handleSuccess ( stream ) {
146146 recordButton . disabled = false ;
147- console . log ( 'getUserMedia() got stream:' , stream ) ;
147+ console . log ( 'Got stream:' , stream ) ;
148148 window . stream = stream ;
149149
150150 const gumVideo = document . querySelector ( 'video#gum' ) ;
@@ -159,27 +159,37 @@ function handleSuccess(stream) {
159159 codecPreferences . disabled = false ;
160160}
161161
162- async function init ( constraints ) {
162+ async function init ( constraints , isGetDisplayMedia ) {
163163 try {
164- const stream = await navigator . mediaDevices . getUserMedia ( constraints ) ;
164+ const stream = isGetDisplayMedia ?
165+ await navigator . mediaDevices . getDisplayMedia ( constraints ) :
166+ await navigator . mediaDevices . getUserMedia ( constraints ) ;
165167 handleSuccess ( stream ) ;
166168 } catch ( e ) {
167- console . error ( 'navigator.getUserMedia error:' , e ) ;
168- errorMsgElement . innerHTML = `navigator.getUserMedia error:${ e . toString ( ) } ` ;
169+ console . error ( 'Source open error:' , e ) ;
170+ errorMsgElement . innerHTML = `Source error: ${ e . toString ( ) } ` ;
169171 }
170172}
171173
172- document . querySelector ( 'button#start' ) . addEventListener ( 'click' , async ( ) => {
173- document . querySelector ( 'button#start' ) . disabled = true ;
174+ async function onStart ( isGetDisplayMedia ) {
175+ document . querySelector ( 'button#start-gum' ) . disabled = true ;
176+ document . querySelector ( 'button#start-gdm' ) . disabled = true ;
174177 const hasEchoCancellation = document . querySelector ( '#echoCancellation' ) . checked ;
175178 const constraints = {
176179 audio : {
177- echoCancellation : { exact : hasEchoCancellation }
180+ echoCancellation : hasEchoCancellation
178181 } ,
179182 video : {
180183 width : 1280 , height : 720
181184 }
182185 } ;
183186 console . log ( 'Using media constraints:' , constraints ) ;
184- await init ( constraints ) ;
187+ await init ( constraints , isGetDisplayMedia ) ;
188+ }
189+
190+ document . querySelector ( 'button#start-gum' ) . addEventListener ( 'click' , async ( ) => {
191+ await onStart ( false ) ;
192+ } ) ;
193+ document . querySelector ( 'button#start-gdm' ) . addEventListener ( 'click' , async ( ) => {
194+ await onStart ( true ) ;
185195} ) ;
0 commit comments