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