OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 This test uses no media, and thus does not require fake media devices. | 3 This test uses data only, and thus does not require fake media devices. |
4 --> | 4 --> |
5 | 5 |
6 <html> | 6 <html> |
7 <head> | 7 <head> |
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
9 <title>RTCPeerConnection No-Media Connection Test</title> | 9 <title>RTCPeerConnection Data-Only Connection Test with Promises</title> |
10 </head> | 10 </head> |
11 <body> | 11 <body> |
12 <div id="log"></div> | 12 <div id="log"></div> |
13 <h2>iceConnectionState info</h2> | 13 <h2>iceConnectionState info</h2> |
14 <div id="stateinfo"> | 14 <div id="stateinfo"> |
15 </div> | 15 </div> |
16 | 16 |
17 <!-- These files are in place when executing on W3C. --> | 17 <!-- These files are in place when executing on W3C. --> |
18 <script src="../../../resources/testharness.js"></script> | 18 <script src="../../../resources/testharness.js"></script> |
19 <script src="../../../resources/testharnessreport.js"></script> | 19 <script src="../../../resources/testharnessreport.js"></script> |
20 <script src="../../../resources/vendor-prefix.js" | 20 <script src="../../../resources/vendor-prefix.js" |
21 data-prefixed-objects= | 21 data-prefixed-objects= |
22 '[{"ancestors":["window"], "name":"RTCPeerConnection"}, | 22 '[{"ancestors":["window"], "name":"RTCPeerConnection"}, |
23 {"ancestors":["window"], "name":"RTCSessionDescription"}, | 23 {"ancestors":["window"], "name":"RTCSessionDescription"}, |
24 {"ancestors":["window"], "name":"RTCIceCandidate"}]' | 24 {"ancestors":["window"], "name":"RTCIceCandidate"}]' |
25 > | 25 > |
26 </script> | 26 </script> |
27 <script type="text/javascript"> | 27 <script type="text/javascript"> |
28 var test = async_test('Can set up a basic WebRTC call with no data.'); | 28 var test = async_test('Can set up a basic WebRTC call with only data using pro
mises.'); |
29 | 29 |
30 var gFirstConnection = null; | 30 var gFirstConnection = null; |
31 var gSecondConnection = null; | 31 var gSecondConnection = null; |
32 | 32 |
33 var onOfferCreated = test.step_func(function(offer) { | |
34 // TODO: Switch to promise-based interface. | |
35 gFirstConnection.setLocalDescription(offer, ignoreSuccess, | |
36 failed('setLocalDescription first')); | |
37 | |
38 // This would normally go across the application's signaling solution. | |
39 // In our case, the "signaling" is to call this function. | |
40 receiveCall(offer.sdp); | |
41 }); | |
42 | |
43 function receiveCall(offerSdp) { | |
44 | |
45 var parsedOffer = new RTCSessionDescription({ type: 'offer', | |
46 sdp: offerSdp }); | |
47 // These functions use the legacy interface extensions to RTCPeerConnection. | |
48 // TODO: Switch to promise-based interfaces. | |
49 gSecondConnection.setRemoteDescription(parsedOffer, | |
50 function() { | |
51 gSecondConnection.createAnswer(onAnswerCreated, | |
52 failed('createAnswer')); | |
53 }, | |
54 failed('setRemoteDescription second')); | |
55 }; | |
56 | |
57 var onAnswerCreated = test.step_func(function(answer) { | |
58 gSecondConnection.setLocalDescription(answer, ignoreSuccess, | |
59 failed('setLocalDescription second')); | |
60 | |
61 // Similarly, this would go over the application's signaling solution. | |
62 handleAnswer(answer.sdp); | |
63 }); | |
64 | |
65 function handleAnswer(answerSdp) { | |
66 var parsedAnswer = new RTCSessionDescription({ type: 'answer', | |
67 sdp: answerSdp }); | |
68 gFirstConnection.setRemoteDescription(parsedAnswer, ignoreSuccess, | |
69 failed('setRemoteDescription first')); | |
70 }; | |
71 | |
72 var onIceCandidateToFirst = test.step_func(function(event) { | 33 var onIceCandidateToFirst = test.step_func(function(event) { |
73 // If event.candidate is null = no more candidates. | 34 // If event.candidate is null = no more candidates. |
74 if (event.candidate) { | 35 if (event.candidate) { |
75 var candidate = new RTCIceCandidate(event.candidate); | 36 var candidate = new RTCIceCandidate(event.candidate); |
76 gSecondConnection.addIceCandidate(candidate); | 37 gSecondConnection.addIceCandidate(candidate); |
77 } | 38 } |
78 }); | 39 }); |
79 | 40 |
80 var onIceCandidateToSecond = test.step_func(function(event) { | 41 var onIceCandidateToSecond = test.step_func(function(event) { |
81 if (event.candidate) { | 42 if (event.candidate) { |
(...skipping 26 matching lines...) Expand all Loading... |
108 if (gFirstConnection.iceConnectionState == 'completed' && | 69 if (gFirstConnection.iceConnectionState == 'completed' && |
109 gSecondConnection.iceConnectionState == 'connected') { | 70 gSecondConnection.iceConnectionState == 'connected') { |
110 test.done() | 71 test.done() |
111 } | 72 } |
112 if (gFirstConnection.iceConnectionState == 'completed' && | 73 if (gFirstConnection.iceConnectionState == 'completed' && |
113 gSecondConnection.iceConnectionState == 'completed') { | 74 gSecondConnection.iceConnectionState == 'completed') { |
114 test.done() | 75 test.done() |
115 } | 76 } |
116 }); | 77 }); |
117 | 78 |
118 // Returns a suitable error callback. | |
119 function failed(function_name) { | |
120 return test.step_func(function() { | |
121 assert_unreached('WebRTC called error callback for ' + function_name); | |
122 }); | |
123 } | |
124 | |
125 // Returns a suitable do-nothing. | |
126 function ignoreSuccess(function_name) { | |
127 } | |
128 | |
129 // This function starts the test. | 79 // This function starts the test. |
130 test.step(function() { | 80 test.step(function() { |
131 gFirstConnection = new RTCPeerConnection(null); | 81 gFirstConnection = new RTCPeerConnection(null); |
132 gFirstConnection.onicecandidate = onIceCandidateToFirst; | 82 gFirstConnection.onicecandidate = onIceCandidateToFirst; |
133 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; | 83 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
134 | 84 |
135 gSecondConnection = new RTCPeerConnection(null); | 85 gSecondConnection = new RTCPeerConnection(null); |
136 gSecondConnection.onicecandidate = onIceCandidateToSecond; | 86 gSecondConnection.onicecandidate = onIceCandidateToSecond; |
137 gSecondConnection.onaddstream = onRemoteStream; | 87 gSecondConnection.onaddstream = onRemoteStream; |
138 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; | 88 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
139 | 89 |
140 // The offerToReceiveVideo is necessary and sufficient to make | 90 // The createDataChannel is necessary and sufficient to make |
141 // an actual connection. | 91 // sure the ICE connection be attempted. |
142 // TODO: Use a promise-based API. This is legacy. | 92 gFirstConnection.createDataChannel('channel'); |
143 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'), | 93 |
144 {offerToReceiveVideo: true}); | 94 var atStep = 'Create offer'; |
| 95 |
| 96 gFirstConnection.createOffer() |
| 97 .then(function(offer) { |
| 98 atStep = 'Set local description at first'; |
| 99 return gFirstConnection.setLocalDescription(offer); |
| 100 }) |
| 101 .then(function() { |
| 102 atStep = 'Set remote description at second'; |
| 103 return gSecondConnection.setRemoteDescription( |
| 104 gFirstConnection.localDescription); |
| 105 }) |
| 106 .then(function() { |
| 107 atStep = 'Create answer'; |
| 108 return gSecondConnection.createAnswer() |
| 109 }) |
| 110 .then(function(answer) { |
| 111 atStep = 'Set local description at second'; |
| 112 return gSecondConnection.setLocalDescription(answer); |
| 113 }) |
| 114 .then(function() { |
| 115 atStep = 'Set remote description at first'; |
| 116 return gFirstConnection.setRemoteDescription( |
| 117 gSecondConnection.localDescription); |
| 118 }) |
| 119 .then(function() { |
| 120 atStep = 'Negotiation completed'; |
| 121 }) |
| 122 .catch(test.step_func(function(e) { |
| 123 assert_unreached('Error ' + e.name + ': ' + e.message + |
| 124 ' happened at step ' + atStep); |
| 125 })); |
145 }); | 126 }); |
146 </script> | 127 </script> |
147 | 128 |
148 </body> | 129 </body> |
149 </html> | 130 </html> |
OLD | NEW |