test_multi_mics.html (1670B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="mediaStreamPlayback.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 "use strict"; 10 11 createHTML({ 12 title: "Test the ability of opening multiple microphones via gUM", 13 bug: "1238038", 14 }); 15 16 runTest(async () => { 17 // Ensure we use the real microphones by disabling loopback devices and fake devices. 18 await pushPrefs(["media.audio_loopback_dev", ""], ["media.navigator.streams.fake", false]); 19 20 try { 21 // Allow exposing microphone by calling gUM first 22 const defaultStream = await navigator.mediaDevices.getUserMedia({ audio: true }); 23 for (const track of defaultStream.getTracks()) { 24 track.stop(); 25 } 26 27 const devices = await navigator.mediaDevices.enumerateDevices(); 28 // Create constraints 29 let constraints = []; 30 devices.forEach((device) => { 31 if (device.kind === "audioinput") { 32 constraints.push({ 33 audio: { deviceId: { exact: device.deviceId } }, 34 }); 35 } 36 }); 37 if (constraints.length >= 2) { 38 // Open microphones by the constraints 39 let mediaStreams = []; 40 for (const c of constraints) { 41 let stream = await navigator.mediaDevices.getUserMedia(c); 42 mediaStreams.push(stream); 43 } 44 // Close microphones 45 for (const stream of mediaStreams) { 46 for (const track of stream.getTracks()) { 47 track.stop(); 48 } 49 } 50 mediaStreams = []; 51 } else { 52 dump("Skip test since we need at least two microphones\n"); 53 } 54 } catch (e) { 55 ok(false, e.name + ": " + e.message); 56 } 57 }); 58 </script> 59 </pre> 60 </body> 61 </html>