forked from w3c/webrtc-pc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebrtc.html
7774 lines (6238 loc) · 311 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 streams to remote peers and receiving
streams 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=
"http://www.w3.org/2011/04/webrtc/">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>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> and <dfn><a href=
"http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">fires a
simple event</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>,
<dfn>Constraints</dfn>, and <dfn>Consumer</dfn> are defined in
[[!GETUSERMEDIA]].</p>
</section>
<section>
<h2>Peer-to-peer connections</h2>
<section>
<h3>Introduction</h3>
<p>An <code><a>RTCPeerConnection</a></code> allows two users to
communicate directly, browser to browser. 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]].</p>
</section>
<section>
<h3>Configuration</h3>
<section>
<h4>RTCConfiguration Type</h4>
<dl class="idl" title="dictionary RTCConfiguration">
<dt>sequence<RTCIceServer> iceServers</dt>
<dd>
<p>An array containing URIs of 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 ICE engine is allowed to use.</p>
</dd>
<dt>RTCBundlePolicy bundlePolicy = "balanced"</dt>
<dd>
<p>Indicates which <a href="#target-bundle-policy">BundlePolicy</a> to use. </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 [[!RTCWEB-JSEP]]
Section 3.4.4 and 4.1.1.</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>
<div class="issue">
<p>Should we have a "none" type, for cases where no authentication is
needed? (e.g. STUN)
</p>
</div>
</section>
<section>
<h4>RTCIceServer Type</h4>
<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>In network topologies with multiple layers of NATs, it is desirable
to have a STUN server between every layer of NATs in addition to the
TURN servers to minimize the peer to peer network latency.</p>
<p>An example array of RTCIceServer objects is:</p>
<p><code>[
{ "urls": "stun:stun1.example.net" },
{ "urls": ["turns:turn.example.org", "turn:turn.example.net"],
"username": "user",
"credential": "myPassword",
"credentialType": "password" }
]</code></p>
</section>
<section>
<h4>RTCIceTransportPolicy Enum</h4>
<dl class="idl" title="enum RTCIceTransportPolicy">
<dt>none</dt>
<dd>The ICE engine MUST not send or receive any packets at this
point.</dd>
<dt>relay</dt>
<dd>The ICE engine 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 ICE engine may use any type of candidates when this value is
specified.</dd>
</dl>
</section>
<section>
<h4>RTCBundlePolicy Enum</h4>
Defined in [[!RTCWEB-JSEP]]. The following is a non-normative
summary for convenience.
The BundlePolicy effects 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.
<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>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 system 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>long offerToReceiveVideo</dt>
<dd>
<p>In some cases, an <code>RTCPeerConnection</code> may wish to
receive video but not send any video. The
<code>RTCPeerConnection</code> needs to know if it should signal to
the remote side whether it wishes to receive video or not. This
option allows an application to indicate its preferences for the
number of video streams to receive when creating an offer.</p>
</dd>
<dt>long offerToReceiveAudio</dt>
<dd>
<p>In some cases, an <code>RTCPeerConnection</code> may wish to
receive audio but not send any audio. The
<code>RTCPeerConnection</code> needs to know if it should signal to
the remote side whether it wishes to receive audio. This option
allows an application to indicate its preferences for the number of
audio streams to receive when creating an offer.</p>
</dd>
<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
[[!RTCWEB-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]],
RTCPeerConnection signaling state, ICE gathering state, and ICE
connection state. 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 href=
"#dom-peerconnection-signaling-state"><code>RTCPeerConnection</code>
signalingState</a> to <code>stable</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s <a href=
"#dom-peerconnection-ice-connection-state"><code>RTCPeerConnection</code>
ice connection state</a> to <code>new</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s <a href=
"#dom-peerconnection-ice-gathering-state"><code>RTCPeerConnection</code>
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 to represent a queue of
<code>operations</code> with an empty set.</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
<code>operations</code> array.</p>
</li>
<li>
<p>If the length of the <code>operations</code> 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 <code>operations</code> 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 <a href=
"#dom-peerconnection-ice-gathering-state"><code>RTCPeerConnection</code>
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 set the <a href=
"#dom-peerconnection-ice-gathering-state">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, the ICE connection
state is changed to "connected".</p>
</li>
<li>
<p>When the ICE Agent finishes checking all candidate pairs, if at
least one connection has been found for each <code>MediaStreamTrack</code>, the
<a href=
"#dom-peerconnection-ice-connection-state"><code>RTCPeerConnection</code>
ice connection state</a> is changed to "completed"; otherwise
"failed".</p>
</li>
</ol>
<div class="issue">
<p>The section above shouldn't need to reference MediaStreamTracks when
discussing the ICE connection state; one problem with this is that
it doesn't handle the data channel situation properly.
Rewrite this to refer to m-lines or ICE "media streams" or some such
(here and in the later ICE connection state discussions.)
</p>
</div>
<p>When the ICE Agent needs to notify the script about the candidate
gathering progress, 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 href=
"#dom-peerconnection-signaling-state"><code>RTCPeerConnection</code>
signalingState</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>Set <var>connection</var>'s <a href=
"#dom-peerconnection-ice-gathering-state">ice gathering
state</a> to <code>completed</code> and let
<var>newCandidate</var> be null.</p>
</li>
</ul>
</li>
<li>
<p>Fire a icecandidate event named <code><a href=
"#event-icecandidate">icecandidate</a></code> with
<var>newCandidate</var> at <var>connection</var>.</p>
</li>
</ol>
<p>The task source for the <span title="concept-task">tasks</span>
listed in this section is the networking task source.</p>
<p class="warning">To prevent network sniffing from allowing a fourth
party to establish a connection to a peer using the information sent
out-of-band to the other peer and thus spoofing the client, the
configuration information SHOULD always be transmitted using an
encrypted connection.</p>
</section>
<section>
<h3>Interface Definition</h3>
<p>The <code><a>RTCPeerConnection</a></code> interface presented this
section is not complete. The interface 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>MediaStream</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 options 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
createOffer is called after the session is established, createOffer
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 streams. 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 createOffer MUST be
immediately usable by setLocalDescription without causing an error
as long as setLocalDescription is called reasonably soon.
If a system has limited resources (e.g. a finite number
of decoders), createOffer needs to return an offer that reflects
the current state of the system, so that setLocalDescription will
succeed when it attempts to acquire those resources. The session
descriptions MUST remain usable by setLocalDescription 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>
<p>The value for <code>certificates</code> in
the <code><a>RTCConfiguration</a></code> for
the <code>RTCPeerConnection</code> is used to produce a set of
certificate fingerprints. These certificate fingerprints are used
in the construction of SDP and as input to requests for identity
assertions.</p>
<p>If the <code>RTCPeerConnection</code> is configured to generate
Identity assertions by calling <a>setIdentityProvider</a>, then the
session description SHALL contain an appropriate assertion. If the
identity provider is unable to produce an identity assertion, the
call to <code>createOffer</code> MUST be rejected with a
<code>DOMError</code> that has a name of IdpError.</p>
<p>If this <code>RTCPeerConnection</code> object is closed before
the SDP generation process completes, the USER agent MUST suppress
the result and not resolve or reject the returned promise.</p>
<p>If the SDP generation process completed successfully, the user
agent MUST resolve the returned promise with a
newly created <code><a>RTCSessionDescription</a></code> object,
representing the generated offer.</p>
<p>If the SDP generation process failed for any other reason, the
user agent MUST reject the returned promise with an
<code>DOMError</code> object of type TBD as its argument.</p>
<p class="issue">To Do: Discuss privacy aspects of this from a fingerprinting
point of view - it's probably around as bad as access to a canvas
:-)</p>
</dd>
<dt>Promise<RTCSessionDescription> createAnswer (optional
RTCAnswerOptions options)</dt>
<dd>
<p>The createAnswer method generates an [[!SDP]] answer with the
supported configuration for the session that is compatible with the
parameters in the remote configuration. Like createOffer, the
returned blob contains descriptions of the local MediaStreams
attached to this RTCPeerConnection, the codec/RTP/RTCP options
negotiated for this session, and any candidates that have been
gathered by the ICE Agent. The options parameter may be supplied to
provide additional control over the generated answer.</p>
<p>As an answer, the generated SDP will contain a specific
configuration that, along with the corresponding offer, specifies
how the media plane should be established. The generation of the
SDP MUST follow the appropriate process for generating an
answer.</p>
<p>Session descriptions generated by createAnswer MUST be
immediately usable by setLocalDescription without causing an
error as long as setLocalDescription is called reasonably soon.
Like createOffer, the returned description SHOULD reflect
the current state of the system. The session descriptions MUST
remain usable by setLocalDescription 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>
<p>An answer can be marked as provisional, as described in
[[!RTCWEB-JSEP]], by setting the <code><a href=
"#widl-RTCSessionDescription-type">type</a></code> to
<code>"pranswer"</code>.</p>
<p>If the <code>RTCPeerConnection</code> is configured to generate
Identity assertions by calling <a>setIdentityProvider</a>, then the
session description SHALL contain an appropriate assertion. If the
identity provider is unable to produce an identity assertion, the
call to <code>createAnswer</code> MUST be rejected with a
<code>DOMError</code> that has a name of IdpError.</p>
<p>If this <code>RTCPeerConnection</code> object is closed before
the SDP generation process completes, the USER agent MUST suppress
the result and not resolve or reject the returned promise.</p>
<p>If the SDP generation process completed successfully, the user
agent MUST resolve the returned promise with a
newly created <code><a>RTCSessionDescription</a></code> object,
representing the generated answer.</p>
<p>If the SDP generation process failed for any reason, the user
agent MUST reject the returned promise with a <code>DOMError</code>
object of type TBD.</p>
<p class="issue">TODO: define type of error for SDP generation</p>
</dd>
<dt>Promise<void> setLocalDescription (
RTCSessionDescriptionInit description)</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-setlocaldescription"><code>setLocalDescription()</code></dfn>
method instructs the <code><a>RTCPeerConnection</a></code> to apply
the supplied <code><a>RTCSessionDescriptionInit</a></code> as the local
description.</p>
<p>This API changes the local media state. In order to successfully
handle scenarios where the application wants to offer to change
from one media format to a different, incompatible format, the
<code><a>RTCPeerConnection</a></code> MUST be able to
simultaneously support use of both the current and pending local
descriptions (e.g. support codecs that exist in both descriptions)
until a final answer is received, at which point the
<code><a>RTCPeerConnection</a></code> can fully adopt the pending local
description, or rollback to the current description if the remote side
rejected the change. </p>
<p class="issue">To Do: specify what parts of the SDP can be changed between the
createOffer and setLocalDescription</p>
<p>The following list describes the <dfn id=
"set-description-model">processing model</dfn> for setting a new
<code><a>RTCSessionDescriptionInit</a></code>.</p>
<ul>
<li>
<p>When the method is invoked, the user agent MUST run the
following steps:</p>
<ol>
<li>
<p>Let <var>p</var> be a new promise.</p>
</li>
<li>
<p>If this <code><a>RTCPeerConnection</a></code> object's
<a href="#dom-peerconnection-signaling-state">signaling
state</a> is <code>closed</code>, the user agent MUST reject
<var>p</var> with <code>InvalidStateError</code>, and
jump to the step labeled <em>Return</em>.</p>
</li>
<li>
<p>If a local description contains a different set of ICE
credentials, then the ICE Agent MUST trigger an ICE restart.
When ICE restarts, the gathering state will be changed back to
"gathering", if it was not already gathering. If the <a href=
"#dom-peerconnection-ice-connection-state"><code>RTCPeerConnection</code>
ice connection state</a> was "completed", it will be changed
back to "connected".</p>
</li>
<li>
<p>The user agent MUST start the process to apply the
<code><a>RTCSessionDescriptionInit</a></code> argument.</p>
</li>
<li>
<p><em>Return:</em> Return <var>p</var>.</p>
</li>
</ol>
</li>
<li>
<p>If the process to apply the
<code><a>RTCSessionDescriptionInit</a></code> argument fails for
any reason, then user agent MUST queue a task runs the
following steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be the
<code><a>RTCPeerConnection</a></code> object on with this
method was invoked.</p>
</li>
<li>
<p>If <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state">signaling state</a>
is <code>closed</code>, then abort these steps.</p>
</li>
<li>
<p>If the reason for the failure is:</p>
<ul>
<li>
<p>The content of the
<code><a>RTCSessionDescriptionInit</a></code> argument is
invalid or the <code><a href=
"#widl-RTCSessionDescriptionInit-type">type</a></code> is
wrong for the current <a href=
"#dom-peerconnection-signaling-state">signaling
state</a> of <var>connection</var>.</p>
<p>Let <var>reason</var> be
<code>InvalidSessionDescriptionError</code>.</p>
</li>
<li>
<p>The <code><a>RTCSessionDescriptionInit</a></code> is a
valid description but cannot be applied at the media
layer.</p>
<p class="issue">TODO - next few points are probably wrong.
Make sure to check this in setRemote too.</p>
<p>This can happen, e.g., if there are insufficient
resources to apply the SDP. The user agent MUST then
rollback as necessary if the new description was
partially applied when the failure occurred.</p>
<p>If rollback was not necessary or was completed
successfully, let <var>reason</var> be
<code>IncompatibleSessionDescriptionError</code>. If
rollback was not possible, let <var>reason</var> be
<code>InternalError</code> and set
<var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state">signaling
state</a> to <code>closed</code>.</p>
</li>
</ul>
</li>
<li>
<p>Reject <var>p</var> with <var>reason</var>.</p>
</li>
</ol>
</li>
<li>
<p>If the <code><a>RTCSessionDescriptionInit</a></code> argument is
applied successfully, then user agent MUST queue a task (<dfn
id="setlocal-resolve">setLocalDescription() resolve task</dfn>)
that runs the following steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be the
<code><a>RTCPeerConnection</a></code> object on with this
method was invoked.</p>
</li>
<li>
<p>If <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state">signaling state</a>
is <code>closed</code>, then abort these steps.</p>
</li>
<li>
<p>If the local description was set, and the supplied
description matches the state of all
tracks and data channels,
<a href="#clearing-negotiation-needed">as defined
below</a>, clear the negotiation-needed flag.
</p>
</li>
<li>
<p>Set the <var>connection</var>'s description attributes
by executing one of the following. </p>
<p class="issue"> NOTE: The principles of pending and current SDP
were agreed by the WG but the details the this step has not
yet been fully reviewed. TODO - review this. </p>
<ul>
<!-- A transition stable to haveLocalOffer --> <li> <p>If
the local description was set, and the
<code><a>RTCSessionDescriptionInit</a></code> argument has a
type of "offer", and it has a version that is later than the
currentLocalDescription, then the pendingLocalDescription will be set to
the argument and the state will transition to
have-local-offer. </p> </li>
<!-- C transition haveRemoteOffer or haveLocalProvAnswer to
stable --> <li><p>If the local description was set, and the
<code><a>RTCSessionDescriptionInit</a></code> argument has a
type of "answer", then this completes an offer answer
negotiation and currentLocalDescription is set to the argument,
currentRemoteDescription is set to the value of pendingRemoteDescription,
then pendingRemoteDescription and pendingLocalDescription are set to null,
and the state will transitions to stable. </p> </li>
<!-- D transition stable to haveRemoteOffer --> <li> <p>If
the remote description was set, and the
<code><a>RTCSessionDescriptionInit</a></code> argument has a
type of "offer", and it has a version that is later than the