test_peerConnection_telephoneEventFirst.html (1470B)
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 title: "RTCPeerConnection with telephone-event codec first in SDP", 11 bug: "1581898", 12 visible: true 13 }); 14 15 const test = async () => { 16 const pc1 = new RTCPeerConnection(); 17 const pc2 = new RTCPeerConnection(); 18 const stream = await navigator.mediaDevices.getUserMedia({audio:true}); 19 pc1.addTrack(stream.getAudioTracks()[0], stream); 20 pc2.addTrack(stream.getAudioTracks()[0], stream); 21 22 const offer = await pc1.createOffer(); 23 await pc1.setLocalDescription(offer); 24 25 const regex = /^(m=audio \d+ [^ ]+) (.*) 101(.*)$/m; 26 27 // Rewrite offer so payload type 101 comes first 28 offer.sdp = offer.sdp.replace(regex, '$1 101 $2 $3'); 29 30 ok(offer.sdp.match(/^m=audio \d+ [^ ]+ 101 /m), 31 "Payload type 101 should be first on the m-line"); 32 33 await pc2.setRemoteDescription(offer); 34 const answer = await pc2.createAnswer(); 35 36 pc1.onicecandidate = e => { pc2.addIceCandidate(e.candidate); } 37 pc2.onicecandidate = e => { pc1.addIceCandidate(e.candidate); } 38 39 await pc1.setRemoteDescription(answer); 40 await pc2.setLocalDescription(answer); 41 await new Promise(resolve => { 42 pc1.oniceconnectionstatechange = e => { 43 if (pc1.iceConnectionState == "connected") { 44 resolve(); 45 } 46 }; 47 }); 48 await wait(1000); 49 }; 50 51 runNetworkTest(test); 52 53 </script> 54 </pre> 55 </body> 56 </html>