webrtc.interfaces.rtc_peer_connection#
- class webrtc.interfaces.rtc_peer_connection.RTCPeerConnection(native_obj=None)#
Bases:
webrtc.base.WebRTCObjectThe RTCPeerConnection interface represents a WebRTC connection between the local computer and a remote peer. It provides methods to connect to a remote peer, maintain and monitor the connection, and close the connection once it’s no longer needed.
- addTrack(track: webrtc.MediaStreamTrack, stream: Optional[Union[webrtc.MediaStream, List[webrtc.MediaStream]]] = None) webrtc.RTCRtpSender#
Alias for
add_track
- addTransceiver(track_or_kind: Union[webrtc.MediaStreamTrack, webrtc.MediaType], init: Optional[webrtc.RtpTransceiverInit] = None) webrtc.RTCRtpTransceiver#
Alias for
add_transceiver
- add_track(track: webrtc.MediaStreamTrack, stream: Optional[Union[webrtc.MediaStream, List[webrtc.MediaStream]]] = None) webrtc.RTCRtpSender#
Adds a new
webrtc.MediaStreamTrackto the set of tracks which will be transmitted to the other peer.- Parameters
track (
webrtc.MediaStreamTrack) – Awebrtc.MediaStreamTrackobject representing the media track to add to the peer connection.stream (
webrtc.MediaStreamorlistofwebrtc.MediaStream, optional) – One or more localwebrtc.MediaStreamobjects to which the track should be added.
- Returns
The
webrtc.RTCRtpSenderobject which will be used to transmit the media data.- Return type
- add_transceiver(track_or_kind: Union[webrtc.MediaStreamTrack, webrtc.MediaType], init: Optional[webrtc.RtpTransceiverInit] = None) webrtc.RTCRtpTransceiver#
Creates a new
webrtc.RTCRtpTransceiverand adds it to the set of transceivers associated with the connection. Each transceiver represents a bidirectional stream, with both anwebrtc.RTCRtpSenderand anwebrtc.RTCRtpReceiverassociated with it.- Parameters
track_or_kind (
webrtc.MediaStreamTrack) – Awebrtc.MediaStreamTrackto associate with the transceiver, or a member ofwebrtc.MediaTypewhich is used as the kind of the receiver’s track, and by extension of thewebrtc.RTCRtpReceiveritself.init (
webrtc.RtpTransceiverInit, optional) – An object for specifying any options when creating the new transceiver.
- Returns
The
webrtc.RTCRtpSenderobject which will be used to transmit the media data.- Return type
- close()#
Closes the current peer connection.
- async createAnswer() webrtc.RTCSessionDescription#
Alias for
create_answer
- async createOffer() webrtc.RTCSessionDescription#
Alias for
create_offer
- async create_answer() webrtc.RTCSessionDescription#
Initiates the creation an SDP answer to an offer received from a remote peer during the offer/answer negotiation of a WebRTC connection. The answer contains information about any media already attached to the session, codecs and options supported by the machine, and any ICE candidates already gathered.
- async create_offer() webrtc.RTCSessionDescription#
Initiates the creation of an SDP offer for the purpose of starting a new WebRTC connection to a remote peer. The SDP offer includes information about any MediaStreamTrack objects already attached to the WebRTC session, codec, and options supported by the machine, as well as any candidates already gathered by the ICE agent, for the purpose of being sent over the signaling channel to a potential peer to request a connection or to update the configuration of an existing connection.
- getReceivers() List[webrtc.RTCRtpReceiver]#
Alias for
get_receivers
- getSenders() List[webrtc.RTCRtpSender]#
Alias for
get_senders
- getTransceivers() List[webrtc.RTCRtpTransceiver]#
Alias for
get_transceivers
- get_receivers() List[webrtc.RTCRtpReceiver]#
Returns an array of
webrtc.RTCRtpReceiverobjects, each of which represents one RTP receiver. Each RTP receiver manages the reception and decoding of data for awebrtc.MediaStreamTrackon anwebrtc.RTCPeerConnection.Note
The order of the returned
webrtc.RTCRtpReceiveris not defined by the specification, and may change from one call toget_receiversto the next.- Returns
- An array of
webrtc.RTCRtpReceiverobjects, one for each track on the connection. The array is empty if there are no RTP receivers on the connection.
- An array of
- Return type
listofwebrtc.RTCRtpReceiver
- get_senders() List[webrtc.RTCRtpSender]#
Returns an array of
webrtc.RTCRtpSenderobjects, each of which represents the RTP sender responsible for transmitting one track’s data. A sender object provides methods and properties for examining and controlling the encoding and transmission of the track’s data.Note
The order of the returned
webrtc.RTCRtpSendersis not defined by the specification, and may change from one call toget_sendersto the next.- Returns
An array of
webrtc.RTCRtpSenderobjects, one for each track on the connection. The array is empty if there are no RTP senders on the connection.- Return type
listofwebrtc.RTCRtpSender
- get_transceivers() List[webrtc.RTCRtpTransceiver]#
Returns a
listof thewebrtc.RTCRtpTransceiverobjects being used to send and receive data on the connection.- Returns
An array of the
webrtc.RTCRtpTransceiverobjects representing the transceivers handling sending and receiving all media on thewebrtc.RTCPeerConnection. The list is in the order in which the transceivers were added to the connection.- Return type
listofwebrtc.RTCRtpTransceiver
- removeTrack(sender: webrtc.RTCRtpSender) None#
Alias for
remove_track
- remove_track(sender: webrtc.RTCRtpSender) None#
Tells the local end of the connection to stop sending media from the specified track, without actually removing the corresponding
webrtc.RTCRtpSenderfrom the list of senders as reported byget_senders`. If the track is already stopped, or is not in the connection’s senders list, this method has no effect.
- restartIce() None#
Alias for
restart_ice
- restart_ice() None#
Allows to easily request that ICE candidate gathering be redone on both ends of the connection. This simplifies the process by allowing the same method to be used by either the caller or the receiver to trigger an ICE restart.
- property sctp: Optional[webrtc.RTCSctpTransport]#
An object describing the SCTP transport layer over which SCTP data is being sent and received. If SCTP hasn’t been negotiated, this value is
None- Type
webrtc.RTCSctpTransport, optional
- async setLocalDescription(sdp: webrtc.RTCSessionDescription)#
Alias for
set_local_description
- async setRemoteDescription(sdp: webrtc.RTCSessionDescription)#
Alias for
set_remote_description
- async set_local_description(sdp: webrtc.RTCSessionDescription)#
Changes the local description associated with the connection. This description specifies the properties of the local end of the connection, including the media format. It returns a
Coroutine. A result will be returned once the description has been changed, asynchronously.- Parameters
sdp (
webrtc.RTCSessionDescription) – Awebrtc.RTCSessionDescriptionobject that describes one end of a connection or potential connection.- Return type
None
- async set_remote_description(sdp: webrtc.RTCSessionDescription)#
Sets the specified session description as the remote peer’s current offer or answer. The description specifies the properties of the remote end of the connection, including the media format. It returns a
Coroutine. A result will be returned once the description has been changed, asynchronously.- Parameters
sdp (
webrtc.RTCSessionDescription) – Awebrtc.RTCSessionDescriptionobject that describes one end of a connection or potential connection.- Return type
None