88
99'use strict' ;
1010
11- try {
12- navigator . mediaDevices . enumerateDevices ( )
13- . then ( gotSources ) ;
14- } catch ( e ) {
15- console . log ( e ) ;
16- }
17-
1811const getMediaButton = document . querySelector ( 'button#getMedia' ) ;
1912const createPeerConnectionButton = document . querySelector ( 'button#createPeerConnection' ) ;
2013const createOfferButton = document . querySelector ( 'button#createOffer' ) ;
@@ -38,8 +31,6 @@ const answerSdpTextarea = document.querySelector('div#remote textarea');
3831const audioSelect = document . querySelector ( 'select#audioSrc' ) ;
3932const videoSelect = document . querySelector ( 'select#videoSrc' ) ;
4033
41- audioSelect . onchange = videoSelect . onchange = getMedia ;
42-
4334const localVideo = document . querySelector ( 'div#local video' ) ;
4435const remoteVideo = document . querySelector ( 'div#remote video' ) ;
4536
@@ -58,32 +49,6 @@ const offerOptions = {
5849 offerToReceiveVideo : 1
5950} ;
6051
61- function gotSources ( sourceInfos ) {
62- selectSourceDiv . classList . remove ( 'hidden' ) ;
63- let audioCount = 0 ;
64- let videoCount = 0 ;
65- for ( let i = 0 ; i < sourceInfos . length ; i ++ ) {
66- const option = document . createElement ( 'option' ) ;
67- option . value = sourceInfos [ i ] . deviceId ;
68- option . text = sourceInfos [ i ] . label ;
69- if ( sourceInfos [ i ] . kind === 'audioinput' ) {
70- audioCount ++ ;
71- if ( option . text === '' ) {
72- option . text = `Audio ${ audioCount } ` ;
73- }
74- audioSelect . appendChild ( option ) ;
75- } else if ( sourceInfos [ i ] . kind === 'videoinput' ) {
76- videoCount ++ ;
77- if ( option . text === '' ) {
78- option . text = `Video ${ videoCount } ` ;
79- }
80- videoSelect . appendChild ( option ) ;
81- } else {
82- console . log ( 'unknown' , JSON . stringify ( sourceInfos [ i ] ) ) ;
83- }
84- }
85- }
86-
8752async function getMedia ( ) {
8853 getMediaButton . disabled = true ;
8954
0 commit comments