-
Notifications
You must be signed in to change notification settings - Fork 18
/
webrtc.html
6226 lines (5050 loc) · 239 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<!--
To publish this document, see instructions in README
-->
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ns="http://www.w3.org/1999/xhtml">
<head>
<title>WebRTC 1.0: Real-time Communication Between Browsers</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<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
[[!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.</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>.</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>RTCIceTransports iceTransports = "all"</dt>
<dd>
<p>Indicates which candidates the ICE engine is allowed 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 establish a connection to a remote
peer unless it can be successfully authenticated with the
provided name.</p>
</dd>
</dl>
</section>
<section>
<h4>RTCIceServer Type</h4>
<dl class="idl" title="dictionary RTCIceServer">
<dt>(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>
</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":
"turn:turn.example.org", "username": "user", "credential":
"myPassword" } ]</code>
</p>
</section>
<section>
<h4>RTCIceTransports Enum</h4>
<dl class="idl" title="enum RTCIceTransports">
<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>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 RTCOfferOptions">
<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 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>
<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="enum RTCIdentityOption">
<dt>yes</dt>
<dd>An identity MUST be requested.</dd>
<dt>no</dt>
<dd>No identity is to be requested.</dd>
<dt>ifconfigured</dt>
<dd>The value "ifconfigured" means that an identity will be
requested if either the user has configured an identity in the
browser or if the <code>setIdentityProvider()</code> call has been
made in JavaScript. As this is the default value, an identity will
be requested if and only if the user has configured an IdP in some
way.</dd>
</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>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:</p>
<ol>
<li>
<p>Validate the <code>
<a>RTCConfiguration</a>
</code> argument by running the steps defined by the <a
href="#dom-peerconnection-updateice">updateIce()</a> method.</p>
</li>
<li>
<p>Let <var>connection</var> be a newly created <code>
<a>RTCPeerConnection</a>
</code> object.</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 and provide it the the <a
href="#ice-servers-list">ICE servers list</a>. 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>Initialize an internal variable to represent a queue of
<code>operations</code> with an empty set.</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> 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 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 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 <a
href="#dom-peerconnection-ice-connection-state"><code>RTCPeerConnection</code>
ice connection state</a> is changed to "completed"; otherwise
"failed".</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>
<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 ended.</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="interface RTCPeerConnection : EventTarget ">
<dt>Constructor (RTCConfiguration configuration)</dt>
<dd> See the <a href="#dom-peerconnection">RTCPeerConnection
constructor algorithm</a>. </dd>
<!--
<dt>void getCapabilities ( RTCSessionDescriptionCallback
successCallback )</dt>
<dd>
<p> The getCapabilities method generates a blob of SDP that
contains a RFC 3264 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 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 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>failureCallback</var>
with an <code>DOMError</code> object of type TBD as its
argument.</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)</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 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>failureCallback</var>
with an <code>DOMError</code> object of type TBD as its
argument.</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 rollback
to the old description if the remote side denied the change.</p>
<p class="issue">ISSUE: how to indicate to rollback?</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 <code>InvalidStateError</code> exception 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.
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>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>InvalidSessionDescriptionError</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>TODO ISSUE - 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>errorType</var> be
<code>IncompatibleSessionDescriptionError</code>. If
rollback was not possible, let <var>errorType</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>Invoke the <var>failureCallback</var> with an
<code>DOMError</code> object, whose <code>name</code>
attribute is <var>errorType</var>, as its argument.</p>
</li>
</ol>
</li>