blob: 7ef7e4a3bf2f30a221d1de2c09e5388f206afdc5 [file] [log] [blame]
Soares Chen300db382017-06-19 20:46:421<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.connectionState</title>
4<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6<script src="RTCPeerConnection-helper.js"></script>
7<script>
8 'use strict';
9
10 // Test is based on the following editor draft:
11 // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.htm
12
13 // The following helper functions are called from RTCPeerConnection-helper.js:
14 // exchangeIceCandidates
15 // doSignalingHandshake
16
17 /*
18 4.3.2. Interface Definition
19 interface RTCPeerConnection : EventTarget {
20 ...
21 readonly attribute RTCPeerConnectionState connectionState;
22 attribute EventHandler onconnectionstatechange;
23 };
24
25 4.4.3. RTCPeerConnectionState Enum
26 enum RTCPeerConnectionState {
27 "new",
28 "connecting",
29 "connected",
30 "disconnected",
31 "failed",
32 "closed"
33 };
34
35 5.5. RTCDtlsTransport Interface
36 interface RTCDtlsTransport {
Philipp Hanckec05700b2018-11-06 11:23:2837 readonly attribute RTCIceTransport iceTransport;
Soares Chen300db382017-06-19 20:46:4238 readonly attribute RTCDtlsTransportState state;
39 ...
40 };
41
42 enum RTCDtlsTransportState {
43 "new",
44 "connecting",
45 "connected",
46 "closed",
47 "failed"
48 };
49
50 5.6. RTCIceTransport Interface
51 interface RTCIceTransport {
52 readonly attribute RTCIceTransportState state;
53 ...
54 };
55
56 enum RTCIceTransportState {
57 "new",
58 "checking",
59 "connected",
60 "completed",
61 "failed",
62 "disconnected",
63 "closed"
64 };
65 */
66
67 /*
68 4.4.3. RTCPeerConnectionState Enum
69 new
70 Any of the RTCIceTransports or RTCDtlsTransports are in the new
71 state and none of the transports are in the connecting, checking,
72 failed or disconnected state, or all transports are in the closed state.
73 */
74 test(t => {
75 const pc = new RTCPeerConnection();
76 assert_equals(pc.connectionState, 'new');
77 }, 'Initial connectionState should be new');
78
79 /*
80 4.4.3. RTCPeerConnectionState Enum
81 connected
82 All RTCIceTransports and RTCDtlsTransports are in the connected,
83 completed or closed state and at least of them is in the connected
84 or completed state.
85
86 5.5. RTCDtlsTransportState
87 connected
88 DTLS has completed negotiation of a secure connection.
89
90 5.6. RTCIceTransportState
91 connected
92 The RTCIceTransport has found a usable connection, but is still
93 checking other candidate pairs to see if there is a better connection.
94 It may also still be gathering and/or waiting for additional remote
95 candidates. If consent checks [RFC7675] fail on the connection in use,
96 and there are no other successful candidate pairs available, then the
97 state transitions to "checking" (if there are candidate pairs remaining
98 to be checked) or "disconnected" (if there are no candidate pairs to
99 check, but the peer is still gathering and/or waiting for additional
100 remote candidates).
101
102 completed
103 The RTCIceTransport has finished gathering, received an indication that
104 there are no more remote candidates, finished checking all candidate
105 pairs and found a connection. If consent checks [RFC7675] subsequently
106 fail on all successful candidate pairs, the state transitions to "failed".
107 */
108 async_test(t => {
109 const pc1 = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53110 t.add_cleanup(() => pc1.close());
Soares Chen300db382017-06-19 20:46:42111 const pc2 = new RTCPeerConnection();
112
Philipp Hancke1622a022018-06-11 10:00:53113 t.add_cleanup(() => pc2.close());
114
Soares Chen300db382017-06-19 20:46:42115 const onConnectionStateChange = t.step_func(() => {
116 const { connectionState } = pc1;
117 if(connectionState === 'connected') {
118 const sctpTransport = pc1.sctp;
119
120 const dtlsTransport = sctpTransport.transport;
121 assert_equals(dtlsTransport.state, 'connected',
122 'Expect DTLS transport to be in connected state');
123
Philipp Hanckec05700b2018-11-06 11:23:28124 const iceTransport = dtlsTransport.iceTransport
Soares Chen300db382017-06-19 20:46:42125 assert_true(iceTransport.state === 'connected' ||
126 iceTransport.state === 'completed',
127 'Expect ICE transport to be in connected or completed state');
128
129 t.done();
130 }
131 });
132
133 pc1.createDataChannel('test');
134
135 assert_equals(pc1.onconnectionstatechange, null,
136 'Expect connection to have connectionstatechange event');
137
138 pc1.addEventListener('connectionstatechange', onConnectionStateChange);
139
140 exchangeIceCandidates(pc1, pc2);
141 doSignalingHandshake(pc1, pc2);
Soares Chen300db382017-06-19 20:46:42142 }, 'connection with one data channel should eventually have connected connection state');
143
144 /*
145 TODO
146 4.4.3. RTCPeerConnectionState Enum
147 connecting
148 Any of the RTCIceTransports or RTCDtlsTransports are in the
149 connecting or checking state and none of them is in the failed state.
150
151 disconnected
152 Any of the RTCIceTransports or RTCDtlsTransports are in the disconnected
153 state and none of them are in the failed or connecting or checking state.
154
155 failed
156 Any of the RTCIceTransports or RTCDtlsTransports are in a failed state.
157
158 closed
159 The RTCPeerConnection object's [[isClosed]] slot is true.
160
161 5.5. RTCDtlsTransportState
162 new
163 DTLS has not started negotiating yet.
164
165 connecting
166 DTLS is in the process of negotiating a secure connection.
167
168 closed
169 The transport has been closed.
170
171 failed
172 The transport has failed as the result of an error (such as a failure
173 to validate the remote fingerprint).
174
175 5.6. RTCIceTransportState
176 new
177 The RTCIceTransport is gathering candidates and/or waiting for
178 remote candidates to be supplied, and has not yet started checking.
179
180 checking
181 The RTCIceTransport has received at least one remote candidate and
182 is checking candidate pairs and has either not yet found a connection
183 or consent checks [RFC7675] have failed on all previously successful
184 candidate pairs. In addition to checking, it may also still be gathering.
185
186 failed
187 The RTCIceTransport has finished gathering, received an indication that
188 there are no more remote candidates, finished checking all candidate pairs,
189 and all pairs have either failed connectivity checks or have lost consent.
190
191 disconnected
192 The ICE Agent has determined that connectivity is currently lost for this
193 RTCIceTransport . This is more aggressive than failed, and may trigger
194 intermittently (and resolve itself without action) on a flaky network.
195 The way this state is determined is implementation dependent.
196
197 Examples include:
198 Losing the network interface for the connection in use.
199 Repeatedly failing to receive a response to STUN requests.
200
201 Alternatively, the RTCIceTransport has finished checking all existing
202 candidates pairs and failed to find a connection (or consent checks
203 [RFC7675] once successful, have now failed), but it is still gathering
204 and/or waiting for additional remote candidates.
205
206 closed
207 The RTCIceTransport has shut down and is no longer responding to STUN requests.
208 */
209</script>