| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <!-- | |
| 3 This test uses the legacy callback API with no media, 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 No-Media Connection Test</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 no data.'); | |
| 22 | |
| 23 var gFirstConnection = null; | |
| 24 var gSecondConnection = null; | |
| 25 | |
| 26 var onOfferCreated = test.step_func(function(offer) { | |
| 27 gFirstConnection.setLocalDescription(offer, ignoreSuccess, | |
| 28 failed('setLocalDescription first')); | |
| 29 | |
| 30 // This would normally go across the application's signaling solution. | |
| 31 // In our case, the "signaling" is to call this function. | |
| 32 receiveCall(offer.sdp); | |
| 33 }); | |
| 34 | |
| 35 function receiveCall(offerSdp) { | |
| 36 | |
| 37 var parsedOffer = new RTCSessionDescription({ type: 'offer', | |
| 38 sdp: offerSdp }); | |
| 39 // These functions use the legacy interface extensions to RTCPeerConnection. | |
| 40 gSecondConnection.setRemoteDescription(parsedOffer, | |
| 41 function() { | |
| 42 gSecondConnection.createAnswer(onAnswerCreated, | |
| 43 failed('createAnswer')); | |
| 44 }, | |
| 45 failed('setRemoteDescription second')); | |
| 46 }; | |
| 47 | |
| 48 var onAnswerCreated = test.step_func(function(answer) { | |
| 49 gSecondConnection.setLocalDescription(answer, ignoreSuccess, | |
| 50 failed('setLocalDescription second')); | |
| 51 | |
| 52 // Similarly, this would go over the application's signaling solution. | |
| 53 handleAnswer(answer.sdp); | |
| 54 }); | |
| 55 | |
| 56 function handleAnswer(answerSdp) { | |
| 57 var parsedAnswer = new RTCSessionDescription({ type: 'answer', | |
| 58 sdp: answerSdp }); | |
| 59 gFirstConnection.setRemoteDescription(parsedAnswer, ignoreSuccess, | |
| 60 failed('setRemoteDescription first')); | |
| 61 }; | |
| 62 | |
| 63 var onIceCandidateToFirst = test.step_func(function(event) { | |
| 64 // If event.candidate is null = no more candidates. | |
| 65 if (event.candidate) { | |
| 66 gSecondConnection.addIceCandidate(event.candidate); | |
| 67 } | |
| 68 }); | |
| 69 | |
| 70 var onIceCandidateToSecond = test.step_func(function(event) { | |
| 71 if (event.candidate) { | |
| 72 gFirstConnection.addIceCandidate(event.candidate); | |
| 73 } | |
| 74 }); | |
| 75 | |
| 76 var onRemoteStream = test.step_func(function(event) { | |
| 77 assert_unreached('WebRTC received a stream when there was none'); | |
| 78 }); | |
| 79 | |
| 80 var onIceConnectionStateChange = test.step_func(function(event) { | |
| 81 assert_equals(event.type, 'iceconnectionstatechange'); | |
| 82 assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnect
ionState of first connection"); | |
| 83 assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnec
tionState of second connection"); | |
| 84 var stateinfo = document.getElementById('stateinfo'); | |
| 85 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState | |
| 86 + '<br>Second: ' + gSecondConnection.iceConnectionState; | |
| 87 // Note: All these combinations are legal states indicating that the | |
| 88 // call has connected. All browsers should end up in completed/completed, | |
| 89 // but as of this moment, we've chosen to terminate the test early. | |
| 90 // TODO: Revise test to ensure completed/completed is reached. | |
| 91 if (gFirstConnection.iceConnectionState == 'connected' && | |
| 92 gSecondConnection.iceConnectionState == 'connected') { | |
| 93 test.done() | |
| 94 } | |
| 95 if (gFirstConnection.iceConnectionState == 'connected' && | |
| 96 gSecondConnection.iceConnectionState == 'completed') { | |
| 97 test.done() | |
| 98 } | |
| 99 if (gFirstConnection.iceConnectionState == 'completed' && | |
| 100 gSecondConnection.iceConnectionState == 'connected') { | |
| 101 test.done() | |
| 102 } | |
| 103 if (gFirstConnection.iceConnectionState == 'completed' && | |
| 104 gSecondConnection.iceConnectionState == 'completed') { | |
| 105 test.done() | |
| 106 } | |
| 107 }); | |
| 108 | |
| 109 // Returns a suitable error callback. | |
| 110 function failed(function_name) { | |
| 111 return test.step_func(function() { | |
| 112 assert_unreached('WebRTC called error callback for ' + function_name); | |
| 113 }); | |
| 114 } | |
| 115 | |
| 116 // Returns a suitable do-nothing. | |
| 117 function ignoreSuccess(function_name) { | |
| 118 } | |
| 119 | |
| 120 // This function starts the test. | |
| 121 test.step(function() { | |
| 122 gFirstConnection = new RTCPeerConnection(null); | |
| 123 gFirstConnection.onicecandidate = onIceCandidateToFirst; | |
| 124 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; | |
| 125 | |
| 126 gSecondConnection = new RTCPeerConnection(null); | |
| 127 gSecondConnection.onicecandidate = onIceCandidateToSecond; | |
| 128 gSecondConnection.onaddstream = onRemoteStream; | |
| 129 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; | |
| 130 | |
| 131 // The offerToReceiveVideo is necessary and sufficient to make | |
| 132 // an actual connection. | |
| 133 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'), | |
| 134 {offerToReceiveVideo: true}); | |
| 135 }); | |
| 136 </script> | |
| 137 | |
| 138 </body> | |
| 139 </html> | |
| OLD | NEW |