test_peerConnection_addAudioTrackToExistingVideoStream.html (2131B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 createHTML({ 10 bug: "1246310", 11 title: "Renegotiation: add audio track to existing video-only stream", 12 }); 13 14 runNetworkTest(function (options) { 15 SimpleTest.requestCompleteLog(); 16 17 const audioContext = new AudioContext(); 18 // Start a tone so that the gUM call will record something even with 19 // --use-test-media-devices. TEST_AUDIO_FREQ matches the frequency of the 20 // tone in fake microphone devices. 21 const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ); 22 tone.start(); 23 24 const test = new PeerConnectionTest(options); 25 test.chain.replace("PC_LOCAL_GUM", 26 [ 27 function PC_LOCAL_GUM_ATTACH_VIDEO_ONLY(test) { 28 var localConstraints = {audio: true, video: true}; 29 test.setMediaConstraints([{video: true}], []); 30 return getUserMedia(localConstraints) 31 .then(s => test.originalGumStream = s) 32 .then(() => is(test.originalGumStream.getAudioTracks().length, 1, 33 "Should have 1 audio track")) 34 .then(() => is(test.originalGumStream.getVideoTracks().length, 1, 35 "Should have 1 video track")) 36 .then(() => test.pcLocal.attachLocalTrack( 37 test.originalGumStream.getVideoTracks()[0], 38 test.originalGumStream)); 39 }, 40 ] 41 ); 42 addRenegotiation(test.chain, 43 [ 44 function PC_LOCAL_ATTACH_SECOND_TRACK_AUDIO(test) { 45 test.setMediaConstraints([{audio: true, video: true}], []); 46 return test.pcLocal.attachLocalTrack( 47 test.originalGumStream.getAudioTracks()[0], 48 test.originalGumStream); 49 }, 50 ], 51 [ 52 function PC_CHECK_REMOTE_AUDIO_FLOW(test) { 53 return test.pcRemote.checkReceivingToneFrom(audioContext, test.pcLocal); 54 } 55 ] 56 ); 57 58 return test.run() 59 .finally(() => tone.stop()); 60 }); 61 </script> 62 </pre> 63 </body> 64 </html>