| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 1 | <!doctype html> |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 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> |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 10 | <h2>iceConnectionState info</h2> |
| 11 | <div id="stateinfo"> |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 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> |
| Youenn Fablet | c3be323 | 2018-11-04 03:00:23 | [diff] [blame] | 17 | <script src="/webrtc/RTCPeerConnection-helper.js"></script> |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 18 | <script type="text/javascript"> |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 19 | var test = async_test('Can set up a basic WebRTC call with no data.'); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 20 | |
| 21 | var gFirstConnection = null; |
| 22 | var gSecondConnection = null; |
| 23 | |
| 24 | var onOfferCreated = test.step_func(function(offer) { |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 25 | gFirstConnection.setLocalDescription(offer, ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 26 | failed('setLocalDescription first')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 27 | |
| 28 | // This would normally go across the application's signaling solution. |
| 29 | // In our case, the "signaling" is to call this function. |
| 30 | receiveCall(offer.sdp); |
| 31 | }); |
| 32 | |
| 33 | function receiveCall(offerSdp) { |
| 34 | |
| 35 | var parsedOffer = new RTCSessionDescription({ type: 'offer', |
| 36 | sdp: offerSdp }); |
| Youenn Fablet | 99f5891 | 2018-08-28 06:00:19 | [diff] [blame] | 37 | gSecondConnection.setRemoteDescription(parsedOffer).then( |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 38 | function() { |
| Youenn Fablet | 99f5891 | 2018-08-28 06:00:19 | [diff] [blame] | 39 | gSecondConnection.createAnswer().then(onAnswerCreated, |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 40 | failed('createAnswer')); |
| 41 | }, |
| 42 | failed('setRemoteDescription second')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | var onAnswerCreated = test.step_func(function(answer) { |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 46 | gSecondConnection.setLocalDescription(answer, ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 47 | failed('setLocalDescription second')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 48 | |
| 49 | // Similarly, this would go over the application's signaling solution. |
| 50 | handleAnswer(answer.sdp); |
| 51 | }); |
| 52 | |
| 53 | function handleAnswer(answerSdp) { |
| 54 | var parsedAnswer = new RTCSessionDescription({ type: 'answer', |
| 55 | sdp: answerSdp }); |
| Youenn Fablet | 99f5891 | 2018-08-28 06:00:19 | [diff] [blame] | 56 | gFirstConnection.setRemoteDescription(parsedAnswer).then(ignoreSuccess, |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 57 | failed('setRemoteDescription first')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 58 | }; |
| 59 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 60 | var onIceCandidateToFirst = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 61 | // If event.candidate is null = no more candidates. |
| 62 | if (event.candidate) { |
| Dominique Hazael-Massieux | 29acbc1 | 2015-06-15 09:03:34 | [diff] [blame] | 63 | gSecondConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 64 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 65 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 66 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 67 | var onIceCandidateToSecond = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 68 | if (event.candidate) { |
| Dominique Hazael-Massieux | 29acbc1 | 2015-06-15 09:03:34 | [diff] [blame] | 69 | gFirstConnection.addIceCandidate(event.candidate); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 70 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 71 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 72 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 73 | var onIceConnectionStateChange = test.step_func(function(event) { |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 74 | assert_equals(event.type, 'iceconnectionstatechange'); |
| Dominique Hazael-Massieux | 027c866 | 2015-06-16 07:45:10 | [diff] [blame] | 75 | assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnectionState of first connection"); |
| 76 | assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnectionState of second connection"); |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 77 | var stateinfo = document.getElementById('stateinfo'); |
| 78 | stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState |
| 79 | + '<br>Second: ' + gSecondConnection.iceConnectionState; |
| 80 | // Note: All these combinations are legal states indicating that the |
| 81 | // call has connected. All browsers should end up in completed/completed, |
| 82 | // but as of this moment, we've chosen to terminate the test early. |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 83 | // TODO: Revise test to ensure completed/completed is reached. |
| Harald Alvestrand | e42bf76 | 2015-05-12 08:47:56 | [diff] [blame] | 84 | if (gFirstConnection.iceConnectionState == 'connected' && |
| 85 | gSecondConnection.iceConnectionState == 'connected') { |
| 86 | test.done() |
| 87 | } |
| 88 | if (gFirstConnection.iceConnectionState == 'connected' && |
| 89 | gSecondConnection.iceConnectionState == 'completed') { |
| 90 | test.done() |
| 91 | } |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 92 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 93 | gSecondConnection.iceConnectionState == 'connected') { |
| 94 | test.done() |
| 95 | } |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 96 | if (gFirstConnection.iceConnectionState == 'completed' && |
| 97 | gSecondConnection.iceConnectionState == 'completed') { |
| 98 | test.done() |
| 99 | } |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 100 | }); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 101 | |
| 102 | // Returns a suitable error callback. |
| 103 | function failed(function_name) { |
| 104 | return test.step_func(function() { |
| 105 | assert_unreached('WebRTC called error callback for ' + function_name); |
| 106 | }); |
| 107 | } |
| 108 | |
| Harald Alvestrand | d691893 | 2015-05-12 10:19:42 | [diff] [blame] | 109 | // Returns a suitable do-nothing. |
| 110 | function ignoreSuccess(function_name) { |
| 111 | } |
| 112 | |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 113 | // This function starts the test. |
| 114 | test.step(function() { |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 115 | gFirstConnection = new RTCPeerConnection(null); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 116 | gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 117 | gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 118 | |
| Harald Alvestrand | f50f28c | 2015-05-11 12:55:42 | [diff] [blame] | 119 | gSecondConnection = new RTCPeerConnection(null); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 120 | gSecondConnection.onicecandidate = onIceCandidateToSecond; |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 121 | gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 122 | |
| Youenn Fablet | c3be323 | 2018-11-04 03:00:23 | [diff] [blame] | 123 | generateVideoReceiveOnlyOffer(gFirstConnection) |
| Philipp Hancke | c6fd45b | 2018-08-31 18:58:00 | [diff] [blame] | 124 | .then(onOfferCreated, failed('createOffer')); |
| Harald Alvestrand | 2ee104d | 2015-04-28 10:44:52 | [diff] [blame] | 125 | }); |
| 126 | </script> |
| 127 | |
| 128 | </body> |
| 129 | </html> |