Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RTCPeerConnection

BaselineWidely available *

TheRTCPeerConnection 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.

EventTarget RTCPeerConnection

Constructor

RTCPeerConnection()

Returns a newRTCPeerConnection, representing a connection between the local device and a remote peer.

Instance properties

Also inherits properties fromEventTarget.

canTrickleIceCandidatesRead only

Returns a boolean value which indicates whether or not the remote peer can accepttrickled ICE candidates.

connectionStateRead only

Indicates the current state of the peer connection by returning one of the strings:new,connecting,connected,disconnected,failed, orclosed.

currentLocalDescriptionRead only

Returns anRTCSessionDescription object describing the local end of the connection as it was most recently successfully negotiated since the last time thisRTCPeerConnection finished negotiating and connecting to a remote peer.Also included is a list of any ICE candidates that may already have been generated by the ICE agent since the offer or answer represented by the description was first instantiated.

currentRemoteDescriptionRead only

Returns anRTCSessionDescription object describing the remote end of the connection as it was most recently successfully negotiated since the last time thisRTCPeerConnection finished negotiating and connecting to a remote peer.Also included is a list of any ICE candidates that may already have been generated by the ICE agent since the offer or answer represented by the description was first instantiated.

iceConnectionStateRead only

Returns a string which state of the ICE agent associated with this RTCPeerConnection.It can be one of the following values:new,checking,connected,completed,failed,disconnected, orclosed.

iceGatheringStateRead only

Returns a string that describes connection's ICE gathering state.This lets you detect, for example, when collection of ICE candidates has finished.Possible values are:new,gathering, orcomplete.

localDescriptionRead only

Returns anRTCSessionDescriptiondescribing the session for the local end of the connection.If it has not yet been set, returnsnull.

peerIdentityRead only

Returns aPromise that resolves to anRTCIdentityAssertion which contains a string identifying the remote peer.Once this promise resolves successfully, the resulting identity is the target peer identity and will not change for the duration of the connection.

pendingLocalDescriptionRead only

Returns anRTCSessionDescription object describing a pending configuration change for the local end of the connection.This does not describe the connection as it currently stands, but as it may exist in the near future.

pendingRemoteDescriptionRead only

Returns anRTCSessionDescription objectdescribing a pending configuration change for the remote end of the connection.This does not describe the connection as it currently stands, but as it may exist in the near future.

remoteDescriptionRead only

Returns anRTCSessionDescription object describing the session, including configuration and media information, for the remote end of the connection.If this hasn't been set yet, this returnsnull.

sctpRead only

Returns anRTCSctpTransport object describing theSCTP transport layer over which SCTP data is being sent and received.If SCTP hasn't been negotiated, this value isnull.

signalingStateRead only

Returns a string describing the state of the signaling process on the local end of the connection while connecting or reconnecting to another peer.It is one of the following values:stable,have-local-offer,have-remote-offer,have-local-pranswer,have-remote-pranswer, orclosed.

Static methods

RTCPeerConnection.generateCertificate()

Creates an X.509 certificate and its corresponding private key, returning aPromise that resolves with the newRTCCertificate once it is generated.

Instance methods

Also inherits methods fromEventTarget.

addIceCandidate()

Adds a new remote candidate to theRTCPeerConnection's remote description, which describes the state of the remote end of the connection.

addTrack()

Adds a newMediaStreamTrack to the set of tracks which will be transmitted to the other peer.

addTransceiver()

Creates a newRTCRtpTransceiver and adds it to the set of transceivers associated with the connection.Each transceiver represents a bidirectional stream, with both anRTCRtpSender and anRTCRtpReceiver associated with it.

close()

Closes the current peer connection.

createAnswer()

Initiates the creation of anSDP 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 browser, and anyICE candidates already gathered.

createDataChannel()

Initiates the creation a new channel linked with the remote peer, over which any kind of data may be transmitted.This can be useful for back-channel content, such as images, file transfer, text chat, game update packets, and so forth.

createOffer()

Initiates the creation of anSDP offer for the purpose of starting a new WebRTC connection to a remote peer.The SDP offer includes information about anyMediaStreamTrack objects already attached to the WebRTC session, codec, and options supported by the browser, as well as any candidates already gathered by theICE 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.

getConfiguration()

Returns an object which indicates the current configuration of the connection.

getIdentityAssertion()

Initiates the gathering of an identity assertion and returns aPromise which resolves to an identity assertion encoded as a string.This has an effect only ifsignalingState is notclosed.

getReceivers()

Returns an array ofRTCRtpReceiver objects, each of which represents oneRTP receiver.

getSenders()

Returns an array ofRTCRtpSender objects, each of which represents theRTP sender responsible for transmitting one track's data.

getStats()

Returns aPromise which resolves with data providing statistics about either the overall connection or about the specifiedMediaStreamTrack.

getTransceivers()

Returns a list of all theRTCRtpTransceiver objects being used to send and receive data on the connection.

removeTrack()

Tells the local end of the connection to stop sending media from the specified track, without actually removing the correspondingRTCRtpSender from the list of sendersas reported bygetSenders().If the track is already stopped, or is not in the connection's senders list, this method has no effect.

restartIce()

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 anICE restart.

setConfiguration()

Sets the current configuration of the connection based on the values included in the specified object.This lets you change theICE servers used by the connection and which transport policies to use.

setIdentityProvider()

Sets the Identity Provider (IdP) to the triplet given in parameter: its name, the protocol used to communicate with it and an username.The protocol and the username are optional.

setLocalDescription()

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 aPromise which is fulfilled once the description has been changed, asynchronously.

setRemoteDescription()

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 aPromise which is fulfilled once the description has been changed, asynchronously.

Obsolete methods

addStream()DeprecatedNon-standard

Adds aMediaStream as a local source of audio or video.Instead of using this obsolete method, you should instead useaddTrack() once for each track you wish to send to the remote peer.

createDTMFSender()DeprecatedNon-standard

Creates a newRTCDTMFSender, associated to a specificMediaStreamTrack, that will be able to sendDTMF phone signaling over the connection.

removeStream()DeprecatedNon-standard

Removes aMediaStream as a local source of audio or video.Because this method is obsolete, you should instead useremoveTrack().

Events

Listen to these events usingaddEventListener() or by assigning an event listener to theoneventname property of this interface.

connectionstatechange

Sent when the overall connectivity status of theRTCPeerConnection changes.

datachannel

Sent when the remote peer adds anRTCDataChannel to the connection.

icecandidate

Sent to request that the specified candidate be transmitted to the remote peer.

icecandidateerror

Sent to the connection if an error occurred duringICE candidate gathering. The event describes the error.

iceconnectionstatechange

Sent when the state of theICE connection changes, such as when it disconnects.

icegatheringstatechange

Sent when theICE layer's gathering state, reflected byiceGatheringState, changes.This indicates whether ICE negotiation has not yet begun (new), has begun gathering candidates (gathering), or has completed (complete).

negotiationneeded

Sent when negotiation or renegotiation of theICE connection needs to be performed;this can happen both when first opening a connection as well as when it is necessary to adapt to changing network conditions.The receiver should respond by creating an offer and sending it to the other peer.

signalingstatechange

Sent when the connection'sICE signaling state changes.

track

Sent after a new track has been added to one of theRTCRtpReceiver instances which comprise the connection.

Obsolete events

addstreamDeprecatedNon-standard

Sent when a newMediaStream has been added to the connection.Instead of listening for this obsolete event, you should listen fortrack events;one is sent for eachMediaStreamTrack added to the connection.

removestreamDeprecatedNon-standard

Sent when aMediaStream is removed from the connection.Instead of listening for this obsolete event, you should listen forremovetrack events on each stream.

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# interface-definition

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp