forked from w3c/webrtc-pc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webrtc.html
8498 lines (6799 loc) · 339 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>
<!--
To publish this document, see instructions in README
-->
<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="http://www.w3.org/Tools/respec/respec-w3c-common"
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>This document is neither complete nor stable, and as such is not yet
suitable for commercial implementation. However, early experimentation is
encouraged. The API is based on preliminary work done in the WHATWG. The
Web Real-Time Communications Working Group expects this specification to
evolve significantly based on:</p>
<ul>
<li>The outcome of ongoing exchanges in the companion RTCWEB group at
IETF to define the set of protocols that, together with this document,
will enable real-time communications in Web browsers.</li>
<li>Privacy issues that arise when exposing local capabilities and local
streams.</li>
<li>Technical discussions within the group.</li>
<li>Experience gained through early experimentations.</li>
<li>Feedback received from other groups and individuals.</li>
</ul>
</section>
<section class="informative" id="intro">
<h2>Introduction</h2>
<p>There are a number of facets to 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 with the exception of the <code><a>RTCIdentityProvider</a></code>
interface which is used by the
user agent but not implemented by the user agent.</p>
<p>It also defines conformance criteria for identity providers which provide
implementations of the <code><a>RTCIdentityProvider</a></code>
interface.</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]], as
this specification uses that specification and terminology.</p>
</section>
<section>
<h2>Terminology</h2>
<p>The <code><a href=
"http://dev.w3.org/html5/spec/webappapis.html#eventhandler">EventHandler</a></code>
interface represents a callback used for event handlers as defined in
[[!HTML5]].</p>
<p>The concepts <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">queue a
task</a></dfn>, <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fire a
simple event</a></dfn> and <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#networking-task-source">networking task source</a></dfn> are defined in [[!HTML5]].</p>
<p>The terms <dfn>event</dfn>, <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#event-handlers">event
handlers</a></dfn> and <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#event-handler-event-type">event
handler event types</a></dfn> are defined in [[!HTML5]].</p>
<p>The terms <dfn>MediaStream</dfn>, <dfn>MediaStreamTrack</dfn>, and
<dfn>MediaStreamConstraints</dfn> are defined in [[!GETUSERMEDIA]].</p>
<p>The term <dfn>media description</dfn> is defined in [[!RFC4566]].</p>
</section>
<section>
<h2>Peer-to-peer connections</h2>
<section>
<h3>Introduction</h3>
<p>An <code><a>RTCPeerConnection</a></code> instance allows to establish
peer to peer communications. Communications are coordinated
via 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>RTCConfiguration 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>
<dl class="idl" title="dictionary RTCConfiguration">
<dt>sequence<RTCIceServer> iceServers</dt>
<dd>
<p>An array of objects describing servers available to be used by ICE,
such as STUN and TURN server.</p>
</dd>
<dt>RTCIceTransportPolicy iceTransportPolicy = "all"</dt>
<dd>
<p>Indicates which candidates the <a>ICE agent</a> is allowed to use.</p>
</dd>
<dt>RTCBundlePolicy bundlePolicy = "balanced"</dt>
<dd>
<p>Indicates which <a href="#target-bundle-policy">media-bundling policy</a> to use when gathering ICE candidates. </p>
</dd>
<dt>RTCRtcpMuxPolicy rtcpMuxPolicy = "require"</dt>
<dd>
<p>Indicates which <a href="#target-rtcp-mux-policy">rtcp-mux policy</a> to use when gathering ICE candidates. </p>
</dd>
<dt>DOMString peerIdentity</dt>
<dd>
<p>Sets the <a href="#target-peer-identity">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>sequence<RTCCertificate> certificates</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 href="#widl-RTCPeerConnection-generateCertificate-Promise-RTCCertificate--AlgorithmIdentifier-keygenAlgorithm"><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 set of certificates are 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. Attempts to change this value MUST be
rejected.</p>
</dd>
<dt>unsigned short iceCandidatePoolSize = 0</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>
<section>
<h4>RTCIceCredentialType Enum</h4>
<dl class="idl" title="enum RTCIceCredentialType">
<dt>password</dt>
<dd>The credential is a long-term authentication password, as
described in [[!RFC5389]], Section 10.2.
</dd>
<dt>token</dt>
<dd>The credential is an access token, as described in
[[!TRAM-TURN-THIRD-PARTY-AUTHZ]], Section 6.2.</dd>
</dl>
</section>
<section>
<h4>RTCIceServer 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>
<dl class="idl" title="dictionary RTCIceServer">
<dt>required (DOMString or sequence<DOMString>) urls</dt>
<dd>
<p>STUN or TURN URI(s) as defined in [[!RFC7064]] and [[!RFC7065]]
or other URI types.</p>
</dd>
<dt>DOMString username</dt>
<dd>
<p>If this <code><a>RTCIceServer</a></code> object represents a
TURN server, then this attribute specifies the username to use with
that TURN server.</p>
</dd>
<dt>DOMString credential</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>
</dd>
<dt>RTCIceCredentialType credentialType = "password"</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>
<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" }
]</code></pre>
</section>
<section>
<h4>RTCIceTransportPolicy Enum</h4>
<p>As noted in <span data-jsep="constructor">[[!JSEP]]</span>, if RTCIceTransportPolicy is specified,
it causes the browser to only surface the permitted
candidates to the application, and only use those candidates for
connectivity checks.</p>
<dl class="idl" title="enum RTCIceTransportPolicy">
<dt>public</dt>
<dd>The <a>ICE agent</a> MUST filter out candidates with private
IP addresses [[RFC1918]].</dd>
<dt>relay</dt>
<dd>The <a>ICE agent</a> MUST only use media relay candidates such as
candidates passing through a TURN server. This can be used to reduce
leakage of IP addresses in certain use cases.</dd>
<dt>all</dt>
<dd>The <a>ICE agent</a> may use any type of candidates when this value is
specified.</dd>
</dl>
</section>
<section>
<h4>RTCBundlePolicy 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>
<dl class="idl" title="enum RTCBundlePolicy" id="target-bundle-policy">
<dt>balanced</dt>
<dd>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.</dd>
<dt>max-compat</dt>
<dd>Gather ICE candidates for each track. If the remote
endpoint is not BUNDLE-aware, negotiate all media tracks on
separate transports.</dd>
<dt>max-bundle</dt>
<dd>Gather ICE candidates for only one track. If the remote
endpoint is not BUNDLE-aware, negotiate only one media
track.</dd>
</dl>
</section>
<section>
<h4>RTCRtcpMuxPolicy Enum</h4>
<p>Defined in <span data-jsep="constructor">[[!JSEP]]</span>. The following is a
non-normative summary for convenience.</p>
<p>The RtcpMuxPolicy affects what ICE candidates are gathered
to support non-multiplexed RTCP.</p>
<dl class="idl" title="enum RTCRtcpMuxPolicy" id="target-rtcp-mux-policy">
<dt>negotiate</dt>
<dd>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.</dd>
<dt>require</dt>
<dd>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.</dd>
</dl>
</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>
<dl class="idl" title="dictionary RTCOfferAnswerOptions">
<dt>boolean voiceActivityDetection = true</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>
<dl class="idl" title="dictionary RTCOfferOptions : RTCOfferAnswerOptions">
<dt>boolean iceRestart = false</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>localDescription</a></code> attribute's SDP). Applying the
generated description will restart ICE.</p>
<p>When the value of this dictionary member is false, and the
<code><a>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>localDescription</a></code> attribute.</p>
</dd>
</dl>
<dl class="idl" title="dictionary RTCAnswerOptions : RTCOfferAnswerOptions">
</dl>
</section>
</section>
<section>
<h3>RTCPeerConnection Interface</h3>
<p>The general operation of the RTCPeerConnection is described in
[[!JSEP]].</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>The <var>configuration</var> has the information to find and access
the servers used by ICE. There may be multiple servers of each type and
any TURN server also acts as a STUN server.</p>
<p>An <code><a>RTCPeerConnection</a></code> object has an associated
<dfn id="rtcpeerconnection-ice-agent">ICE agent</dfn> [[!ICE]],
<dfn>signaling state</dfn>, <dfn>ICE gathering state</dfn>, and <dfn>ICE
connection state</dfn>. These are initialized when the object is created.</p>
<p>When the <dfn id=
"dom-peerconnection"><code>RTCPeerConnection()</code></dfn> constructor
is invoked, the user agent MUST run the following steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be a newly created
<code><a>RTCPeerConnection</a></code> object.</p>
</li>
<li>
<p><a href="#set-pc-configuration">Set the configuration</a>
specified by the constructor's first argument.</p>
</li>
<li>
<p>Create an ICE Agent as defined in [[!ICE]] and let
<var>connection</var>'s <code>RTCPeerConnection</code> ICE Agent be
that ICE Agent. The ICE Agent will
proceed with gathering as soon as the <a href=
"#ice-transports-setting">ICE transports setting</a> is not set to
<code>none</code>. At this point the ICE Agent does not know how
many ICE components it needs (and hence the number of candidates to
gather), but it can make a reasonable assumption such as 2. As the
<code>RTCPeerConnection</code> object gets more information, the
ICE Agent can adjust the number of components.</p>
</li>
<li>
<p>Set <var>connection</var>'s <a>
signaling state</a> to <code>stable</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s
<a>ICE connection state</a> to <code>new</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s <a>
ICE gathering state</a> to <code>new</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s
<code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>,
<code><a href=
"#dom-peerconnection-currentlocaldesc">currentLocalDescription</a></code>,
<code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
and <code><a href=
"#dom-peerconnection-currentremotedesc">currentRemoteDescription</a></code>
to null.
</p>
</li>
<li>
<p>Initialize an internal variable <var>operations</var> to represent a queue of
operations with an empty array.</p>
</li>
<li>
<p>If the <code>certificates</code> value in
the <code>RTCConfiguration</code> structure is non-empty, check that
the <code>expires</code> on each value is in the future. If a
certificate has expired, throw an <code>InvalidParameter</code>
exception and abort these steps; otherwise, store the certificates.
If no <code>certificates</code> value was specified, one or more
new <code>RTCCertificate</code> instances are generated for use with
this <code>RTCPeerConnection</code> instance.</p>
</li>
<li>
<p>Return <var>connection</var>.</p>
</li>
</ol>
<p>Once the RTCPeerConnection object has been initialized, for every
call to <code>createOffer</code>, <code>setLocalDescription</code>,
<code>createAnswer</code>, <code>setRemoteDescription</code>,
and <code>addIceCandidate</code>,
execute the following steps:</p>
<ol>
<li>
<p>Let <var>p</var> be a new promise.</p>
</li>
<li>
<p>Append an object representing the current call being handled
(i.e. function name and corresponding arguments) to the
<var>operations</var> array.</p>
</li>
<li>
<p>If the length of the <var>operations</var> array is exactly 1,
execute the object from the front of the queue.</p>
</li>
<li>
<p>Upon fulfillment or rejection of the promise returned
by the function, fulfill or reject <var>p</var> with the
corresponding value or reason. Upon fulfillment or
rejection of <var>p</var>, execute the following
steps:</p>
<ol>
<li><p>Remove the corresponding object from
the <var>operations</var> array.</p></li>
<li><p>If the array is non-empty, execute the first
object queued.</p></li>
</ol>
</li>
<li>
<p>Return <var>p</var>.</p>
</li>
</ol>
<p>The general idea is to have only one among <code>createOffer</code>,
<code>setLocalDescription</code>, <code>createAnswer</code> and
<code>setRemoteDescription</code>
and <code>addIceCandidate</code> executing at any given
time. If subsequent calls are made while the returned promise
of a previous call is still unsettled, they are added to a
queue and executed when all the previous calls are executed
and their promises are settled.</p>
<p>Additionally, during the lifetime of the RTCPeerConnection object,
the following procedures are followed when an ICE event occurs:</p>
<ol>
<li>
<p>If the <code>RTCPeerConnection</code>'s
<a>ICE gathering state</a> is <code>new</code> and the <a href=
"#ice-transports-setting">ICE transports setting</a> is not set to
<code>none</code>, the user agent MUST queue a task to start
gathering ICE addresses and <a>update the ICE gathering state</a>
to <code>gathering</code>.</p>
</li>
<li>
<p>If the ICE Agent has found one or more candidate pairs for each
<code>MediaStreamTrack</code> that forms a valid connection, <a>update the ICE connection
state</a> to <code>connected</code>.</p>
</li>
<li>
<p>When the ICE Agent finishes checking all candidate pairs, if at
least one connection has been found for each <a>media description</a>, <a>update the
ICE connection state</a> to <code>completed</code>, otherwise to
<code>failed</code>.</p>
</li>
</ol>
<p>When a new ICE candidate is available or when the ICE gathering process is done
, the user agent MUST queue a task to run the
following steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be the
<code><a>RTCPeerConnection</a></code> object associated with this
ICE Agent.</p>
</li>
<li>
<p>If <var>connection</var>'s
<a>signaling state</a> is <code>closed</code>, abort these steps.</p>
</li>
<li>
<p>If the intent of the ICE Agent is to notify the script that:</p>
<ul>
<li>
<p>A new candidate is available.</p>
<p>Add the candidate to <var>connection</var>'s
<code><a>localDescription</a></code> and create a
<code><a>RTCIceCandidate</a></code> instance to represent the
candidate. Let <var>newCandidate</var> be that object.</p>
</li>
<li>
<p>The gathering process is done.</p>
<p><a data-lt="update the ICE gathering state">Update <var>connection</var>'s ICE gathering
state</a> to <code>completed</code> and let
<var>newCandidate</var> be null.</p>
</li>
</ul>
</li>
<li>
<p>Fire an event named <code><a href=
"#event-icecandidate">icecandidate</a></code> with
<var>newCandidate</var> at <var>connection</var>.</p>
</li>
</ol>
<p>To <dfn id=
"update-ice-gathering-state">update the <a>ICE gathering state</a></dfn> of an
<code><a>RTCPeerConnection</a></code> instance <var>connection</var> to
<var>newState</var>, the User Agent MUST queue a task that sets
<var>connection</var>'s <a href=
"#dom-peerconnection-ice-gathering-state">iceGatheringState</a>
attribute to <var>newState</var> and fires a simple event named
<code><a href=
"#event-icegatheringstatechange">icegatheringstatechange</a></code> at
<var>connection</var>.</p>
<p>To <dfn id=
"update-ice-connection-state">update the <a>ICE connection state</a></dfn> of an
<code><a>RTCPeerConnection</a></code> instance <var>connection</var> to
<var>newState</var>, the User Agent MUST queue a task that sets
<var>connection</var>'s <a href=
"#dom-peerconnection-ice-connection-state">iceConnectionState</a>
attribute to <var>newState</var> and fires a simple event named
<code><a href=
"#event-iceconnectionstatechange">icegatheringstatechange</a></code> at
<var>connection</var>.</p>
<p>To <dfn id="set-description">set an RTCSessionDescription</dfn>
<var>description</var> on an <code><a>RTCPeerConnection</a></code>
object <var>connection</var>, run the following steps:</p>
<ol>
<li>
<p>If <var>connection</var>'s
<a>signaling
state</a> is <code>closed</code>, the user agent MUST return a
promise rejected with an <code>InvalidStateError</code>.</p>
</li>
<li>
<p>Let <var>p</var> be a new promise.</p>
</li>
<li>
<p>In parallel, start the process to apply <var>description</var> as
described in <span data-jsep="processing-a-local-desc processing-a-remote-desc">[[!JSEP]]</span>.</p>
<ol>
<li>
<p>If the process to apply <var>description</var> fails for
any reason, then user agent MUST queue a task runs the
following steps:</p>
<ol>
<li>
<p>If <var>connection</var>'s <a>signaling state</a>
is <code>closed</code>, then abort these steps.</p>
</li>
<li>
<p>If the content of <var>description</var> is invalid or if
<var>description</var>'s <code><a href=
"#widl-RTCSessionDescription-type">type</a></code> is wrong for
the current <a>signaling state</a> of
<var>connection</var>, then reject <var>p</var> with an
<code>InvalidSessionDescriptionError</code> and abort these
steps.</p>
</li>
<li>
<p>If <var>description</var> cannot be applied at the media
layer, but the User Agent recovered, possibly by rolling back
to the previous configuration, then reject <var>p</var> with
<code>IncompatibleSessionDescriptionError</code> and abort
these steps.</p>
<p>This occurs, for example, when the version of
<var>description</var> is older than the one currently
being used.</p>
</li>
<li>
<p>Otherwise, set <var>connection</var>'s <a>signaling state</a> to
<code>closed</code>.</p>
</li>
<li>
<p>Fire a simple event named <code><a href=
"#event-signalingstatechange">signalingstatechange</a></code>
at <var>connection</var>.</p>
</li>
<li>
<p>Reject <var>p</var> with <code>InternalError</code>.</p>
</li>
</ol>
</li>
<li>
<p>If <var>description</var> is applied successfully, the user
agent MUST queue a task that runs the following steps:</p>
<ol>
<li>
<p>If <var>connection</var>'s <a>signaling state</a>
is <code>closed</code>, then abort these steps.</p>
</li>
<li>
<p>If <var>description</var> is set as a local description, and
its content matches the state of all tracks and data channels,
<a href="#clearing-negotiation-needed">as defined below</a>,
clear the negotiation-needed flag.
</p>
<p class="issue">NOTE: The principles of pending and current SDP
were agreed by the WG but the details in the next steps have not
yet been fully reviewed. TODO - review this.</p>
</li>
<li>
<p>If <var>description</var> is set as a local description,
then run one of the following steps:</p>
<ul>
<!-- A) transition stable to haveLocalOffer -->
<li>
<p>If <var>description</var> is of type "offer",
set <var>connection</var>'s <code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>
attribute to <var>description</var> and <a>signaling state</a>
to <code>have-local-offer</code>.</p>
</li>
<!-- C) transition haveRemoteOffer or haveLocalProvAnswer to
stable -->
<li>
<p>If <var>description</var> is
of type "answer", then this completes an offer answer
negotiation. Set <var>connection</var>'s <code><a href=
"#dom-peerconnection-currentlocaldesc">currentLocalDescription</a></code>
to <var>description</var> and <code><a href=
"#dom-peerconnection-currentremotedesc">currentRemoteDescription</a></code>
to the value of <code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>.
Set both <code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
and <code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>
to null. Finally set <var>connection</var>'s <a>signaling state</a>
to <code>stable</code></p>
</li>
<!-- B) transition rollback to haveLocalOffer to stable -->
<li>
<p>If <var>description</var> is
of type "rollback", then this is a rollback. Set
<var>connection</var>'s <code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>
to null and <a>signaling state</a>
to <code>stable</code>.</p>
</li>
<!-- G) transition haveRemoteOffer to haveLocalProvAnswer -->
<li>
<p>If <var>description</var> is
of type "pranswer", then set <var>connection</var>'s
<code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>
to <var>description</var> and <a>signaling state</a>
to <code>have-local-pranswer</code>.</p>
</li>
</ul>
</li>
<li>
<p>Otherwise, if <var>description</var> is set as a remote
description, then run one of the following steps:</p>
<ul>
<!-- D) transition stable to haveRemoteOffer -->
<li>
<p>If <var>description</var> is
of type "offer",
set <var>connection</var>'s <code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
attribute to <var>description</var> and <a>signaling state</a>
to <code>have-remote-offer</code>.</p>
</li>
<!-- F) transition haveRemoteOffer or haveLocalProvAnswer to
stable -->
<li>
<p>If <var>description</var> is
of type "answer", then this completes an offer answer
negotiation. Set <var>connection</var>'s <code><a href=
"#dom-peerconnection-currentremotedesc">currentRemoteDescription</a></code>
to <var>description</var> and <code><a href=
"#dom-peerconnection-currentlocaldesc">currentLocalDescription</a></code>
to the value of <code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>.
Set both <code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
and <code><a href=
"#dom-peerconnection-pendinglocaldesc">pendingLocalDescription</a></code>
to null. Finally set <var>connection</var>'s <a>signaling state</a>
to <code>stable</code></p>
</li>
<!-- E) transition rollback to haveRemoteOffer to stable -->
<li>
<p>If <var>description</var> is
of type "rollback", then this is a rollback. Set
<var>connection</var>'s <code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
to null and <a>signaling state</a>
to <code>stable</code>.</p>
</li>
<!-- H) transition haveRemoteOffer to haveLocalProvAnswer -->
<li>
<p>If <var>description</var> is
of type "pranswer", then set <var>connection</var>'s
<code><a href=
"#dom-peerconnection-pendingremotedesc">pendingRemoteDescription</a></code>
to <var>description</var> and <a>signaling state</a>
to <code>have-remote-pranswer</code>.</p>
</li>
</ul>
</li>
<li>
<p>If <var>connection</var>'s <a>signaling state</a>
changed above, fire a simple event named <code><a href=
"#event-signalingstatechange">signalingstatechange</a></code>
at <var>connection</var>.</p>
</li>
<li>
<p>If <var>description</var> is set as a local description,
<var>connection</var>'s <a>ICE gathering
state</a> is <code>new</code>, and <var>description</var>
contains media, then <a data-lt="update the ICE gathering state">update <var>connection</var>'s
ICE gathering state</a> to <code>gathering</code>.</p>
</li>
<li>
<p>If the process to apply <var>description</var> resulted
in an ICE restart <span data-jsep="applying-a-local-desc applying-a-remote-desc">[[!JSEP]]</span>, then run the following
steps:</p>
<ol>
<li>
<p>If <var>connection</var> is not already gathering,
<a data-lt="update the ICE gathering state">update
<var>connection</var>'s ICE gathering state</a> to
<code>gathering</code>.</p>
</li>
<li>
<p>If <var>connection</var>'s <a>
ICE connection state</a>
is <code>completed</code>, <a data-lt="update the ICE connection state">update
<var>connection</var>'s ICE connection state</a> to
<code>connected</code>.</p>
</li>
</ol>
</li>
<li>
<p>If <var>description</var> is set as a remote description
with new media descriptions [[!JSEP]], the User Agent
MUST <a href="#dispatch-receiver">dispatch a receiver</a> for
all new media descriptions.</p>
</li>
<li>
<p>If <var>connection</var>'s <a>signaling state</a> is
now <code>stable</code>, and the negotiation-needed flag is
set, the User Agent MUST queue a task to fire a simple event
named <code><a href=
"#event-negotiation">negotiationneeded</a></code> at
<var>connection</var> and clear the negotiation-needed flag.</p>
</li>
<li>
<p>Resolve <var>p</var> with <var>undefined</var>.</p>
</li>
</ol>
</li>
</ol>
</li>
<li>
<p>Return <var>p</var>.</p>
</li>
</ol>
<p>The task source for the tasks
listed in this section is the <a>networking task source</a>.</p>
</section>
<section>
<h3>Interface Definition</h3>
<p>The <code><a>RTCPeerConnection</a></code> interface presented in this
section is extended by several partial
interfaces throughout this specification. Notably, the <a href=
"#rtcpeerconnection-interface-extensions">RTP Media section</a>, that
adds the APIs to send and receive <code><a>MediaStreamTrack</a></code>
objects.</p>
<dl class="idl" title="interface RTCPeerConnection : EventTarget ">
<dt>Constructor (optional RTCConfiguration configuration)</dt>
<dd>
See the <a href="#dom-peerconnection">RTCPeerConnection constructor
algorithm</a>.
</dd>
<dt>Promise<RTCSessionDescription> createOffer (
optional RTCOfferOptions options)</dt>
<dd>
<p>The createOffer method generates a blob of SDP that contains an
RFC 3264 offer with the supported configurations for the session,
including descriptions of the local <code>MediaStreamTrack</code>s
attached to this <code>RTCPeerConnection</code>, the codec/RTP/RTCP
options supported by this implementation, and any candidates that
have been gathered by the ICE Agent. The <code>options</code> parameter may be
supplied to provide additional control over the offer
generated.</p>
<p>As an offer, the generated SDP will contain the full set of
capabilities supported by the session (as opposed to an answer,
which will include only a specific negotiated subset to use); for
each SDP line, the generation of the SDP MUST follow the
appropriate process for generating an offer. In the event
<code>createOffer</code> is called after the session is established, <code>createOffer</code>
will generate an offer that is compatible with the current session,
incorporating any changes that have been made to the session since
the last complete offer-answer exchange, such as addition or
removal of tracks. If no changes have been made, the offer will
include the capabilities of the current local description as well
as any additional capabilities that could be negotiated in an
updated offer.</p>
<p>Session descriptions generated by <code>createOffer</code> MUST be
immediately usable by <code>setLocalDescription</code> without causing an error
as long as <code>setLocalDescription</code> is called reasonably soon.
If a system has limited resources (e.g. a finite number
of decoders), <code>createOffer</code> needs to return an offer that reflects
the current state of the system, so that <code>setLocalDescription</code> will
succeed when it attempts to acquire those resources. The session
descriptions MUST remain usable by <code>setLocalDescription</code> without
causing an error until at least the end of the fulfillment callback of the
returned promise. Calling this method is needed to get the ICE user name
fragment and password.</p>