-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWebRTC 1.0 Real-time Communication Between Browsers.html
More file actions
4751 lines (3767 loc) · 186 KB
/
WebRTC 1.0 Real-time Communication Between Browsers.html
File metadata and controls
4751 lines (3767 loc) · 186 KB
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 name="generator" content=
"HTML Tidy for HTML5 (experimental) for Mac OS X https://github.com/w3c/tidy-html5/tree/c63cc39">
<title>WebRTC 1.0: Real-time Communication Between Browsers</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<!--
To publish this document, see instructions in README
-->
<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=
"http://datatracker.ietf.org/wg/rtcweb/">IETF RTCWEB group</a> and an API
specification to get access to local media devices developed by the
<a href="http://www.w3.org/2011/04/webrtc/">Media Capture Task
Force</a>.</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>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><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>
</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>.</p>
</section>
<section>
<h3>Configuration</h3>
<section>
<h4>RTCConfiguration Type</h4>
<dl class="idl" title="dictionary RTCConfiguration">
<dt>RTCIceServer[] iceServers</dt>
<dd>
<p>An array containing STUN and TURN servers available to be used
by ICE.</p>
</dd>
</dl>
</section>
<section>
<h4>RTCIceServer Type</h4>
<dl class="idl" title="dictionary RTCIceServer">
<dt>DOMString url</dt>
<dd>
<p>A STUN or TURN URI as defined in [[!STUN-URI]] and
[[!TURN-URI]].</p>
</dd>
<dt>DOMString? credential</dt>
<dd>
<p>If the url element of the internal array is a TURN URI, then
this is the credential to use with that TURN server.</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>[ { url:"stun:stun.example.net" } , {
url:"turn:user@turn.example.org", credential:"myPassword"} ]</code></p>
</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 [[!STUN]] and [[!TURN]] servers. 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
ICE agent[[!ICE]],
RTCPeerConnection signaling
state, ICE gathering state, and ICE connection state.
These are initialized when the object is
created.</p>
<p>An <code><a>RTCPeerConnection</a></code> object has two associated
stream sets. A <dfn id="local-streams-set">local streams set</dfn>,
representing streams that are currently sent, and a <dfn id=
"remote-streams-set">remote streams set</dfn>, representing streams that
are currently received with this
<code><a>RTCPeerConnection</a></code> object. The stream sets are
initialized to empty sets when the <code><a>RTCPeerConnection</a></code>
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. This algorithm
has a synchronous section (which is triggered as part of the event loop
algorithm).</p>
<ol>
<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 and provide it the STUN and TURN
servers from the configuration array. The ICE Agent will proceed
with gathering as soon as the IceTransports constraint is not set
to "none". 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>Initialize an internal variable to represent a queue of
<code>operations</code> with an empty set.</p>
</li>
<li>
<p>Return <var>connection</var>, but continue these steps
asynchronously.</p>
</li>
<li>
<p>Await a stable state. The synchronous section consists of the
remaining steps of this algorithm.</p>
</li>
</ol>
<p>Once the RTCPeerConnection object has been initialized, for every
call to <code>createOffer</code>, <code>setLocalDescription</code>,
<code>createAnswer</code> and <code>setRemoteDescription</code>;
execute the following steps:</p>
<ol>
<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 function from the front of the queue asynchronously.</p>
</li>
<li>
<p>When the asynchronous operation completes (either successfully
or with an error), remove the corresponding object from the
<code>operations</code> array. After removal, if the array is
non-empty, execute the first object queued asynchronously and
repeat this step on completion.</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> executing at any given time. If
subsequent calls are made while one of them is still executing, they
are added to a queue and processed when the previous operation is fully
completed. It is valid, and expected, for normal error handling
procedures to be applied.</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 <var>iceConnectionState</var> is <code>new</code> and the IceTransports constraint
is not set to <code>none</code>, it MUST queue a task to start gathering ICE
addresses and set the <var>iceConnectionState</var> to "gathering".</p>
</li>
<li>
<p>If the ICE Agent has found one or more candidate pairs for each
MediaStreamTrack 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 MediaStreamTrack, the
<var>iceConnectionState</var> is changed to "completed"; else the iceConnectionState is
changed to "failed".</p>
</li>
<li>
<p>If the <var>iceConnectionState</var> is "connected" or "completed" and
both the local and remote session descriptions have received a valid
SDP offer / answer pair, the
RTCPeerConnection state is set to "stable".</p>
</li>
<li>
<p>If the <var>iceConnectionState</var> is "failed", a task is queued to call
the close method.</p>
<p class="issue">Open Issue: CJ - this seems wrong to me - just
because a network connection failed does not mean the PC should be put
into a dead state it can not recover from.</p>
</li>
</ol>
<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> object 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>User agents negotiate the codec resolution, bitrate, and other media
parameters. It is RECOMMENDED that user agents initially negotiate for
the maximum resolution of a video stream. For streams that are then
rendered (using a <code>video</code> element), it is RECOMMENDED that
user agents renegotiate for a resolution that matches the rendered
display size.</p>
<p>The word "components" in this context refers to an RTP media flow
and does not have anything to do with how [[ICE]] uses the term
"component".</p>
<p>When a user agent has reached the point where a
<code><a>MediaStream</a></code> can be created to represent incoming
components, the user agent MUST run the following steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be the
<code><a>RTCPeerConnection</a></code> expecting this media.</p>
</li>
<li>
<p>Create a <code><a>MediaStream</a></code> object
<var>stream</var>, to represent the incoming media stream.
</p>
</li>
<li>
<p>Run the <a href="#represent-component-with-track">algorithm</a>
to represent an incoming component with a track for each incoming
component.</p>
<p class="note">The creation of new incoming
<code>MediaStream</code>s may be triggered either by SDP
negotiation or by the receipt of media on a given flow.
<!-- [[OPEN ISSUE: How many <code>MediaStream</code>s are created
when you receive multiple conflicting pranswers?]] --></p>
</li>
<li>
<p>Queue a task to run the following substeps:</p>
<ol>
<li>
<p>If the <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state"><code>RTCPeerConnection</code>
signalingState</a> is <code>closed</code>, abort these
steps.</p>
</li><!-- close() was probably called just before this
task ran -->
<li>
<p>Add <var>stream</var> to <var>connection</var>'s
<a href="#remote-streams-set">remote streams set</a>.</p>
</li>
<li>
<p><a href="#fire-a-stream-event">Fire a stream event</a> named
<code title="event-MediaStream-addstream"><a href=
"#event-mediastream-addstream">addstream</a></code> with
<var>stream</var> at the <var title="">connection</var> object.
</p>
</li>
</ol>
</li>
</ol>
<p>When a user agent has negotiated media for a component that belongs
to a media stream that is already represented by an existing
<code><a>MediaStream</a></code> object, the user agent MUST associate
the component with that <code><a>MediaStream</a></code> object.</p>
<p>When an <code><a>RTCPeerConnection</a></code> finds that a stream
from the remote peer has been removed, the user agent MUST follow these steps:</p>
<ol>
<li>
<p>Let <var>connection</var> be the
<code><a>RTCPeerConnection</a></code> associated with the stream
being removed.</p>
</li>
<li>
<p>Let <var>stream</var> be the <code><a>MediaStream</a></code>
object that represents the media stream being removed, if any. If
there isn't one, then abort these steps.</p>
</li>
<li>
<p>By definition, <var>stream</var> is now <a>finished</a>.</p>
<p class="note">A <span title="concept-task">task</span> is thus
<span title="queue a task">queued</span> to update
<var>stream</var> and fire an event.</p>
</li>
<li>
<p>Queue a task to run the following substeps:</p>
<ol>
<li>
<p>If the <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state"><code>RTCPeerConnection</code>
signalingState</a> is <code>closed</code>, abort these
steps.</p>
</li><!-- close() was probably called just before this
task ran -->
<li>
<p>Remove <var>stream</var> from <var>connection</var>'s
<a href="#remote-streams-set">remote streams set</a>.</p>
</li>
<li>
<p><a href="#fire-a-stream-event">Fire a stream event</a> named
<code title="event-MediaStream-removestream"><a href=
"#event-mediastream-removestream">removestream</a></code> with
<var title="">stream</var> at the <var>connection</var>
object.</p>
</li>
</ol>
</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>If something in the browser changes that causes the
<code><a>RTCPeerConnection</a></code> object to need to initiate a new
session description negotiation, a <code><a href=
"#event-negotiation">negotiationneeded</a></code> event is fired at the
<code><a>RTCPeerConnection</a></code> object.</p>
<p>In particular, if an <code><a>RTCPeerConnection</a></code> object is
<a title="consumer">consuming</a> a <code><a>MediaStream</a></code> on
which a track is added, by, e.g., the <code><a href=
"getusermedia.html#dom-mediastream-addtrack">addTrack()</a></code>
method being invoked, the <code><a>RTCPeerConnection</a></code> object
MUST fire the "negotiationneeded" event. Removal of media components
must also trigger "negotiationneeded".</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>
<dl class="idl" title=
"[Constructor (RTCConfiguration configuration, optional MediaConstraints constraints)] interface RTCPeerConnection : EventTarget ">
<!--
<dt>void getCapabilities ( RTCSessionDescriptionCallback
successCallback )</dt>
<dd>
<p> The getCapabilities method generates a blob of SDP that
contains a RFC offer that represets the most optimist view on
the capabilities of the media system. It does not reserver any
resources, ports, or other state but is meant to provide a way
to discover the types of capabilities of the browser including
which codecs may be supported. The SDP should have any ports set
to 0 (Open Issue: should this be 9?). Other values that would
allocate state should be set to static, unusable values. It
should include the SDP for media stream for each media type the
browser supports along with all the codecs that are supported.
It does not matter if any streams have been added to the
RTCPeerConnection object. </p>
<p> TODO - discuss privacy implications. </p>
</dd>
-->
<dt>void createOffer (RTCSessionDescriptionCallback successCallback,
RTCPeerConnectionErrorCallback failureCallback, optional
MediaConstraints constraints)</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 constraints parameter may
be supplied to provide additional control over the offer generated.
More information about constraints can be found in
[[!RTCWEB-CONSTRAINTS]].</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 within the successCallback
function. 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 end of the successCallback
function. Calling this method is needed to get the ICE user name
fragment and password.</p>
<p>If the <code>RTCPeerConnection</code> is configured to generate
Identity assertions, then the session description SHALL contain an
appropriate assertion.</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 call any of the result callbacks.</p>
<p>If the SDP generation process completed successfully, the user
agent MUST queue a task to invoke <var>successCallback</var> with a
newly created <code><a>RTCSessionDescription</a></code> object,
representing the generated offer, as its argument.</p>
<p>If the SDP generation process failed for any reason, the user
agent MUST queue a task to invoke <var>errorCallback</var> with an
<code>RTCError</code> object of type TBD as its argument.</p>
<p>An exception with an <code>RTCError</code> object of type
<code>INVALID_CONSTRAINTS_TYPE</code> is thrown if the constraints
parameter is malformed, and an <code>RTCError</code> object of type
<code>INCOMPATIBLE_CONSTRAINTS</code> is provided to the failure
callback if the constraints could not be successfully applied.</p>
<p>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>void createAnswer (RTCSessionDescriptionCallback successCallback,
RTCPeerConnectionErrorCallback failureCallback, optional
MediaConstraints constraints)</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 constraints 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 generating an
error if setLocalDescription is called from the successCallback
function. 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 successCallback function. 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, then the session description SHALL contain an
appropriate assertion.</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 call any of the result callbacks.</p>
<p>If the SDP generation process completed successfully, the user
agent MUST queue a task to invoke <var>successCallback</var> with a
newly created <code><a>RTCSessionDescription</a></code> object,
representing the generated answer, as its argument.</p>
<p>If the SDP generation process failed for any reason, the user
agent MUST queue a task to invoke <var>errorCallback</var> with an
<code>RTCError</code> object of type TBD as its argument.</p>
<p>An exception with an <code>RTCError</code> object of type
<code>INVALID_CONSTRAINTS_TYPE</code> is thrown if the constraints
parameter is malformed, and an <code>RTCError</code> object of type
<code>INCOMPATIBLE_CONSTRAINTS</code> is provided to the failure
callback if the constraints could not be successfully applied.</p>
</dd>
<dt>void setLocalDescription (RTCSessionDescription description,
VoidFunction successCallback, RTCPeerConnectionErrorCallback
failureCallback)</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>RTCSessionDescription</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 old and new 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 new local
description, or roll back to the old description if the remote side
denied the change.</p>
<p class="issue">ISSUE: how to indicate to roll back?</p>
<p>To Do: specify what parts of the SDP can be changed between the
createOffer and setLocalDescription</p>
<p>When the method is invoked, the user agent must follow the
<dfn id="set-description-model">processing model</dfn> described
by the following list:</p>
<ul>
<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 throw an exception with
an <code>RTCError</code> object of type <code>INVALID_STATE</code>
and abort this operation.</p>
</li>
<li>
<p>If a local description contains a different set of ICE
credentials, then the ICE Agent MUST trigger an ICE restart.
</p>
</li>
<li>
<p>If the process to apply the <code>
<a>RTCSessionDescription</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>RTCSessionDescription</a></code> argument is invalid
or the <code><a href=
"#widl-RTCSessionDescription-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>errorType</var> be
<code>INVALID_SESSION_DESCRIPTION</code>.</p>
</li>
<li>
<p>The <code><a>RTCSessionDescription</a></code> is
a valid description but cannot be applied at the media
layer.</p>
<p>This can happen, e.g., if there are
insufficient resources to apply the SDP. The user agent
MUST then roll back 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>errorType</var> be
<code>INCOMPATIBLE_SESSION_DESCRIPTION</code>. If
rollback was not possible, let <var>errorType</var> be
<code>INTERNAL_ERROR</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>Invoke the <var>failureCallback</var> with an
<code>RTCError</code> object, of type
<var>errorType</var>, as its argument.
</li>
</ol>
</li>
<li>
<p>If the <code><a>RTCSessionDescription</a></code> argument is
applied successfully, 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
metod 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>Set <var>connection</var>'s description attribute
(<code><a>localDescription</a></code> or <code>
<a>remoteDescription</a></code> depending on the setting
operation) to the <code><a>RTCSessionDescription</a></code>
argument.</p>
</li>
<li>
<p>If the local description was set,
<var>connection</var>'s <a href=
"#dom-peerconnection-ice-gathering-state">ice gathering
state</a> is <code>new</code>, and the local description
contains media, then set <var>connection</var>'s <a href=
"#dom-peerconnection-ice-gathering-state">ice gathering
state</a> to <code>gathering</code>.</p>
</li>
<li>
<p>If the local description was set with content that
caused an ICE restart, then set <var>connection</var>'s
<a href="#dom-peerconnection-ice-gathering-state">ice
gathering state</a> to <code>gathering</code>.</p>
</li>
<li>
<p>Set <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state">signalingState</a>
accordingly.</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>Queue a new task that, if <var>connection</var>'s <a href=
"#dom-peerconnection-signaling-state">signalingState</a>
is not <code>closed</code>, invokes the
<var>successCallback</var>.</p>
</li>
</ol>
</li>
</ul>
</dd>
<dt>readonly attribute RTCSessionDescription localDescription</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-localdescription"><code>localDescription</code></dfn>
attribute MUST return the <code><a>RTCSessionDescription</a></code>
that was most recently passed to <code><a href=
"#dom-peerconnection-setlocaldescription">setLocalDescription()</a></code>,
plus any local candidates that have been generated by the ICE Agent
since then.</p>
<p>A null object will be returned if the local description has not
yet been set.</p>
</dd>
<dt>void setRemoteDescription (RTCSessionDescription description,
VoidFunction successCallback, RTCPeerConnectionErrorCallback
failureCallback)</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-setremotedescription"><code>setRemoteDescription()</code></dfn>
method instructs the <code><a>RTCPeerConnection</a></code> to apply
the supplied <code><a>RTCSessionDescription</a></code> as the
remote offer or answer. This API changes the local media state.</p>
<p>If <code>a=identity</code> attributes are present, the browser
verifies the identity following the procedures in [XREF
sec.identity-proxy-assertion-request].</p>
<p>When the method is invoked, the user agent must follow the
<a href="#set-description-model">processing model</a> of
<code><a href=
"#dom-peerconnection-setlocaldescription">setLocalDescription()</a>
</code>.</p>
</dd>
<dt>readonly attribute RTCSessionDescription remoteDescription</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-remotedescription"><code>remoteDescription</code></dfn>
attribute MUST return the <code><a>RTCSessionDescription</a></code>
that was most recently passed to <code><a href=
"#dom-peerconnection-setremotedescription">setRemoteDescription()</a></code>,
plus any remote candidates that have been supplied via
<code><a href=
"#dom-peerconnection-addicecandidate">addIceCandidate()</a></code>
since then.</p>
<p>A null object will be returned if the remote description has not
yet been set.</p>
</dd>
<dt>readonly attribute RTCSignalingState signalingState</dt>
<dd>
<p>The <dfn
id="dom-peerconnection-signaling-state"><code>signalingState</code></dfn>
attribute MUST return the
<code><a href="#dom-peerconnection-signaling-state">RTCPeerConnection</a></code> object's <a href=
"#dom-peerconnection-signaling-state"><code>RTCPeerConnection</code>
signaling state</a>.</p>
</dd>
<dt>void updateIce (optional RTCConfiguration configuration,
optional MediaConstraints constraints)</dt>
<dd>
<p>The updateIce method updates the ICE Agent process of gathering
local candidates and pinging remote candidates. If there is a
mandatory constraint called "IceTransports" it will control how the
ICE engine can act. This can be used to limit the use to TURN
candidates by a callee to avoid leaking location information prior
to the call being accepted.</p>
<p>This call may result in a change to the state of the ICE Agent,
and may result in a change to media state if it results in
connectivity being established.</p>
<div class="note">
This method was previously used to restart ICE. We should
document the new procedure in the correct place.
</div>
<p>An exception with an <code>RTCError</code> object of type
<code>INVALID_CONSTRAINTS_TYPE</code> is thrown if the constraints
parameter is malformed, and an <code>RTCError</code> object of type
<code>INCOMPATIBLE_CONSTRAINTS</code> is provided to the failure
callback if the constraints could not be successfully applied.</p>
</dd>
<dt>void addIceCandidate (RTCIceCandidate candidate)</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-addicecandidate"><code>addIceCandidate()</code></dfn>
method provides a remote candidate to the ICE Agent. In addition to
being added to the remote description, connectivity checks will be
sent to the new candidates as long as the "IceTransports"
constraint is not set to "none". This call will result in a change
to the connection state of the ICE Agent, and may result in a change to media
state if it results in different connectivity being
established.</p>
<p>An exception with an <code>RTCError</code> object of type
<code>INVALID_CANDIDATE_TYPE</code> is thrown if candidate
parameter is malformed.</p>
</dd>
<dt>readonly attribute RTCIceGatheringState iceGatheringState</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-ice-gathering-state"><code>iceGatheringState</code></dfn>
attribute MUST return the gathering state of the <a href=
"#rtcpeerconnection-ice-agent"><code>RTCPeerConnection</code> ICE
Agent</a> connection state.</p>
</dd>
<dt>readonly attribute RTCIceConnectionState iceConnectionState</dt>
<dd>
<p>The <dfn id=
"dom-peerconnection-ice-connection-state"><code>iceConnectionState</code></dfn> attribute
MUST return the state of the <a href=
"#rtcpeerconnection-ice-agent"><code>RTCPeerConnection</code> ICE
Agent</a> ICE state.</p>
</dd>
<dt>sequence<MediaStream> getLocalStreams()</dt>
<dd>
<p>Returns a sequence of <code><a>MediaStream</a></code> objects
representing the streams that are currently sent with this