forked from w3c/webrtc-pc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webrtc.html
13443 lines (13335 loc) · 685 KB
/
webrtc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="webrtc.css" rel="stylesheet">
<title>WebRTC 1.0: Real-time Communication Between Browsers</title>
<script class="remove" src="respec-w3c-common.js" type="text/javascript">
// // keep this comment //
</script>
<script class="remove" src="webrtc.js" type="text/javascript">
// // keep
this comment //
</script>
</head>
<body>
<section id="abstract">
<p>This document defines a set of ECMAScript APIs in WebIDL to allow media
to be sent to and received from another browser or device implementing the
appropriate set of real-time protocols. This specification is being
developed in conjunction with a protocol specification developed by the
IETF RTCWEB group and an API specification to get access to local media
devices developed by the Media Capture Task Force.</p>
</section>
<section id="sotd">
<p>The API is based on preliminary work done in the WHATWG.</p>
<p>While the specification is feature complete and is expected to be stable, there are also a number of <a href="https://github.com/w3c/webrtc-pc/issues?utf8=%E2%9C%93&q=is%3Aopen%20is%3Aissue%20-label%3AEditorial%20">known substantive issues</a> on the specification that will be addressed during the Candidate Recommendation period based on implementation experience feedback.</p>
<p>It might also evolve based on feedback gathered as its <a href="https://github.com/web-platform-tests/wpt/tree/master/webrtc">associated test suite</a> evolves. This test suite will be used to build an <a href="https://wpt.fyi/webrtc">implementation report</a> of the API.</p>
<p>To go into Proposed Recommendation status, the group expects to demonstrate implementation of each feature in at least two deployed browsers, and at least one implementation of each optional feature. Mandatory feature with only one implementation may be marked as optional in a revised Candidate Recommendation where applicable.</p>
<p>The following features are marked as at risk:</p>
<ul>
<li>The value <a href="#dom-rtcrtcpmuxpolicy-negotiate"><code>negotiate</code></a> of RTCRtcpMuxPolicy.</li>
<li>The <code>encodings</code> attribute of <code><a>RTCRtpReceiveParameters</a></code>.</li>
<li>The <code>getDefaultIceServers()</code> method of <code><a>RTCPeerConnection</a></code>.</li>
</ul>
</section>
<section class="informative" id="intro">
<h2>Introduction</h2>
<p>There are a number of facets to peer-to-peer communications and
video-conferencing in HTML covered by this specification:</p>
<ul>
<li>Connecting to remote peers using NAT-traversal technologies such as
ICE, STUN, and TURN.</li>
<li>Sending the locally-produced tracks to remote peers and receiving
tracks from remote peers.</li>
<li>Sending arbitrary data directly to remote peers.</li>
</ul>
<p>This document defines the APIs used for these features. This
specification is being developed in conjunction with a protocol
specification developed by the <a href=
"https://datatracker.ietf.org/wg/rtcweb/">IETF RTCWEB group</a> and an API
specification to get access to local media devices [[GETUSERMEDIA]]
developed by the <a href="https://www.w3.org/wiki/Media_Capture">Media
Capture Task Force</a>. An overview of the system can be found in
[[RTCWEB-OVERVIEW]] and [[RTCWEB-SECURITY]].</p>
</section>
<section id="conformance">
<p>This specification defines conformance criteria that apply to a single
product: the <dfn>user agent</dfn> that implements the interfaces that it
contains.</p>
<p>Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the end result is equivalent. (In
particular, the algorithms defined in this specification are intended to be
easy to follow, and not intended to be performant.)</p>
<p>Implementations that use ECMAScript to implement the APIs defined in
this specification MUST implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL-1]], as
this specification uses that specification and terminology.</p>
</section>
<section>
<h2>Terminology</h2>
<p>The <code><a data-cite=
"!HTML51/webappapis.html#event-handler">EventHandler</a></code>
interface, representing a callback used for event handlers, and the
<code><dfn data-cite="!HTML51/webappapis.html#errorevent-errorevent">
ErrorEvent</dfn></code> interface are defined in [[!HTML51]].</p>
<p>The concepts <dfn data-cite="!HTML51/webappapis.html#queuing">queue a
task</dfn> and <dfn data-cite="!HTML51/webappapis.html#networking-task-source">networking
task source</dfn> are defined in [[!HTML51]].</p>
<p>The concept <dfn data-cite="!DOM#firing-events">fire an
event</dfn> is defined in [[!DOM]].</p>
<p>The terms <dfn>event</dfn>, <dfn data-cite="!HTML51/webappapis.html#events-event-handlers">event
handlers</dfn> and <dfn data-cite="!HTML51/webappapis.html#event-handler-event-type">event
handler event types</dfn> are defined in [[!HTML51]].</p>
<p><code><dfn data-cite="!HIGHRES-TIME#dom-performance-timeorigin">performance.timeOrigin</dfn></code>
and <code><dfn data-cite="!HIGHRES-TIME#dom-performance-now">performance.now()</dfn></code>
are defined in [[!HIGHRES-TIME]].</p>
<p>The terms <dfn><a href=
"https://html.spec.whatwg.org/multipage/infrastructure.html#serializable-objects">
serializable objects</a></dfn>, <dfn><a href=
"https://html.spec.whatwg.org/multipage/infrastructure.html#serialization-steps">
serialization steps</a></dfn>, and <dfn><a href=
"https://html.spec.whatwg.org/multipage/infrastructure.html#deserialization-steps">
deserialization steps</a></dfn> are defined in [[!HTML]].</p>
<p>The terms <dfn>MediaStream</dfn>, <dfn>MediaStreamTrack</dfn>, and
<dfn>MediaStreamConstraints</dfn> are defined in [[!GETUSERMEDIA]].
Note that <code><a>MediaStream</a></code> is extended in <code><a href="#mediastream-network-use">
the MediaStream section</a></code> in this document while <code><a>MediaStreamTrack</a></code>
is extended in <code><a href="#mediastreamtrack-network-use">
the MediaStreamTrack section</a></code> in this document.</p>
<p>The term <dfn>Blob</dfn> is defined in [[!FILEAPI]].</p>
<p>The term <dfn>media description</dfn> is defined in [[!RFC4566]].</p>
<p>The term <dfn>media transport</dfn> is defined in [[!RFC7656]].</p>
<p>The term <dfn>generation</dfn> is defined in [[!TRICKLE-ICE]] Section 2.</p>
<p>The terms <dfn data-cite="!WEBRTC-STATS#dom-rtcstatstype">RTCStatsType</dfn>, <dfn data-cite="!WEBRTC-STATS#dfn-stats-object">stats object</dfn> and <dfn data-cite="!WEBRTC-STATS#dfn-monitored-object">monitored object</dfn> are defined in [[!WEBRTC-STATS]].
<p>When referring to exceptions, the terms <dfn
data-cite="!WEBIDL-1#dfn-throw">throw</dfn> and
<dfn data-dfn-for="exception" data-cite=
"!WEBIDL-1#dfn-create-exception">create</dfn> are
defined in [[!WEBIDL-1]].</p>
<p>The term "throw" is used as specified in [[!INFRA]]: it terminates
the current processing steps.
</p>
<p>The terms <dfn data-lt="fulfill|fulfillment">fulfilled</dfn>, <dfn
data-lt="reject|rejection|rejecting">rejected</dfn>, <dfn data-lt=
"resolve|resolves">resolved</dfn>, <dfn>pending</dfn> and
<dfn>settled</dfn> used in the context of Promises are defined in
[[!ECMASCRIPT-6.0]].</p>
<p>The terms <dfn>bundle</dfn>, <dfn>bundle-only</dfn> and <dfn>bundle-policy</dfn>
are defined in [[!JSEP]].</p>
<p>The <dfn>OAuth Client</dfn> and <dfn>Authorization Server</dfn> roles
are defined in [[!RFC6749]] Section 1.1.</p>
<p>
The terms <dfn>isolated stream</dfn>,
<dfn>peeridentity</dfn>, <dfn>request an identity assertion</dfn> and
<dfn>validate the identity</dfn> are defined in [[!WEBRTC-IDENTITY]].
</p>
<p class="note">
The general principles for Javascript APIs apply, including the principle
of <a href="https://w3ctag.github.io/design-principles/#js-rtc">
run-to-completion</a> and no-data-races as defined in [[API-DESIGN-PRINCIPLES]].
That is, while a task is running, external events do
not influence what's visible to the Javascript application. For example,
the amount of data buffered on a data channel will increase due to
"send" calls while Javascript is executing, and the decrease due to
packets being sent will be visible after a task checkpoint.
<br>
It is the responsibility of the user agent to make sure the set of
values presented to the application is consistent - for instance that
getContributingSources() (which is synchronous) returns values for all
sources measured at the same time.
</p>
</section>
<section>
<h2>Peer-to-peer connections</h2>
<section>
<h3>Introduction</h3>
<p>An <code><a>RTCPeerConnection</a></code> instance allows an
application to establish peer-to-peer communications with another
<code><a>RTCPeerConnection</a></code> instance in another browser, or to
another endpoint implementing the required protocols. Communications are coordinated by the
exchange of control messages (called a signaling protocol) over a
signaling channel which is provided by unspecified means, but generally
by a script in the page via the server, e.g. using
<code>XMLHttpRequest</code> [[XMLHttpRequest]] or Web Sockets
[[WEBSOCKETS-API]].</p>
</section>
<section>
<h3>Configuration</h3>
<section>
<h4><dfn>RTCConfiguration</dfn> Dictionary</h4>
<p>The <code>RTCConfiguration</code> defines a set of parameters to
configure how the peer-to-peer communication established via
<code><a>RTCPeerConnection</a></code> is established or
re-established.</p>
<div>
<pre class="idl">dictionary RTCConfiguration {
sequence<RTCIceServer> iceServers;
RTCIceTransportPolicy iceTransportPolicy = "all";
RTCBundlePolicy bundlePolicy = "balanced";
RTCRtcpMuxPolicy rtcpMuxPolicy = "require";
DOMString peerIdentity;
sequence<RTCCertificate> certificates;
[EnforceRange]
octet iceCandidatePoolSize = 0;
};</pre>
<section>
<h2>Dictionary <a class="idlType">RTCConfiguration</a> Members</h2>
<dl data-link-for="RTCConfiguration" data-dfn-for=
"RTCConfiguration" class="dictionary-members">
<dt data-tests="RTCConfiguration-iceServers.html"><dfn data-idl><code>iceServers</code></dfn> of type <span class=
"idlMemberType">sequence<<a>RTCIceServer</a>></span></dt>
<dd>
<p>An array of objects describing servers available to be used
by ICE, such as STUN and TURN servers.</p>
</dd>
<dt data-tests="RTCConfiguration-iceTransportPolicy.html"><dfn data-idl><code>iceTransportPolicy</code></dfn> of type
<span class="idlMemberType"><a>RTCIceTransportPolicy</a></span>,
defaulting to <code>"all"</code></dt>
<dd>
<p>Indicates which candidates the <a>ICE Agent</a> is allowed
to use.</p>
</dd>
<dt data-tests="RTCConfiguration-bundlePolicy.html"><dfn data-idl><code>bundlePolicy</code></dfn> of type <span class=
"idlMemberType"><a>RTCBundlePolicy</a></span>, defaulting to
<code>"balanced"</code></dt>
<dd>
<p>Indicates which <a data-lt=RTCBundlePolicy>media-bundling policy</a> to use when
gathering ICE candidates.</p>
</dd>
<dt><dfn data-idl><code>rtcpMuxPolicy</code></dfn> of type <span class=
"idlMemberType"><a>RTCRtcpMuxPolicy</a></span>, defaulting to
<code>"require"</code></dt>
<dd>
<p>Indicates which <a data-lt=RTCRtcpMuxPolicy>rtcp-mux policy</a> to use when gathering
ICE candidates.</p>
</dd>
<dt><dfn data-idl><code>peerIdentity</code></dfn> of type <span class=
"idlMemberType">DOMString</span></dt>
<dd>
<p>Sets the <a>target peer identity</a> for the
<a>RTCPeerConnection</a>. The <a>RTCPeerConnection</a> will not
establish a connection to a remote peer unless it can be
successfully authenticated with the provided name.</p>
</dd>
<dt data-tests="RTCPeerConnection-constructor.html"><dfn data-idl><code>certificates</code></dfn> of type <span class=
"idlMemberType">sequence<<a>RTCCertificate</a>></span></dt>
<dd>
<p>A set of certificates that the
<a><code>RTCPeerConnection</code></a> uses to authenticate.</p>
<p>Valid values for this parameter are created through calls to
the <a data-link-for=
"RTCPeerConnection"><code>generateCertificate</code></a>
function.</p>
<p>Although any given DTLS connection will use only one
certificate, this attribute allows the caller to provide
multiple certificates that support different algorithms. The
final certificate will be selected based on the DTLS handshake,
which establishes which certificates are allowed. The
<code>RTCPeerConnection</code> implementation selects which of
the certificates is used for a given connection; how
certificates are selected is outside the scope of this
specification.</p>
<p>If this value is absent, then a default set of certificates
is generated for each <a><code>RTCPeerConnection</code></a>
instance.</p>
<p>This option allows applications to establish key continuity.
An <code>RTCCertificate</code> can be persisted in
[[INDEXEDDB]] and reused. Persistence and reuse also avoids the
cost of key generation.</p>
<p>The value for this configuration option cannot change after
its value is initially selected.</p>
</dd>
<dt data-tests="RTCPeerConnection-constructor.html"><dfn data-idl><code>iceCandidatePoolSize</code></dfn> of type
<span class="idlMemberType">octet</span>, defaulting to
<code>0</code></dt>
<dd>
<p>Size of the prefetched ICE pool as defined in
<span data-jsep=
"ice-candidate-pool constructor">[[!JSEP]]</span>.</p>
</dd>
</dl>
</section>
</div>
</section>
<section>
<h4><dfn>RTCIceCredentialType</dfn> Enum</h4>
<div>
<pre class="idl">enum RTCIceCredentialType {
"password",
"oauth"
};</pre>
<table data-link-for="RTCIceCredentialType" data-dfn-for=
"RTCIceCredentialType" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description</th>
</tr>
<tr>
<td data-tests="RTCConfiguration-iceServers.html"><dfn data-idl><code>password</code></dfn></td>
<td>The credential is a long-term authentication username and
password, as described in [[!RFC5389]], Section 10.2.
</td>
</tr>
<tr>
<td data-tests="RTCConfiguration-iceServers.html"><dfn data-idl><code>oauth</code></dfn></td>
<td><p>An OAuth 2.0 based authentication method, as described
in [[!RFC7635]].
</p>
<p>For OAuth Authentication, the <a>ICE Agent</a> requires three
pieces of credential information. The credential is composed of
a <code>kid</code>, which the <a>RTCIceServer</a>
<code>username</code> member is used for, and
<code>macKey</code> and <code> accessToken</code>, which are
placed in the <a>RTCOAuthCredential</a> dictionary.
</p>
<p class="note">
This specification does not define how an application (acting
as the <a>OAuth Client</a>) obtains the
<code>accessToken</code>, <code>kid</code> and
<code>macKey</code> from the <a>Authorization Server</a>, as
WebRTC only handles the interaction between the <a>ICE
agent</a> and TURN server. For example, the application may use
the OAuth 2.0 Implicit Grant type, with PoP (Proof-of-Possession)
Token type, as described in [[!RFC6749]] and
[[OAUTH-POP-KEY-DISTRIBUTION]]; an example of this is provided
in [[!RFC7635]], Appendix B.
</p>
<p>
The application, acting as the <a>OAuth
Client</a>, is responsible for refreshing the credential
information and updating the <a>ICE Agent</a> with fresh new
credentials before the <code>accessToken</code> expires. The
<a>OAuth Client</a> can use the <a
href="#interface-definition"><code>RTCPeerConnection</code></a>
<a data-lt="setConfiguration"
href="#dom-rtcpeerconnection-setconfiguration"><code>
setConfiguration</code></a> method to periodically refresh the
TURN credentials.</p>
<p>The length of the HMAC key
(<code>RTCOAuthCredential.macKey</code>) MAY be any integer
number of bytes greater than 20 (160 bits).</p>
<p class="note">According to [[!RFC7635]] Section 4.1, the
HMAC key MUST be a symmetric key, as asymmetric keys would
result in large access tokens which may not fit in a single
STUN message.
</p>
<p class="note">Currently the STUN/TURN protocols use only SHA-1 and SHA-2
family hash algorithms for Message Integrity Protection, as
defined in [[RFC5389]] Section 15.4, and [[STUN-BIS]]
Section 14.6.
</p>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h4><dfn>RTCOAuthCredential</dfn> Dictionary</h4>
<p>The <code>RTCOAuthCredential</code> dictionary is used to describe
the OAuth auth credential information which is used by the STUN/TURN
client (inside the <a>ICE Agent</a>) to authenticate against a STUN/TURN
server, as described in [[!RFC7635]]. Note that the <code>kid</code>
parameter is not located in this dictionary, but in
<code>RTCIceServer</code>'s <code>username</code> member.
</p>
<div>
<pre class="idl">dictionary RTCOAuthCredential {
required DOMString macKey;
required DOMString accessToken;
};</pre>
<section>
<h2>Dictionary <a class="idlType">RTCOAuthCredential</a> Members
</h2>
<dl data-link-for="RTCOAuthCredential"
data-dfn-for="RTCOAuthCredential" class="dictionary-members">
<dt data-tests="RTCConfiguration-iceServers.html"><dfn data-idl><code>macKey</code></dfn> of type <span class=
"idlMemberType">DOMString</span>, required</dt>
<dd>
<p>The "mac_key", as described in [[!RFC7635]], Section 6.2, in
a base64-url encoded format. It is used in STUN message
integrity hash calculation (as the password is used in password
based authentication). Note that the OAuth response "key"
parameter is a JSON Web Key (JWK) or a JWK encrypted with a JWE
format. Also note that this is the only OAuth parameter whose
value is not used directly, but must be extracted from the "k"
parameter value from the JWK, which contains the needed
base64-encoded "mac_key".</p>
</dd>
<dt data-tests="RTCConfiguration-iceServers.html"><dfn data-idl><code>accessToken</code></dfn> of type <span class=
"idlMemberType">DOMString</span>, required</dt>
<dd>
<p>The "access_token", as described in [[!RFC7635]], Section
6.2, in a base64-encoded format. This is an encrypted
self-contained token that is opaque to the application.
Authenticated encryption is used for message encryption and
integrity protection. The access token contains a non-encrypted
nonce value, which is used by the Authorization Server for unique
mac_key generation. The second part of the token is protected
by Authenticated Encryption. It contains the mac_key, a
timestamp and a lifetime. The timestamp combined with lifetime
provides expiry information; this information describes the
time window during which the token credential is valid and
accepted by the TURN server.
</p>
</dd>
</dl>
</section>
</div>
<p>An example of an RTCOAuthCredential dictionary is:</p>
<pre class="example highlight"><code>
{
macKey: 'WmtzanB3ZW9peFhtdm42NzUzNG0=',
accessToken: 'AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA=='
}
</code></pre>
</section>
<section>
<h4><dfn>RTCIceServer</dfn> Dictionary</h4>
<p>The <code>RTCIceServer</code> dictionary is used to describe the
STUN and TURN servers that can be used by the <a>ICE Agent</a> to
establish a connection with a peer.</p>
<div>
<pre class="idl">dictionary RTCIceServer {
required (DOMString or sequence<DOMString>) urls;
DOMString username;
(DOMString or RTCOAuthCredential) credential;
RTCIceCredentialType credentialType = "password";
};</pre>
<section>
<h2>Dictionary <a class="idlType">RTCIceServer</a> Members</h2>
<dl data-link-for="RTCIceServer" data-dfn-for="RTCIceServer" class=
"dictionary-members">
<dt><dfn data-idl><code>urls</code></dfn> of type <span class=
"idlMemberType">(DOMString or
sequence<DOMString>)</span>, required</dt>
<dd>
<p>STUN or TURN URI(s) as defined in [[!RFC7064]] and
[[!RFC7065]] or other URI types.</p>
</dd>
<dt><dfn data-idl><code>username</code></dfn> of type <span class=
"idlMemberType">DOMString</span></dt>
<dd>
<p>If this <code><a>RTCIceServer</a></code> object represents a
TURN server, and <code>credentialType</code> is
<code>"password"</code>, then this attribute specifies the
username to use with that TURN server.</p>
<p>If this <code><a>RTCIceServer</a></code> object represents a
TURN server, and <code>credentialType</code> is
<code>"oauth"</code>, then this attribute specifies the Key ID
(<code>kid</code>) of the shared symmetric key, which is shared
between the TURN server and the Authorization Server, as described
in [[!RFC7635]]. It is an ephemeral and unique key identifier.
The <code>kid</code> allows the TURN server to select the
appropriate keying material for decryption of the Access-Token,
so the key identified by this <code>kid</code> is used in the
Authenticated Encryption of the "access_token". The
<code>kid</code> value is equal with the OAuth response "kid"
parameter, as defined in [[!RFC7515]] Section 4.1.4.
</p>
</dd>
<dt><dfn data-idl><code>credential</code></dfn> of type <span class=
"idlMemberType">(DOMString or <a>RTCOAuthCredential</a>)
</span></dt>
<dd>
<p>If this <code><a>RTCIceServer</a></code> object represents a
TURN server, then this attribute specifies the credential to
use with that TURN server.</p>
<p>If <code>credentialType</code> is <code>"password"</code>,
<code>credential</code> is a DOMString, and represents a
long-term authentication password, as described in
[[!RFC5389]], Section 10.2.</p>
<p>If <code>credentialType</code> is <code>"oauth"</code>,
<code>credential</code> is an <a>RTCOAuthCredential</a>, which
contains the OAuth access token and MAC key.</p>
</dd>
<dt><dfn data-idl><code>credentialType</code></dfn> of type <span class=
"idlMemberType"><a>RTCIceCredentialType</a></span>, defaulting to
<code>"password"</code></dt>
<dd>
<p>If this <code><a>RTCIceServer</a></code> object represents a
TURN server, then this attribute specifies how
<var>credential</var> should be used when that TURN server
requests authorization.</p>
</dd>
</dl>
</section>
</div>
<p>An example array of RTCIceServer objects is:</p>
<pre class="example highlight"><code>
[
{urls: 'stun:stun1.example.net'},
{urls: ['turns:turn.example.org', 'turn:turn.example.net'],
username: 'user',
credential: 'myPassword',
credentialType: 'password'},
{urls: 'turns:turn2.example.net',
username: '22BIjxU93h/IgwEb',
credential: {
macKey: 'WmtzanB3ZW9peFhtdm42NzUzNG0=',
accessToken: 'AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA=='
},
credentialType: 'oauth'}
];
</code></pre>
</section>
<section data-tests="RTCConfiguration-iceTransportPolicy.html">
<h4><dfn>RTCIceTransportPolicy</dfn> Enum</h4>
<p>As described in <span data-jsep="constructor">[[!JSEP]]</span>, if the
<a data-link-for='RTCConfiguration'>iceTransportPolicy</a> member of
the <code>RTCConfiguration</code> is specified, it defines the
<span data-jsep="ice-candidate-policy">ICE candidate policy
[[!JSEP]]</span> the browser uses to surface the permitted candidates
to the application; only these candidates will be used for connectivity
checks.</p>
<div>
<pre class="idl">enum RTCIceTransportPolicy {
"relay",
"all"
};</pre>
<table data-link-for="RTCIceTransportPolicy" data-dfn-for=
"RTCIceTransportPolicy" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description (non-normative)</th>
</tr>
<tr>
<td><dfn data-idl><code>relay</code></dfn></td>
<td>
<p>
The <a>ICE Agent</a> uses only media relay candidates
such as candidates passing through a TURN server.
</p>
<div class="note">
This can be used to prevent the remote endpoint from learning
the user's IP addresses, which may be desired in certain
use cases. For example, in a "call"-based application, the
application may want to prevent an unknown caller from
learning the callee's IP addresses until the callee has
consented in some way.
</div>
</td>
</tr>
<tr>
<td><dfn data-idl><code>all</code></dfn></td>
<td>
<p>
The <a>ICE Agent</a> can use any type of candidate when
this value is specified.
</p>
<div class="note">
The implementation can still use its own candidate
filtering policy in order to limit the IP addresses exposed
to the application, as noted in the description of
<code>RTCIceCandidate.<a data-link-for="RTCIceCandidate">address</a></code>.
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h4><dfn>RTCBundlePolicy</dfn> Enum</h4>
<p>As described in <span data-jsep="constructor">[[!JSEP]]</span>,
bundle policy affects which media tracks are negotiated if the remote
endpoint is not bundle-aware, and what ICE candidates are gathered. If
the remote endpoint is bundle-aware, all media tracks and data channels
are bundled onto the same transport.</p>
<div>
<pre id="target-bundle-policy" class="idl">enum RTCBundlePolicy {
"balanced",
"max-compat",
"max-bundle"
};</pre>
<table data-link-for="RTCBundlePolicy" data-dfn-for="RTCBundlePolicy"
class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description (non-normative)</th>
</tr>
<tr>
<td data-tests="RTCRtpSender-transport.https.html"><dfn data-idl><code>balanced</code></dfn></td>
<td>Gather ICE candidates for each media type in use (audio,
video, and data). If the remote endpoint is not bundle-aware,
negotiate only one audio and video track on separate
transports.</td>
</tr>
<tr>
<td data-tests="RTCRtpSender-transport.https.html"><dfn data-idl><code>max-compat</code></dfn></td>
<td>Gather ICE candidates for each track. If the remote
endpoint is not bundle-aware, negotiate all media tracks on
separate transports.</td>
</tr>
<tr>
<td data-tests="RTCRtpSender-transport.https.html"><dfn data-idl><code>max-bundle</code></dfn></td>
<td>Gather ICE candidates for only one track. If the remote
endpoint is not bundle-aware, negotiate only one media
track.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h4><dfn>RTCRtcpMuxPolicy</dfn> Enum</h4>
<p>As described in <span data-jsep="constructor">[[!JSEP]]</span>, the
RtcpMuxPolicy affects what ICE candidates are gathered to support
non-multiplexed RTCP.</p>
<div>
<pre id="target-rtcp-mux-policy" class="idl">enum RTCRtcpMuxPolicy {
// At risk due to lack of implementers' interest.
"negotiate",
"require"
};</pre>
<table data-link-for="RTCRtcpMuxPolicy" data-dfn-for=
"RTCRtcpMuxPolicy" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description (non-normative)</th>
</tr>
<tr>
<td><dfn data-idl><code>negotiate</code></dfn></td>
<td>Gather ICE candidates for both RTP and RTCP candidates. If
the remote-endpoint is capable of multiplexing RTCP, multiplex
RTCP on the RTP candidates. If it is not, use both the RTP and
RTCP candidates separately. Note that, as stated in <span
data-jsep="constructor">[[!JSEP]]</span>, the user agent
MAY not implement non-multiplexed RTCP, in which case it will
reject attempts to construct an <a>RTCPeerConnection</a> with the
<code>negotiate</code> policy.</td>
</tr>
<tr>
<td><dfn data-idl><code>require</code></dfn></td>
<td>Gather ICE candidates only for RTP and multiplex RTCP on
the RTP candidates. If the remote endpoint is not capable of
rtcp-mux, session negotiation will fail.</td>
</tr>
</tbody>
</table>
<div class="issue atrisk">
<p>Aspects of this specification supporting non-multiplexed RTP/RTCP are marked
as features at risk, since there is no clear commitment from implementers.
This includes:</p>
<ol>
<li>The value <code>negotiate</code>, since there is no clear commitment
from implementers for the behavior associated with this.</li>
<li>Support for the <code>rtcpTransport</code> attribute within the
<code><a>RTCRtpSender</a></code> and <code><a>RTCRtpReceiver</a></code>.</li>
</ol>
</div>
</div>
</section>
<section>
<h4>Offer/Answer Options</h4>
<p>These dictionaries describe the options that can be used to control
the offer/answer creation process.</p>
<div>
<pre class="idl">dictionary RTCOfferAnswerOptions {
boolean voiceActivityDetection = true;
};</pre>
<section>
<h2>Dictionary <dfn>RTCOfferAnswerOptions</dfn>
Members</h2>
<dl data-link-for="RTCOfferAnswerOptions" data-dfn-for=
"RTCOfferAnswerOptions" class="dictionary-members">
<dt><dfn data-idl><code>voiceActivityDetection</code></dfn> of type
<span class="idlMemberType">boolean</span>, defaulting to
<code>true</code></dt>
<dd>
<p>Many codecs and systems are capable of detecting "silence"
and changing their behavior in this case by doing things such
as not transmitting any media. In many cases, such as when
dealing with emergency calling or sounds other than spoken
voice, it is desirable to be able to turn off this behavior.
This option allows the application to provide information about
whether it wishes this type of processing enabled or
disabled.</p>
</dd>
</dl>
</section>
</div>
<div>
<pre class="idl">dictionary RTCOfferOptions : RTCOfferAnswerOptions {
boolean iceRestart = false;
};</pre>
<section>
<h2>Dictionary <dfn>RTCOfferOptions</dfn> Members</h2>
<dl data-link-for="RTCOfferOptions" data-dfn-for="RTCOfferOptions"
class="dictionary-members">
<dt><dfn data-idl><code>iceRestart</code></dfn> of type <span class=
"idlMemberType">boolean</span>, defaulting to
<code>false</code></dt>
<dd>
<p>When the value of this dictionary member is true, the
generated description will have ICE credentials that are
different from the current credentials (as visible in the
<code><a data-link-for=
"RTCPeerConnection">localDescription</a></code> attribute's
SDP). Applying the generated description will restart ICE, as
described in section 9.1.1.1 of [[!ICE]].</p>
<p>When the value of this dictionary member is false, and the
<code><a data-link-for=
"RTCPeerConnection">localDescription</a></code> attribute has
valid ICE credentials, the generated description will have the
same ICE credentials as the current value from the
<code><a data-link-for=
"RTCPeerConnection">localDescription</a></code> attribute.</p>
<p class="note">Performing an ICE restart is recommended when
<code><a data-link-for="RTCPeerConnection">iceConnectionState</a></code> transitions to
<code>"<a data-link-for="RTCIceConnectionState">failed</a>"</code>.
An application may additionally choose to listen for the
<code><a data-link-for="RTCPeerConnection">iceConnectionState</a></code> transition to
<code>"<a data-link-for="RTCIceConnectionState">disconnected</a>"</code>
and then use other sources of information (such as using
<code><a data-link-for="RTCPeerConnection">getStats</a></code> to measure if the number of bytes sent
or received over the next couple of seconds increases) to determine
whether an ICE restart is advisable.</p>
</dd>
</dl>
</section>
</div>
<div>
<p>The <dfn>RTCAnswerOptions</dfn> dictionary describe options specific to session description of type <code>answer</code> (none in this version of the specification).</p>
<pre class="idl">
dictionary RTCAnswerOptions : RTCOfferAnswerOptions {
};</pre>
</div>
</section>
</section>
<section>
<h3>State Definitions</h3>
<section>
<h4><dfn>RTCSignalingState</dfn> Enum</h4>
<div>
<pre class="idl">enum RTCSignalingState {
"stable",
"have-local-offer",
"have-remote-offer",
"have-local-pranswer",
"have-remote-pranswer",
"closed"
};</pre>
<table data-link-for="RTCSignalingState" data-dfn-for=
"RTCSignalingState" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description</th>
</tr>
<tr>
<td data-tests="RTCPeerConnection-onsignalingstatechanged.https.html,RTCPeerConnection-setRemoteDescription.html"><dfn data-idl><code>stable</code></dfn></td>
<td>There is no offer/answer exchange in progress. This is
also the initial state, in which case the local and remote
descriptions are empty.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-createOffer.html, RTCPeerConnection-setLocalDescription-offer.html,RTCPeerConnection-setLocalDescription.html,RTCPeerConnection-setRemoteDescription.html"><dfn data-idl><code>have-local-offer</code></dfn></td>
<td>A local description, of type <code>"offer"</code>, has been successfully
applied.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-setLocalDescription-answer.html,RTCPeerConnection-setRemoteDescription-offer.html,RTCPeerConnection-setRemoteDescription-rollback.html,RTCPeerConnection-setRemoteDescription.html"><dfn data-idl><code>have-remote-offer</code></dfn></td>
<td>A remote description, of type <code>"offer"</code>, has been
successfully applied.</td>
</tr>
<tr>
<td><dfn data-idl><code>have-local-pranswer</code></dfn></td>
<td>A remote description of type <code>"offer"</code> has been successfully
applied and a local description of type <code>"pranswer"</code> has been
successfully applied.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-setRemoteDescription-pranswer.html,RTCPeerConnection-setRemoteDescription.html"><dfn data-idl><code>have-remote-pranswer</code></dfn></td>
<td>A local description of type <code>"offer"</code> has been successfully
applied and a remote description of type <code>"pranswer"</code> has been
successfully applied.</td>
</tr>
<tr>
<td><dfn data-idl><code>closed</code></dfn></td>
<td>The <code><a>RTCPeerConnection</a></code> has been closed;
its <a>[[\IsClosed]]</a> slot is <code>true</code>.</td>
</tr>
</tbody>
</table>
</div>
<figure>
<img alt="signalling state transition diagram" src=
"images/peerstates.svg" width="600">
<figcaption>
Non-normative signalling state transitions diagram. Method calls abbreviated.
</figcaption>
</figure>
<p>An example set of transitions might be:</p>
<dl>
<dt>Caller transition:</dt>
<dd>
<ul>
<li>new RTCPeerConnection(): <code>stable</code></li>
<li>setLocalDescription(offer): <code>have-local-offer</code></li>
<li>setRemoteDescription(pranswer): <code>have-remote-pranswer</code></li>
<li>setRemoteDescription(answer): <code>stable</code></li>
</ul>
</dd>
<dt>Callee transition:</dt>
<dd>
<ul>
<li>new RTCPeerConnection(): <code>stable</code></li>
<li>setRemoteDescription(offer): <code>have-remote-offer</code></li>
<li>setLocalDescription(pranswer): <code>have-local-pranswer</code></li>
<li>setLocalDescription(answer): <code>stable</code></li>
</ul>
</dd>
</dl>
</section>
<section>
<h4><dfn>RTCIceGatheringState</dfn> Enum</h4>
<div>
<pre class="idl">enum RTCIceGatheringState {
"new",
"gathering",
"complete"
};</pre>
<table data-link-for="RTCIceGatheringState" data-dfn-for=
"RTCIceGatheringState" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description</th>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceGatheringState.html"><dfn data-idl><code>new</code></dfn></td>
<td>Any of the <code><a>RTCIceTransport</a></code>s are in the
<code>"new"</code> gathering state and none of the transports are
in the <code>"gathering"</code> state, or there are no
transports.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceGatheringState.html"><dfn data-idl><code>gathering</code></dfn></td>
<td>Any of the <code><a>RTCIceTransport</a></code>s are in the
<code>"gathering"</code> state.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceGatheringState.html"><dfn data-idl><code>complete</code></dfn></td>
<td>At least one <code><a>RTCIceTransport</a></code> exists,
and all <code><a>RTCIceTransport</a></code>s are in the
<code>"completed"</code> gathering state.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h4><dfn>RTCPeerConnectionState</dfn> Enum</h4>
<div>
<pre class="idl">enum RTCPeerConnectionState {
"closed",
"failed",
"disconnected",
"new",
"connecting",
"connected"
};</pre>
<table data-link-for="RTCPeerConnectionState" data-dfn-for=
"RTCPeerConnectionState" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description</th>
</tr>
<tr>
<td><dfn data-idl><code>closed</code></dfn></td>
<td>
The <code><a>RTCPeerConnection</a></code> object's
<a>[[\IsClosed]]</a> slot is <code>true</code>.
</td>
</tr>
<tr>
<td><dfn data-idl><code>failed</code></dfn></td>
<td>The previous state doesn't apply and any
<code><a>RTCIceTransport</a></code>s or
<code><a>RTCDtlsTransport</a></code>s are in the
<code>"failed"</code> state.</td>
</tr>
<tr>
<td><dfn data-idl><code>disconnected</code></dfn></td>
<td>None of the previous states apply and any
<code><a>RTCIceTransport</a></code>s or
<code><a>RTCDtlsTransport</a></code>s are in the
<code>"disconnected"</code> state.</td>
</tr>
<tr>
<td><dfn data-idl><code>new</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s and
<code><a>RTCDtlsTransport</a></code>s are in the
<code>"new"</code> or <code>"closed"</code> state, or there are
no transports.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-connectionState.html"><dfn data-idl><code>connecting</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s or
<code><a>RTCDtlsTransport</a></code>s are in the
<code>"new"</code>, <code>"connecting"</code> or <code>"checking"</code> state.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-connectionState.html"><dfn data-idl><code>connected</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s and
<code><a>RTCDtlsTransport</a></code>s are in the
<code>"connected"</code>, <code>"completed"</code> or
<code>"closed"</code> state.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h4><dfn>RTCIceConnectionState</dfn> Enum</h4>
<div>
<pre class="idl">enum RTCIceConnectionState {
"closed",
"failed",
"disconnected",
"new",
"checking",
"completed",
"connected"
};</pre>
<table data-link-for="RTCIceConnectionState" data-dfn-for=
"RTCIceConnectionState" class="simple">
<tbody>
<tr>
<th colspan="2">Enumeration description</th>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceConnectionState.https.html"><dfn data-idl><code>closed</code></dfn></td>
<td>
The <code><a>RTCPeerConnection</a></code> object's
<a>[[\IsClosed]]</a> slot is <code>true</code>.
</td>
</tr>
<tr>
<td><dfn data-idl><code>failed</code></dfn></td>
<td>The previous state doesn't apply and any
<code><a>RTCIceTransport</a></code>s are in the
<code>"failed"</code> state.</td>
</tr>
<tr>
<td><dfn data-idl><code>disconnected</code></dfn></td>
<td>None of the previous states apply and any
<code><a>RTCIceTransport</a></code>s are in the
<code>"disconnected"</code> state.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceConnectionState.https.html,no-media-call.html"><dfn data-idl><code>new</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s are in the
<code>"new"</code> or <code>"closed"</code> state,
or there are no transports.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceConnectionState.https.html,no-media-call.html"><dfn data-idl><code>checking</code></dfn></td>
<td>None of the previous states apply and any
<code><a>RTCIceTransport</a></code>s are in the
<code>"new"</code> or <code>"checking"</code> state.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceConnectionState.https.html"><dfn data-idl><code>completed</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s are in the
<code>"completed"</code> or <code>"closed"</code> state.</td>
</tr>
<tr>
<td data-tests="RTCPeerConnection-iceConnectionState.https.html"><dfn data-idl><code>connected</code></dfn></td>
<td>None of the previous states apply and all
<code><a>RTCIceTransport</a></code>s are in the
<code>"connected"</code>, <code>"completed"</code> or
<code>"closed"</code> state.</td>
</tr>
</tbody>
</table>
</div>
<p>Note that if an <code><a>RTCIceTransport</a></code> is discarded as
a result of signaling (e.g. RTCP mux or bundling), or created as a
result of signaling (e.g. adding a new <a>media description</a>), the
state may advance directly from one state to another.</p>
</section>
</section>
<section>
<h3>RTCPeerConnection Interface</h3>
<p>The [[!JSEP]] specification, as a whole, describes the details of how
the <code><a>RTCPeerConnection</a></code> operates. References to
specific subsections of [[!JSEP]] are provided as appropriate.</p>
<section>
<h4>Operation</h4>
<p>Calling <code>new <a>RTCPeerConnection</a>(<var>configuration</var>)
</code> creates an <code><a>RTCPeerConnection</a></code> object.</p>
<p><code><var>configuration</var>.servers</code> contains information
used to find and access the servers used by ICE. The application can
supply multiple servers of each type, and any TURN server MAY also be
used as a STUN server for the purposes of gathering server reflexive
candidates.</p>
<p>An <code><a>RTCPeerConnection</a></code> object has a <dfn>signaling
state</dfn>, a <dfn>connection state</dfn>, an <dfn>ICE gathering
state</dfn>, and an <dfn>ICE connection state</dfn>. These are
initialized when the object is created.</p>
<p data-link-for="RTCPeerConnection">The ICE protocol implementation of
an <code><a>RTCPeerConnection</a></code> is represented by an <dfn>ICE
agent</dfn> [[!ICE]]. Certain <code><a>RTCPeerConnection</a></code>
methods involve interactions with the <a>ICE Agent</a>, namely
<code><a>addIceCandidate</a></code>, <code><a>setConfiguration</a></code>,
<code><a>setLocalDescription</a></code>,
<code><a>setRemoteDescription</a></code> and <code><a>close</a></code>.
These interactions are described in the relevant sections in this
document and in [[!JSEP]]. The <a>ICE Agent</a> also provides
indications to the user agent when the state of its internal
representation of an <code><a>RTCIceTransport</a></code> changes, as
described in <a href= "#rtcicetransport"></a>.</p>
<p>The task source for the tasks listed in this section is the
<a>networking task source</a>.</p>
<section>
<h4>Constructor</h4>
<p>When the <dfn id=