blob: 10933fae4c396198ade091894ea8538d1a174eaf [file] [log] [blame]
Harald Alvestrand2ee104d2015-04-28 10:44:521<!doctype html>
Harald Alvestrand2ee104d2015-04-28 10:44:522
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 Alvestrande42bf762015-05-12 08:47:5610 <h2>iceConnectionState info</h2>
11 <div id="stateinfo">
Harald Alvestrand2ee104d2015-04-28 10:44:5212 </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 Fabletc3be3232018-11-04 03:00:2317 <script src="/webrtc/RTCPeerConnection-helper.js"></script>
Harald Alvestrand2ee104d2015-04-28 10:44:5218 <script type="text/javascript">
Harald Alvestrandf50f28c2015-05-11 12:55:4219 var test = async_test('Can set up a basic WebRTC call with no data.');
Harald Alvestrand2ee104d2015-04-28 10:44:5220
21 var gFirstConnection = null;
22 var gSecondConnection = null;
23
24 var onOfferCreated = test.step_func(function(offer) {
Harald Alvestrandd6918932015-05-12 10:19:4225 gFirstConnection.setLocalDescription(offer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4226 failed('setLocalDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5227
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 Fablet99f58912018-08-28 06:00:1937 gSecondConnection.setRemoteDescription(parsedOffer).then(
Harald Alvestrande42bf762015-05-12 08:47:5638 function() {
Youenn Fablet99f58912018-08-28 06:00:1939 gSecondConnection.createAnswer().then(onAnswerCreated,
Harald Alvestrande42bf762015-05-12 08:47:5640 failed('createAnswer'));
41 },
42 failed('setRemoteDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5243 };
44
45 var onAnswerCreated = test.step_func(function(answer) {
Harald Alvestrandd6918932015-05-12 10:19:4246 gSecondConnection.setLocalDescription(answer, ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4247 failed('setLocalDescription second'));
Harald Alvestrand2ee104d2015-04-28 10:44:5248
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 Fablet99f58912018-08-28 06:00:1956 gFirstConnection.setRemoteDescription(parsedAnswer).then(ignoreSuccess,
Harald Alvestrandf50f28c2015-05-11 12:55:4257 failed('setRemoteDescription first'));
Harald Alvestrand2ee104d2015-04-28 10:44:5258 };
59
Harald Alvestrandf50f28c2015-05-11 12:55:4260 var onIceCandidateToFirst = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5261 // If event.candidate is null = no more candidates.
62 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3463 gSecondConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5264 }
Harald Alvestrandf50f28c2015-05-11 12:55:4265 });
Harald Alvestrand2ee104d2015-04-28 10:44:5266
Harald Alvestrandf50f28c2015-05-11 12:55:4267 var onIceCandidateToSecond = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5268 if (event.candidate) {
Dominique Hazael-Massieux29acbc12015-06-15 09:03:3469 gFirstConnection.addIceCandidate(event.candidate);
Harald Alvestrand2ee104d2015-04-28 10:44:5270 }
Harald Alvestrandf50f28c2015-05-11 12:55:4271 });
Harald Alvestrand2ee104d2015-04-28 10:44:5272
Harald Alvestrandf50f28c2015-05-11 12:55:4273 var onIceConnectionStateChange = test.step_func(function(event) {
Harald Alvestrand2ee104d2015-04-28 10:44:5274 assert_equals(event.type, 'iceconnectionstatechange');
Dominique Hazael-Massieux027c8662015-06-16 07:45:1075 assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnectionState of first connection");
76 assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnectionState of second connection");
Harald Alvestrande42bf762015-05-12 08:47:5677 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 Alvestrandd6918932015-05-12 10:19:4283 // TODO: Revise test to ensure completed/completed is reached.
Harald Alvestrande42bf762015-05-12 08:47:5684 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 Alvestrand2ee104d2015-04-28 10:44:5292 if (gFirstConnection.iceConnectionState == 'completed' &&
93 gSecondConnection.iceConnectionState == 'connected') {
94 test.done()
95 }
Harald Alvestrand2ee104d2015-04-28 10:44:5296 if (gFirstConnection.iceConnectionState == 'completed' &&
97 gSecondConnection.iceConnectionState == 'completed') {
98 test.done()
99 }
Harald Alvestrandf50f28c2015-05-11 12:55:42100 });
Harald Alvestrand2ee104d2015-04-28 10:44:52101
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 Alvestrandd6918932015-05-12 10:19:42109 // Returns a suitable do-nothing.
110 function ignoreSuccess(function_name) {
111 }
112
Harald Alvestrand2ee104d2015-04-28 10:44:52113 // This function starts the test.
114 test.step(function() {
Harald Alvestrandf50f28c2015-05-11 12:55:42115 gFirstConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52116 gFirstConnection.onicecandidate = onIceCandidateToFirst;
117 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
118
Harald Alvestrandf50f28c2015-05-11 12:55:42119 gSecondConnection = new RTCPeerConnection(null);
Harald Alvestrand2ee104d2015-04-28 10:44:52120 gSecondConnection.onicecandidate = onIceCandidateToSecond;
Harald Alvestrand2ee104d2015-04-28 10:44:52121 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
122
Youenn Fabletc3be3232018-11-04 03:00:23123 generateVideoReceiveOnlyOffer(gFirstConnection)
Philipp Hanckec6fd45b2018-08-31 18:58:00124 .then(onOfferCreated, failed('createOffer'));
Harald Alvestrand2ee104d2015-04-28 10:44:52125 });
126</script>
127
128</body>
129</html>