promises-call.html (4020B)
1 <!doctype html> 2 <!-- 3 This test uses data only, and thus does not require fake media devices. 4 --> 5 6 <html> 7 <head> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <title>RTCPeerConnection Data-Only Connection Test with Promises</title> 10 </head> 11 <body> 12 <div id="log"></div> 13 <h2>iceConnectionState info</h2> 14 <div id="stateinfo"> 15 </div> 16 17 <!-- These files are in place when executing on W3C. --> 18 <script src="/resources/testharness.js"></script> 19 <script src="/resources/testharnessreport.js"></script> 20 <script type="text/javascript"> 21 var test = async_test('Can set up a basic WebRTC call with only data using promises.'); 22 23 var gFirstConnection = null; 24 var gSecondConnection = null; 25 26 var onIceCandidateToFirst = test.step_func(function(event) { 27 gSecondConnection.addIceCandidate(event.candidate); 28 }); 29 30 var onIceCandidateToSecond = test.step_func(function(event) { 31 gFirstConnection.addIceCandidate(event.candidate); 32 }); 33 34 var onIceConnectionStateChange = test.step_func(function(event) { 35 assert_equals(event.type, 'iceconnectionstatechange'); 36 var stateinfo = document.getElementById('stateinfo'); 37 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState 38 + '<br>Second: ' + gSecondConnection.iceConnectionState; 39 // Note: All these combinations are legal states indicating that the 40 // call has connected. All browsers should end up in completed/completed, 41 // but as of this moment, we've chosen to terminate the test early. 42 // TODO: Revise test to ensure completed/completed is reached. 43 if (gFirstConnection.iceConnectionState == 'connected' && 44 gSecondConnection.iceConnectionState == 'connected') { 45 test.done() 46 } 47 if (gFirstConnection.iceConnectionState == 'connected' && 48 gSecondConnection.iceConnectionState == 'completed') { 49 test.done() 50 } 51 if (gFirstConnection.iceConnectionState == 'completed' && 52 gSecondConnection.iceConnectionState == 'connected') { 53 test.done() 54 } 55 if (gFirstConnection.iceConnectionState == 'completed' && 56 gSecondConnection.iceConnectionState == 'completed') { 57 test.done() 58 } 59 }); 60 61 // This function starts the test. 62 test.step(function() { 63 gFirstConnection = new RTCPeerConnection(null); 64 test.add_cleanup(() => gFirstConnection.close()); 65 gFirstConnection.onicecandidate = onIceCandidateToFirst; 66 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; 67 68 gSecondConnection = new RTCPeerConnection(null); 69 test.add_cleanup(() => gSecondConnection.close()); 70 gSecondConnection.onicecandidate = onIceCandidateToSecond; 71 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; 72 73 // The createDataChannel is necessary and sufficient to make 74 // sure the ICE connection be attempted. 75 gFirstConnection.createDataChannel('channel'); 76 77 var atStep = 'Create offer'; 78 79 gFirstConnection.createOffer() 80 .then(function(offer) { 81 atStep = 'Set local description at first'; 82 return gFirstConnection.setLocalDescription(offer); 83 }) 84 .then(function() { 85 atStep = 'Set remote description at second'; 86 return gSecondConnection.setRemoteDescription( 87 gFirstConnection.localDescription); 88 }) 89 .then(function() { 90 atStep = 'Create answer'; 91 return gSecondConnection.createAnswer(); 92 }) 93 .then(function(answer) { 94 atStep = 'Set local description at second'; 95 return gSecondConnection.setLocalDescription(answer); 96 }) 97 .then(function() { 98 atStep = 'Set remote description at first'; 99 return gFirstConnection.setRemoteDescription( 100 gSecondConnection.localDescription); 101 }) 102 .then(function() { 103 atStep = 'Negotiation completed'; 104 }) 105 .catch(test.step_func(function(e) { 106 assert_unreached('Error ' + e.name + ': ' + e.message + 107 ' happened at step ' + atStep); 108 })); 109 }); 110 </script> 111 112 </body> 113 </html>