no-media-call.html (3902B)
1 <!doctype html> 2 3 <html> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 6 <title>RTCPeerConnection No-Media Connection Test</title> 7 </head> 8 <body> 9 <div id="log"></div> 10 <h2>iceConnectionState info</h2> 11 <div id="stateinfo"> 12 </div> 13 14 <!-- These files are in place when executing on W3C. --> 15 <script src="/resources/testharness.js"></script> 16 <script src="/resources/testharnessreport.js"></script> 17 <script src="RTCPeerConnection-helper.js"></script> 18 <script type="text/javascript"> 19 let gFirstConnection = null; 20 let gSecondConnection = null; 21 22 function onIceCandidate(otherConnction, event, reject) { 23 try { 24 otherConnction.addIceCandidate(event.candidate); 25 } catch(e) { 26 reject(e); 27 } 28 }; 29 30 function onIceConnectionStateChange(done, failed, event) { 31 try { 32 assert_equals(event.type, 'iceconnectionstatechange'); 33 assert_not_equals(gFirstConnection.iceConnectionState, "failed", 34 "iceConnectionState of first connection"); 35 assert_not_equals(gSecondConnection.iceConnectionState, "failed", 36 "iceConnectionState of second connection"); 37 const stateinfo = document.getElementById('stateinfo'); 38 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState 39 + '<br>Second: ' + gSecondConnection.iceConnectionState; 40 // Note: All these combinations are legal states indicating that the 41 // call has connected. All browsers should end up in completed/completed, 42 // but as of this moment, we've chosen to terminate the test early. 43 // TODO: Revise test to ensure completed/completed is reached. 44 const allowedStates = [ 'connected', 'completed']; 45 if (allowedStates.includes(gFirstConnection.iceConnectionState) && 46 allowedStates.includes(gSecondConnection.iceConnectionState)) { 47 done(); 48 } 49 } catch(e) { 50 failed(e); 51 } 52 }; 53 54 // This function starts the test. 55 promise_test((test) => { 56 return new Promise(async (resolve, reject) => { 57 gFirstConnection = new RTCPeerConnection(null); 58 test.add_cleanup(() => gFirstConnection.close()); 59 gFirstConnection.onicecandidate = 60 (event) => onIceCandidate(gSecondConnection, event, reject); 61 gFirstConnection.oniceconnectionstatechange = 62 (event) => onIceConnectionStateChange(resolve, reject, event); 63 64 gSecondConnection = new RTCPeerConnection(null); 65 test.add_cleanup(() => gSecondConnection.close()); 66 gSecondConnection.onicecandidate = 67 (event) => onIceCandidate(gFirstConnection, event, reject); 68 gSecondConnection.oniceconnectionstatechange = 69 (event) => onIceConnectionStateChange(resolve, reject, event); 70 71 const offer = await generateVideoReceiveOnlyOffer(gFirstConnection); 72 73 await gFirstConnection.setLocalDescription(offer); 74 75 // This would normally go across the application's signaling solution. 76 // In our case, the "signaling" is to call this function. 77 78 await gSecondConnection.setRemoteDescription({ type: 'offer', 79 sdp: offer.sdp }); 80 81 const answer = await gSecondConnection.createAnswer(); 82 83 await gSecondConnection.setLocalDescription(answer); 84 85 assert_equals(gSecondConnection.getSenders().length, 1); 86 assert_not_equals(gSecondConnection.getSenders()[0], null); 87 assert_not_equals(gSecondConnection.getSenders()[0].transport, null); 88 89 // Similarly, this would go over the application's signaling solution. 90 await gFirstConnection.setRemoteDescription({ type: 'answer', 91 sdp: answer.sdp }); 92 93 // The test is terminated by onIceConnectionStateChange() calling resolve 94 // once both connections are connected. 95 }) 96 }); 97 </script> 98 99 </body> 100 </html>