# RTCPeerConnection

The connection between the local peer and a remote one.

### *class* webrtc.interfaces.rtc_peer_connection.RTCPeerConnection(configuration=None)

A connection to a remote peer, which negotiates and carries media tracks and data channels.

The application exchanges descriptions ([`create_offer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_offer), [`create_answer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_answer)) and ICE candidates
with the remote peer over its own signaling channel. Operations that change the negotiation run one after
another, in the order they’re called. See [MDN: RTCPeerConnection](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection).

* **Events:**
  * **negotiationneeded** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – Negotiation (an offer/answer exchange) is needed.
  * **icecandidate** ([`webrtc.RTCPeerConnectionIceEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceEvent)) – A local ICE candidate was gathered and should be
    sent to the remote peer. Its `candidate` is [`None`](https://docs.python.org/3/builtins/constants.html#None) once gathering is complete.
  * **icecandidateerror** ([`webrtc.RTCPeerConnectionIceErrorEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceErrorEvent)) – A STUN or TURN server failed.
  * **signalingstatechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`signaling_state`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.signaling_state) changed.
  * **iceconnectionstatechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`ice_connection_state`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.ice_connection_state) changed.
  * **icegatheringstatechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`ice_gathering_state`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.ice_gathering_state) changed.
  * **connectionstatechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`connection_state`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.connection_state) changed.
  * **track** ([`webrtc.RTCTrackEvent`](../models/events.md#webrtc.models.events.RTCTrackEvent)) – A remote track was negotiated.
  * **datachannel** ([`webrtc.RTCDataChannelEvent`](../models/events.md#webrtc.models.events.RTCDataChannelEvent)) – The remote peer created a data channel.

A connection with handlers or a pending operation stays alive until it or its event loop closes.

* **Parameters:**
  **configuration** ([`webrtc.RTCConfiguration`](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCConfiguration), optional) – The configuration of the connection.
  The defaults of [`webrtc.RTCConfiguration`](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCConfiguration) are used if it’s omitted.
* **Raises:**
  * [**webrtc.InvalidSyntaxError**](../exceptions.md#webrtc.exceptions.InvalidSyntaxError) – If an ICE server URL is invalid.
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If a TURN server has no credentials, or a certificate has expired.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If a member of the configuration is out of range.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If a member of the configuration has a wrong type, or a value its enum doesn’t have.

### Events

- `negotiationneeded`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `signalingstatechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `iceconnectionstatechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `icegatheringstatechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `connectionstatechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `icecandidate`: [`RTCPeerConnectionIceEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceEvent)
- `icecandidateerror`: [`RTCPeerConnectionIceErrorEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceErrorEvent)
- `track`: [`RTCTrackEvent`](../models/events.md#webrtc.models.events.RTCTrackEvent)
- `datachannel`: [`RTCDataChannelEvent`](../models/events.md#webrtc.models.events.RTCDataChannelEvent)

Handlers are registered with [`on()`](../events.md#webrtc.utils.events.UniformEventTarget.on).

#### *async* create_offer(options=None)

Creates an offer that starts a negotiation or renegotiates one.

The offer describes the transceivers and data channels of the connection, with the codecs it supports and
the ICE candidates gathered so far. It isn’t applied until it’s passed to [`set_local_description()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.set_local_description).
See [MDN: RTCPeerConnection/createOffer](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer).

* **Parameters:**
  **options** ([`webrtc.RTCOfferOptions`](../models/rtc_offer_answer_options.md#webrtc.models.rtc_offer_answer_options.RTCOfferOptions), optional) – How to create the offer.
* **Returns:**
  [`webrtc.RTCSessionDescriptionInit`](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit) – The offer, to set with [`set_local_description()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.set_local_description).
* **Raises:**
  [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the signaling state isn’t `stable` or `have-local-offer`,
      or the connection is closed.
* **Return type:**
  [*RTCSessionDescriptionInit*](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit)

#### *async* create_answer(options=None)

Creates an answer to the offer set as the remote description.

It isn’t applied until it’s passed to [`set_local_description()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.set_local_description).
See [MDN: RTCPeerConnection/createAnswer](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createAnswer).

* **Parameters:**
  **options** ([`webrtc.RTCAnswerOptions`](../models/rtc_offer_answer_options.md#webrtc.models.rtc_offer_answer_options.RTCAnswerOptions), optional) – How to create the answer.
* **Returns:**
  [`webrtc.RTCSessionDescriptionInit`](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit) – The answer, to set with [`set_local_description()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.set_local_description).
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the options aren’t an [`webrtc.RTCAnswerOptions`](../models/rtc_offer_answer_options.md#webrtc.models.rtc_offer_answer_options.RTCAnswerOptions).
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed or has no remote offer.
* **Return type:**
  [*RTCSessionDescriptionInit*](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit)

#### *async* set_local_description(description=None)

Applies a local session description, which starts ICE gathering.

See [MDN: RTCPeerConnection/setLocalDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setLocalDescription).

* **Parameters:**
  **description** ([`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional) – The description, as returned by
  [`create_offer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_offer) or [`create_answer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_answer), or a `rollback` one. An
  [`webrtc.RTCSessionDescriptionInit`](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit) or [`webrtc.RTCLocalSessionDescriptionInit`](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCLocalSessionDescriptionInit) is accepted
  too, with its SDP modified if needed. Without it, or without a type and an SDP, the
  offer or the answer the signaling state calls for is created and set.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the type doesn’t match the signaling state, or the connection is closed.
  * [**webrtc.InvalidModificationError**](../exceptions.md#webrtc.exceptions.InvalidModificationError) – If the SDP changes the fingerprint [`create_offer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_offer) or
        [`create_answer()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.create_answer) made.
  * [**webrtc.RTCError**](../exceptions.md#webrtc.exceptions.RTCError) – If the SDP can’t be parsed (`sdp_syntax_error`).
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the description has an SDP but no type, or is neither of the accepted types.

#### *async* set_remote_description(description)

Applies an offer, an answer or a rollback received from the remote peer.

An offer set while there’s a local offer rolls the local one back first. Remote tracks the description
adds are announced with `track` events. See [MDN: RTCPeerConnection/setRemoteDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription).

* **Parameters:**
  **description** ([`webrtc.RTCSessionDescriptionInit`](../models/rtc_session_description_init.md#webrtc.models.rtc_session_description_init.RTCSessionDescriptionInit)) – The description received from the remote peer,
  like one from `webrtc.RTCSessionDescriptionInit.from_json()`. An
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) is accepted too.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the type doesn’t match the signaling state, or the connection is closed.
  * [**webrtc.RTCError**](../exceptions.md#webrtc.exceptions.RTCError) – If the SDP can’t be parsed (`sdp_syntax_error`).
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If the description can’t be applied.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the description is neither of the accepted types.

#### add_track(track, \*streams)

Starts sending a track to the remote peer, from the next negotiation.

If there’s an unused transceiver of the same kind, it’s reused. Otherwise a new one is added.
See [MDN: RTCPeerConnection/addTrack](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack).

* **Parameters:**
  * **track** ([`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack)) – The track to send.
  * **\*streams** ([`webrtc.MediaStream`](media_stream.md#webrtc.interfaces.media_stream.MediaStream)) – The local streams the remote peer receives the track in.
* **Returns:**
  [`webrtc.RTCRtpSender`](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender) – The sender of the track.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If a sender of the connection already has the track.
* **Return type:**
  [*RTCRtpSender*](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender)

#### add_transceiver(track_or_kind, init=None)

Adds a new transceiver, negotiated with the next offer.

See [MDN: RTCPeerConnection/addTransceiver](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTransceiver).

* **Parameters:**
  * **track_or_kind** ([`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack) or [`webrtc.MediaType`](../enums.md#webrtc.enums.MediaType)) – The track the sender of the
    transceiver sends, or the kind of media (`'audio'` or `'video'`) for a transceiver without one.
  * **init** ([`webrtc.RTCRtpTransceiverInit`](../models/rtc_rtp_transceiver_init.md#webrtc.models.rtc_rtp_transceiver_init.RTCRtpTransceiverInit), optional) – The options of the new transceiver.
* **Returns:**
  [`webrtc.RTCRtpTransceiver`](rtc_rtp_transceiver.md#webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver) – The new transceiver.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the kind is neither audio nor video, or a `rid` of the send encodings is invalid, or
        missing or repeated with several encodings.
  * [**webrtc.OperationError**](../exceptions.md#webrtc.exceptions.OperationError) – If the codec of a send encoding can’t be sent.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
* **Return type:**
  [*RTCRtpTransceiver*](rtc_rtp_transceiver.md#webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver)

#### get_transceivers()

Returns the transceivers of the connection, in the order they were added.

See [MDN: RTCPeerConnection/getTransceivers](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getTransceivers).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.RTCRtpTransceiver`](rtc_rtp_transceiver.md#webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver) – The transceivers.
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[*RTCRtpTransceiver*](rtc_rtp_transceiver.md#webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver)]

#### get_senders()

Returns the senders of the transceivers of the connection, one per transceiver.

See [MDN: RTCPeerConnection/getSenders](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getSenders).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.RTCRtpSender`](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender) – The senders, including the ones without a track.
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[*RTCRtpSender*](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender)]

#### get_receivers()

Returns the receivers of the transceivers of the connection, one per transceiver.

See [MDN: RTCPeerConnection/getReceivers](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getReceivers).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.RTCRtpReceiver`](rtc_rtp_receiver.md#webrtc.interfaces.rtc_rtp_receiver.RTCRtpReceiver) – The receivers.
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[*RTCRtpReceiver*](rtc_rtp_receiver.md#webrtc.interfaces.rtc_rtp_receiver.RTCRtpReceiver)]

#### remove_track(sender)

Stops sending the track of a sender, from the next negotiation. The sender stays in [`get_senders()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.get_senders).

Does nothing if the sender has no track, or is stopped or rolled back. See [MDN: RTCPeerConnection/removeTrack](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/removeTrack).

* **Parameters:**
  **sender** ([`webrtc.RTCRtpSender`](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender)) – A sender of this connection.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If the sender wasn’t created by this connection.

#### *async* add_ice_candidate(candidate=None)

Adds a candidate received from the remote peer to the remote description.

See [MDN: RTCPeerConnection/addIceCandidate](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addIceCandidate).

* **Parameters:**
  **candidate** ([`webrtc.RTCIceCandidateInit`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidateInit) or [`webrtc.RTCIceCandidate`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate), optional) – The
  candidate, like one from `webrtc.RTCIceCandidateInit.from_json()`. An empty `candidate`,
  or [`None`](https://docs.python.org/3/builtins/constants.html#None), means the end of candidates.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If a non-empty candidate has neither `sdp_mid` nor `sdp_m_line_index`.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If there’s no remote description, or the connection is closed.
  * [**webrtc.OperationError**](../exceptions.md#webrtc.exceptions.OperationError) – If the candidate can’t be parsed or doesn’t match a media section.

#### create_data_channel(label, data_channel_dict=None)

Creates a channel to exchange messages with the remote peer.

The first channel needs a negotiation, which adds the SCTP transport. A `negotiated` channel isn’t
announced to the remote peer, so both peers create it with the same `id`.
See [MDN: RTCPeerConnection/createDataChannel](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel).

* **Parameters:**
  * **label** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The name of the channel, up to 65535 bytes in UTF-8.
  * **data_channel_dict** ([`webrtc.RTCDataChannelInit`](rtc_data_channel.md#webrtc.interfaces.rtc_data_channel.RTCDataChannelInit), optional) – How to create the channel.
* **Returns:**
  [`webrtc.RTCDataChannel`](rtc_data_channel.md#webrtc.interfaces.rtc_data_channel.RTCDataChannel) – The channel.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the label or an option is out of range, or both `max_packet_life_time` and
        `max_retransmits` are set, or `negotiated` is set without `id`.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
  * [**webrtc.OperationError**](../exceptions.md#webrtc.exceptions.OperationError) – If the `id` is in use, or no id is left.
* **Return type:**
  [*RTCDataChannel*](rtc_data_channel.md#webrtc.interfaces.rtc_data_channel.RTCDataChannel)

#### *async* get_stats(selector=None)

Collects the stats of the connection, or of the sender or the receiver of a track.

Calls in the same loop iteration, like those one [`asyncio.gather()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather) starts, share one collection.

See [MDN: RTCPeerConnection/getStats](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats).

* **Parameters:**
  **selector** ([`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack), optional) – A track of exactly one sender or receiver
  of the connection. Only the stats of that sender or receiver are collected.
* **Returns:**
  [`webrtc.RTCStatsReport`](../models/rtc_stats.md#webrtc.models.rtc_stats.RTCStatsReport) – The stats.
* **Raises:**
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If no sender or receiver, or more than one, has the track.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
* **Return type:**
  [*RTCStatsReport*](../models/rtc_stats.md#webrtc.models.rtc_stats.RTCStatsReport)

#### *async static* generate_certificate(keygen_algorithm)

Generates a key and a self-signed certificate on a worker thread, for `RTCConfiguration.certificates`.

See [MDN: RTCPeerConnection/generateCertificate_static](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/generateCertificate_static).

* **Parameters:**
  **keygen_algorithm** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`webrtc.Algorithm`](../models/rtc_certificate.md#webrtc.models.rtc_certificate.Algorithm)) – A WebCrypto algorithm: `'ECDSA'`
  (with the P-256 curve), an [`webrtc.EcKeyGenParams`](../models/rtc_certificate.md#webrtc.models.rtc_certificate.EcKeyGenParams), or an [`webrtc.RsaHashedKeyGenParams`](../models/rtc_certificate.md#webrtc.models.rtc_certificate.RsaHashedKeyGenParams)
  like `RsaHashedKeyGenParams('RSASSA-PKCS1-v1_5', modulus_length=2048,
  public_exponent=bytes([1, 0, 1]), hash='SHA-256')`. Its `expires` sets for how many milliseconds
  the certificate is valid, up to a year (30 days by default).
* **Returns:**
  [`webrtc.RTCCertificate`](../models/rtc_certificate.md#webrtc.models.rtc_certificate.RTCCertificate) – The certificate.
* **Raises:**
  * [**webrtc.NotSupportedError**](../exceptions.md#webrtc.exceptions.NotSupportedError) – If the algorithm isn’t supported.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `expires` isn’t an unsigned 64-bit integer.
* **Return type:**
  [webrtc.RTCCertificate](../models/rtc_certificate.md#webrtc.models.rtc_certificate.RTCCertificate)

#### get_configuration()

Returns the configuration of the connection, as it was last set.

The certificates are the ones in use, generated or given. See [MDN: RTCPeerConnection/getConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getConfiguration).

* **Returns:**
  [`webrtc.RTCConfiguration`](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCConfiguration) – A copy of the configuration. Changing it doesn’t affect the
  connection.
* **Return type:**
  [*RTCConfiguration*](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCConfiguration)

#### set_configuration(configuration=None)

Replaces the configuration of the connection. Members that aren’t set get their default values.

Changed ICE servers or ICE transport policy apply to the candidates gathered next, like after
[`restart_ice()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.restart_ice). See [MDN: RTCPeerConnection/setConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setConfiguration).

* **Parameters:**
  **configuration** ([`webrtc.RTCConfiguration`](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCConfiguration), optional) – The new configuration.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
  * [**webrtc.InvalidModificationError**](../exceptions.md#webrtc.exceptions.InvalidModificationError) – If a member that can’t be changed differs, like
        `webrtc.RTCConfiguration.bundle_policy` or
        `webrtc.RTCConfiguration.always_negotiate_data_channels`.
  * [**webrtc.InvalidSyntaxError**](../exceptions.md#webrtc.exceptions.InvalidSyntaxError) – If an ICE server URL is invalid.
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If a TURN server has no credentials, or a certificate has expired.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If a member of the configuration is out of range.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If a member of the configuration has a wrong type, or a value its enum doesn’t have.

#### restart_ice()

Requests an ICE restart, with new credentials and candidates, from the next negotiation on either side.

It leads to a `negotiationneeded` event. It does nothing before the first local description, since that one
already has new credentials, or once the connection is closed. See [MDN: RTCPeerConnection/restartIce](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/restartIce).

#### close()

Closes the connection for good, stopping its transceivers and data channels.

No events follow except remote tracks’ `ended`. See [MDN: RTCPeerConnection/close](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/close).

#### *property* sctp *: [RTCSctpTransport](rtc_sctp_transport.md#webrtc.interfaces.rtc_sctp_transport.RTCSctpTransport) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The transport of the data channels.

It’s [`None`](https://docs.python.org/3/builtins/constants.html#None) until the data channels are negotiated.
See [MDN: RTCPeerConnection/sctp](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/sctp).

* **Type:**
  [`webrtc.RTCSctpTransport`](rtc_sctp_transport.md#webrtc.interfaces.rtc_sctp_transport.RTCSctpTransport), optional

#### *property* local_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The pending local description, or else the current one.

[`None`](https://docs.python.org/3/builtins/constants.html#None) until one is set. It includes the ICE candidates gathered so far.
See [MDN: RTCPeerConnection/localDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/localDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* remote_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The pending remote description, or else the current one.

[`None`](https://docs.python.org/3/builtins/constants.html#None) until one is set. It includes the candidates added with [`add_ice_candidate()`](#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.add_ice_candidate).
See [MDN: RTCPeerConnection/remoteDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/remoteDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* current_local_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The local description of the last completed negotiation.

See [MDN: RTCPeerConnection/currentLocalDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/currentLocalDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* current_remote_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The remote description of the last completed negotiation.

See [MDN: RTCPeerConnection/currentRemoteDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/currentRemoteDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* pending_local_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The local description of a negotiation in progress.

See [MDN: RTCPeerConnection/pendingLocalDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/pendingLocalDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* pending_remote_description *: [RTCSessionDescription](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The remote description of a negotiation in progress.

See [MDN: RTCPeerConnection/pendingRemoteDescription](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/pendingRemoteDescription).

* **Type:**
  [`webrtc.RTCSessionDescription`](../models/rtc_session_description.md#webrtc.models.rtc_session_description.RTCSessionDescription), optional

#### *property* can_trickle_ice_candidates *: [bool](https://docs.python.org/3/builtins/functions.html#bool) | [None](https://docs.python.org/3/builtins/constants.html#None)*

Whether the remote peer takes candidates one by one (trickle ICE).

[`None`](https://docs.python.org/3/builtins/constants.html#None) until there’s a remote description. See [MDN: RTCPeerConnection/canTrickleIceCandidates](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/canTrickleIceCandidates).

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool), optional

#### *property* connection_state *: [RTCPeerConnectionState](../enums.md#webrtc.enums.RTCPeerConnectionState)*

The overall state of the ICE and DTLS transports of the connection.

See [MDN: RTCPeerConnection/connectionState](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState).

* **Type:**
  [`webrtc.RTCPeerConnectionState`](../enums.md#webrtc.enums.RTCPeerConnectionState)

#### *property* signaling_state *: [RTCSignalingState](../enums.md#webrtc.enums.RTCSignalingState)*

Where the connection is in the offer/answer exchange.

See [MDN: RTCPeerConnection/signalingState](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/signalingState).

* **Type:**
  [`webrtc.RTCSignalingState`](../enums.md#webrtc.enums.RTCSignalingState)

#### *property* ice_connection_state *: [RTCIceConnectionState](../enums.md#webrtc.enums.RTCIceConnectionState)*

The overall state of the ICE transports of the connection.

See [MDN: RTCPeerConnection/iceConnectionState](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState).

* **Type:**
  [`webrtc.RTCIceConnectionState`](../enums.md#webrtc.enums.RTCIceConnectionState)

#### *property* ice_gathering_state *: [RTCIceGatheringState](../enums.md#webrtc.enums.RTCIceGatheringState)*

The overall candidate gathering state of the ICE transports.

See [MDN: RTCPeerConnection/iceGatheringState](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceGatheringState).

* **Type:**
  [`webrtc.RTCIceGatheringState`](../enums.md#webrtc.enums.RTCIceGatheringState)
