この翻訳は不完全です。英語から この記事を翻訳 してください。


RTCPeerConnection インタフェースはローカルコンピュータとリモートピア間のWebRTC コネクションを表現します。このインタフェースはリモートピアへ接続や、その接続の保守や監視するメソッド、さらに、不要になった接続を閉じるメソッドを提供します。

注釈: RTCPeerConnection と RTCSessionDescription は多くのブラウザでプレフィックスが付いています。あなたのサイトやWebアプリの幅広く可能な限りの互換性を確かにするためには、優秀で広く支持されている Adapter.js のような変換ライブラリの使用を強く勧めます。 Adapter.js がプリフィックスの扱いを超えて、ブラウザ間のWebRTCの実装において、その互換性のギャップを埋めているということは注目に値します。

コンストラクター

RTCPeerConnection()
RTCPeerConnection() コンストラクターはRTCPeerConnectionを新たに作成し、返します。これは、ローカルデバイスとリモートピアの間の接続を表現します。

プロパティ

Also inherits プロパティ from: EventTarget

canTrickleIceCandidates [翻訳する]
The read-only RTCPeerConnection property canTrickleIceCandidates returns a Boolean which indicates whether or not the remote peer can accept trickled ICE candidates.
connectionState [翻訳する]
The read-only connectionState property of the RTCPeerConnection interface indicates the current state of the peer connection by returning one of the string values specified by the enum RTCPeerConnectionState.
currentLocalDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.currentLocalDescription returns an RTCSessionDescription object describing the local end of the connection as it was most recently successfully negotiated since the last time the  RTCPeerConnection 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.
currentRemoteDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.currentRemoteDescription returns an RTCSessionDescription object describing the remote end of the connection as it was most recently successfully negotiated since the last time the RTCPeerConnection 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.
defaultIceServers [翻訳する]
The read-only property RTCPeerConnection.defaultIceServers returns an array of objects based on the RTCIceServer dictionary, which indicates what, if any, ICE servers the browser will use by default if none are provided to the RTCPeerConnection in its RTCConfiguration. However, browsers are not required to provide any default ICE servers at all.
iceConnectionState 読取専用 [翻訳する]
The read-only property RTCPeerConnection.iceConnectionState returns an enum of type RTCIceConnectionState which state of the ICE agent associated with the RTCPeerConnection.
iceGatheringState 読取専用 [翻訳する]
The read-only property RTCPeerConnection.iceGatheringState returns an enum of type RTCIceGatheringState that describes connection's ICE gathering state. This lets you detect, for example, when collection of ICE candidates has finished.
localDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.localDescription returns an RTCSessionDescription describing the session for the local end of the connection. If it has not yet been set, this is null.
peerIdentity 読取専用 [翻訳する]
The read-only property RTCPeerConnection.peerIdentity returns an RTCIdentityAssertion, containing a DOMString once set and verified. If no peer has yet been set and verified, this property will return null. Once set, via the appropriate method, it can't be changed.
pendingLocalDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.pendingLocalDescription returns an RTCSessionDescription 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. Use RTCPeerConnection.currentLocalDescription or RTCPeerConnection.localDescription to get the current state of the endpoint. For details on the difference, see Pending and current descriptions in WebRTC connectivity.
pendingRemoteDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.pendingRemoteDescription returns an RTCSessionDescription object describing 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. Use RTCPeerConnection.currentRemoteDescription or RTCPeerConnection.remoteDescription to get the current session description for the remote endpoint. For details on the difference, see Pending and current descriptions in WebRTC connectivity.
remoteDescription 読取専用 [翻訳する]
The read-only property RTCPeerConnection.remoteDescription returns a RTCSessionDescription describing the session (which includes configuration and media information) for the remote end of the connection. If this hasn't been set yet, this is null.
sctp [翻訳する]
The read-only sctp property on the RTCPeerConnection interface returns an RTCSctpTransport describing the SCTP transport over which SCTP data is being sent and received. If SCTP hasn't been negotiated, this value is null.
signalingState 読取専用 [翻訳する]
The read-only signalingState property on the RTCPeerConnection interface returns one of the string values specified by the RTCSignalingState enum; these values describe the state of the signaling process on the local end of the connection while connecting or reconnecting to another peer. See Signaling in Lifetime of a WebRTC session for more details about the signaling process.

イベントハンドラー

Also inherits イベントハンドラー from: EventTarget

onaddstream [翻訳する]
The RTCPeerConnection.onaddstream event handler is a property containing the code to execute when the addstream event, of type MediaStreamEvent, is received by this RTCPeerConnection. Such an event is sent when a MediaStream is added to this connection by the remote peer. The event is sent immediately after the call setRemoteDescription() and doesn't wait for the result of the SDP negotiation.
onconnectionstatechange [翻訳する]
The RTCPeerConnection.onconnectionstatechange property specifies an EventHandler which is called to handle the connectionstatechange event when it occurs on an instance of RTCPeerConnection. This happens whenever the aggregate state of the connection changes.
ondatachannel [翻訳する]
The RTCPeerConnection.ondatachannel property is an EventHandler which specifies a function which is called when the datachannel event occurs on an RTCPeerConnection. This event, of type RTCDataChannelEvent, is sent when an RTCDataChannel is added to the connection by the remote peer calling createDataChannel().
onicecandidate [翻訳する]
The RTCPeerConnection.onicecandidate property is an EventHandler which specifies a function to be called when the icecandidate event occurs on an RTCPeerConnection instance. This happens whenever the local ICE agent needs to deliver a message to the other peer through the signaling server.
oniceconnectionstatechange [翻訳する]
The RTCPeerConnection.oniceconnectionstatechange property is an event handler which specifies a function to be called when the iceconnectionstatechange event is fired on an RTCPeerConnection instance. This happens when the state of the connection's ICE agent, as represented by the iceConnectionState property, changes.
onicegatheringstatechange [翻訳する]
The RTCPeerConnection.onicegatheringstatechange property is an EventHandler which specifies a function to be called when the icegatheringstatechange event is sent to an RTCPeerConnection instance. This happens when the ICE gathering state—that is, whether or not the ICE agent is actively gathering candidates—changes.
onidentityresult [翻訳する]
The RTCPeerConnection.onidentityresult event handler is a property containing the code to execute when the identityresult event, of type RTCIdentityEvent, is received by this RTCPeerConnection. Such an event is sent when an identity assertion is generated, via getIdentityAssertion() or during the creation of an offer or an answer.
onidpassertionerror [翻訳する]
The RTCPeerConnection.onidpassertionerror event handler is a property containing the code to execute whent the idpassertionerror event, of type RTCIdentityErrorEvent, is received by this RTCPeerConnection. Such an event is sent when the associated identity provider (IdP) encounters an error while generating an identity assertion.
onidpvalidationerror [翻訳する]
The RTCPeerConnection.onidpvalidationerror event handler is a property containing the code to execute whent the idpvalidationerror event, of type RTCIdentityErrorEvent, is received by this RTCPeerConnection. Such an event is sent when the associated identity provider (IdP) encounters an error while validating an identity assertion.
onnegotiationneeded [翻訳する]
The RTCPeerConnection.onnegotiationneeded property is an EventHandler which specifies a function which is called to handle the negotiationneeded event when it occurs on an RTCPeerConnection instance. This event is fired when a change has occurred which requires session negotiation. This negotiation should be carried out as the offerer, because some session changes cannot be negotiated as the answerer.
onpeeridentity [翻訳する]
The RTCPeerConnection.onpeeridentity event handler is a property containing the code to execute whent the peeridentity event, of type Event, is received by this RTCPeerConnection. Such an event is sent when an identity assertion, received from a peer, has been successfully validated.
onremovestream [翻訳する]
The RTCPeerConnection.onremovestream event handler is a property containing the code to execute when the removestream event, of type MediaStreamEvent, is received by this RTCPeerConnection. Such an event is sent when a MediaStream is removed from this connection.
onsignalingstatechange [翻訳する]
The onsignalingstatechange property of the RTCPeerConnection interface is an EventHandler which specifies a function to be called when the signalingstatechange event occurs on an RTCPeerConnection interface.
ontrack [翻訳する]
The RTCPeerConnection property ontrack is an EventHandler which specifies a function to be called when the track event occurs, indicating that a track has been added to the RTCPeerConnection.

メソッド

Also inherits メソッド from: EventTarget

addIceCandidate() [翻訳する]
When a web site or app using RTCPeerConnection receives a new ICE candidate from the remote peer over its signaling channel, it delivers the newly-received candidate to the browser's ICE agent by calling RTCPeerConnection.addIceCandidate().
addStream() [翻訳する]
The RTCPeerConnection.addStream() method adds a MediaStream as a local source of audio or video. If the negotiation already happened, a new one will be needed for the remote peer to be able to use it.
addTrack() [翻訳する]
The RTCPeerConnection method addTrack() adds a new media track to the set of tracks which will be transmitted to the other peer.
close() [翻訳する]
The RTCPeerConnection.close() method closes the current peer connection.
createAnswer() [翻訳する]
The createAnswer() method on the RTCPeerConnection interface creates 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 browser, and any ICE candidates already gathered. The answer is delivered to the returned Promise, and should then be sent to the source of the offer to continue the negotiation process.
createDataChannel() [翻訳する]
The createDataChannel() method on the RTCPeerConnection interface creates a new channel 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() [翻訳する]
The createOffer() method of the RTCPeerConnection interface initiates the creation of an SDP offer for the purpose of starting a new WebRTC connection to a remote peer.
generateCertificate() [翻訳する]
The generateCertificate() method of the RTCPeerConnection interface creates and stores an X.509 certificate and corresponding private key then returns an RTCCertificate, providing access to it.
getConfiguration() [翻訳する]
The RTCPeerConnection.getConfiguration() method returns an RTCConfiguration object which indicates the current configuration of the RTCPeerConnection on which the method is called.
getIdentityAssertion() [翻訳する]
The RTCPeerConnection.getIdentityAssertion() method initiates the gathering of an identity assertion. This has an effect only if the signalingState is not "closed".
getLocalStreams() [翻訳する]
The RTCPeerConnection.getLocalStreams() method returns an array of MediaStream associated with the local end of the connection. The array may be empty.
getReceivers() [翻訳する]
The RTCPeerConnection.getReceivers() method returns an array of RTCRtpReceiver objects, each of which represents one RTP receiver. Each RTP receiver manages the reception and decoding of data for a MediaStreamTrack on an RTCPeerConnection
getRemoteStreams() [翻訳する]
The RTCPeerConnection.getRemoteStreams() method returns an array of MediaStream associated with the remote end of the connection. The array may be empty.
getSenders() [翻訳する]
The RTCPeerConnection method getSenders() returns an array of RTCRtpSender objects, each of which represents the RTP sender responsible for transmitting one track's data.
getStats() [翻訳する]
The RTCPeerConnection method getStats() returns a promise which resolves with data providing statistics about either the overall connection or about the specified MediaStreamTrack.
getStreamById() [翻訳する]
The RTCPeerConnection.getStreamById() method returns the MediaStream with the given id that is associated with local or remote end of the connection. If no stream matches, it returns null.
removeStream() [翻訳する]
The RTCPeerConnection.removeStream() method removes a MediaStream as a local source of audio or video. If the negotiation already happened, a new one will be needed for the remote peer to be able to use it. Because this method has been deprecated, you should instead use removeTrack() if your target browser versions have implemented it.
removeTrack() [翻訳する]
The RTCPeerConnection.removeTrack() method tells the local end of the connection to stop sending media from the specified track, without actually removing the corresponding RTCRtpSender from the list of senders as reported by RTCPeerConnection.getSenders().
setConfiguration() [翻訳する]
The RTCPeerConnection.setConfiguration() method sets the current configuration of the RTCPeerConnection based on the values included in the specified RTCConfiguration object. This lets you change the ICE servers used by the connection and which transport policies to use.
setIdentityProvider() [翻訳する]
The RTCPeerConnection.setIdentityProvider() method sets the Identity Provider (IdP) to the triplet given in parameter: its name, the protocol used to communicate with it (optional) and an optional username. The IdP will be used only when an assertion is needed.
setLocalDescription() [翻訳する]
The RTCPeerConnection.setLocalDescription() method changes the local description associated with the connection. This description specifies the properties of the local end of the connection, including the media format.
setRemoteDescription() [翻訳する]
The RTCPeerConnection.setRemoteDescription() method changes the remote description associated with the connection. This description specifies the properties of the remote end of the connection, including the media format.

廃止メソッド

以下のメソッドは廃止されており、すべての主要なブラウザーで未実装です。

RTCPeerConnection.createDTMFSender()
特定の MediaStreamTrack と関連付けられた新たな RTCDTMFSender を生成します。これにより、その接続において DTMF 音(電話のトーン信号、プッシュ音)を送れるようになるでしょう。

定数

RTCBundlePolicy enum

この RTCBundlePolicy 列挙子は、リモートピアが、単一の転送リンクにおいて複数のメディアストリームをまとめるための SDP BUNDLE standard と互換していない場合に、ICEの候補を収集するために特定のポリシーを要求する時に使用される文字列定数を定義します。

注釈: In technical terms, a BUNDLE lets all media flow between two peers flow across a single 5-tuple; that is, from the same IP and port on one peer to the same IP and port on the other peer, using the same transport protocol.

Constant Description
"balanced" On BUNDLE-aware connections, the ICE agent should gather candidates for all of the media types in use (audio, video, and data). Otherwise, the ICE agent should only negotiate one audio and video track on separate transports.
"max-compat" The ICE agent should gather candidates for each track, using separate transports to negotiate all media tracks for connections which aren't BUNDLE-compatible.
"max-bundle"

The ICE agent should gather candidates for just one track. If the connection isn't BUNDLE-compatible, then the ICE agent should negotiate just one media track.

 

RTCIceConnectionState enum

The RTCIceConnectionState enum defines the string constants used to describe the current state of the ICE agent and its connection to the ICE server (that is, the STUN or TURN server).

Constant Description
"new" The ICE agent is gathering addresses or is waiting to be given remote candidates through calls to RTCPeerConnection.addIceCandidate() (or both).
"checking" The ICE agent has been given one or more remote candidates and is checking pairs of local and remote candidates against one another to try to find a compatible match, but has not yet found a pair which will allow the peer connection to be made. It's possible that gathering of candidates is also still underway.
"connected" A usable pairing of local and remote candidates has been found for all components of the connection, and the connection has been established. It's possible that gathering is still underway, and it's also possible that the ICE agent is still checking candidates against one another looking for a better connection to use.
"completed" The ICE agent has finished gathering candidates, has checked all pairs against one another, and has found a connection for all components.
"failed" The ICE candidate has checked all candidates pairs against one another and has failed to find compatible matches for all components of the connection. It is, however, possible that the ICE agent did find compatible connections for some components.
"disconnected" Checks to ensure that components are still connected failed for at least one component of the RTCPeerConnection. This is a less stringent test than "failed" and may trigger intermittently and resolve just as spontaneously on less reliable networks, or during temporary disconnections. When the problem resolves, the connection may return to the "connected" state.
"closed" The ICE agent for this RTCPeerConnection has shut down and is no longer handling requests.

RTCIceGatheringState enum

The RTCIceGatheringState enum defines string constants which reflect the current status of ICE gathering, as returned using the RTCPeerConnection.iceGatheringState property. You can detect when this value changes by watching for an event of type icegatheringstatechange.

Constant Description
"new" The peer connection was just created and hasn't done any networking yet.
"gathering" The ICE agent is in the process of gathering candidates for the connection.
"complete" The ICE agent has finished gathering candidates. If something happens that requires collecting new candidates, such as a new interface being added or the addition of a new ICE server, the state will revert to "gathering" to gather those candidates.

RTCIceTransportPolicy enum

The RTCIceTransportPolicy enum defines string constants which can be used to limit the transport policies of the ICE candidates to be considered during the connection process.

Constant Description
"all" All ICE candidates will be considered.
"public" Only ICE candidates with public IP addresses will be considered. Removed from the specification's May 13, 2016 working draft.
"relay" Only ICE candidates whose IP addresses are being relayed, such as those being passed through a TURN server, will be considered.

RTCPeerConnectionState enum

The RTCPeerConnectionState enum defines string constants which describe states in which the RTCPeerConnection may be. These values are returned by the connectionState property. This state essentially represents the aggregate state of all ICE transports (which are of type RTCIceTransport or RTCDtlsTransport) being used by the connection.

Constant Description
"new" At least one of the connection's ICE transports (RTCIceTransports or RTCDtlsTransports) are in the "new" state, and none of them are in one of the following states: "connecting""checking""failed", or "disconnected"or all of the connection's transports are in the "closed" state.
"connecting" One or more of the ICE transports are currently in the process of establishing a connection; that is, their RTCIceConnectionStateis either "checking" or "connected", and no transports are in the "failed" state. <<< Make this a link once I know where that will be documented
"connected" Every ICE transport used by the connection is either in use (state "connected" or "completed") or is closed (state "closed"); in addition, at least one transport is either "connected" or "completed".
"disconnected" At least one of the ICE transports for the connection is in the "disconnected" state and none of the other transports are in the state "failed""connecting", or "checking".
"failed" One or more of the ICE transports on the connection is in the "failed" state.
"closed"

The RTCPeerConnection is closed.

This value was in the RTCSignalingState enum (and therefore found by reading the value of the signalingState) property until the May 13, 2016 draft of the specification.

RTCRtcpMuxPolicy enum

The RTCRtcpMuxPolicy enum defines string constants which specify what ICE candidates are gathered to support non-multiplexed RTCP. <<<add a link to info about multiplexed RTCP.

Constant Description
"negotiate" Instructs the ICE agent to gather both RTP and RTCP candidates. If the remote peer can multiplex RTCP, then RTCP candidates are multiplexed atop the corresponding RTP candidates. Otherwise, both the RTP and RTCP candidates are returned, separately.
"require" Tells the ICE agent to gather ICE candidates for only RTP, and to multiplex RTCP atop them. If the remote peer doesn't support RTCP multiplexing, then session negotiation fails.

RTCSignalingState enum

The RTCSignalingState enum specifies the possible values of RTCPeerConnection.signalingState, which indicates where in the process of signaling the exchange of offer and answer the connection currently is.

Constant Description
"stable" There is no ongoing exchange of offer and answer underway. This may mean that the RTCPeerConnection object is new, in which case both the localDescription and remoteDescription are null; it may also mean that negotiation is complete and a connection has been established.
"have-local-offer" The local peer has called RTCPeerConnection.setLocalDescription(), passing in SDP representing an offer (usually created by calling RTCPeerConnection.createOffer()), and the offer has been applied successfully.
"have-remote-offer" The remote peer has created an offer and used the signaling server to deliver it to the local peer, which has set the offer as the remote description by calling RTCPeerConnection.setRemoteDescription().
"have-local-pranswer" The offer sent by the remote peer has been applied and an answer has been created (usually by calling RTCPeerConnection.createAnswer()) and applied by calling RTCPeerConnection.setLocalDescription(). This provisional answer describes the supported media formats and so forth, but may not have a complete set of ICE candidates included. Further candidates will be delivered separately later.
"have-remote-pranswer" A provisional answer has been received and successfully applied in response to an offer previously sent and established by calling setLocalDescription().
"closed"

The connection is closed.

Note: This value moved into the RTCPeerConnectionState enum in the May 13, 2016 draft of the specification, as it reflects the state of the RTCPeerConnection, not the signaling connection. You now detect a closed connection by checking for connectionState to be "closed" instead.

基本的な利用方法

基本的な RTCPeerConnection の使い方では、あなたのローカルマシンとリモートマシン間のコネクションのネゴシエーションするために、生成したSession Description Protocolを2点間で交換することです。呼び出し側は、リモートマシンにオファーを送信して処理を開始し、リモートマシンはその呼び出しを受理するか拒否します。

2つのパーティは(呼び出し側と被呼び出し側のパーティ) はそれぞれ自身の RTCPeerConnection インスタンスをセットアップして、ピア・ツー・ピア コネクションの末端を表現する必要があります。

var pc = new RTCPeerConnection();
pc.onaddstream = function(obj) {
  var vid = document.createElement("video");
  document.appendChild(vid);
  vid.srcObject = obj.stream;
}

// Helper functions
function endCall() {
  var videos = document.getElementsByTagName("video");
  for (var i = 0; i < videos.length; i++) {
    videos[i].pause();
  }

  pc.close();
}

function error(err) {
  endCall();
}

呼び出しの初期化

If you are the one initiating the call, you would use navigator.getUserMedia() to get a video stream, then add the stream to the RTCPeerConnection. Once that's been done, call RTCPeerConnection.createOffer() to create an offer, configure the offer, then send it to the server through which the connection is being mediated.

// Get a list of friends from a server
// User selects a friend to start a peer connection with
navigator.getUserMedia({video: true}, function(stream) {
  // Adding a local stream won't trigger the onaddstream callback,
  // so call it manually.
  pc.onaddstream({stream: stream});
  pc.addStream(stream);

  pc.createOffer(function(offer) {
    pc.setLocalDescription(new RTCSessionDescription(offer), function() {
      // send the offer to a server to be forwarded to the friend you're calling.
    }, error);
  }, error);
});

呼び出しの応答

On the opposite end, the friend will receive the offer from the server using whatever protocol is being used to do so. Once the offer arrives, navigator.getUserMedia() is once again used to create the stream, which is added to theRTCPeerConnection. An RTCSessionDescription object is created and set up as the remote description by calling RTCPeerConnection.setRemoteDescription().

Then an answer is created using RTCPeerConnection.createAnswer() and sent back to the server, which forwards it to the caller.

var offer = getOfferFromFriend();
navigator.getUserMedia({video: true}, function(stream) {
  pc.onaddstream({stream: stream});
  pc.addStream(stream);

  pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
    pc.createAnswer(function(answer) {
      pc.setLocalDescription(new RTCSessionDescription(answer), function() {
        // send the answer to a server to be forwarded back to the caller (you)
      }, error);
    }, error);
  }, error);
});

応答のハンドリング

Back on the original machine, the response is received. Once that happens, call RTCPeerConnection.setRemoteDescription() to set the response as the remote end of the connection.

// pc was set up earlier when we made the original offer
var offer = getResponseFromFriend();
pc.setRemoteDescription(new RTCSessionDescription(offer), function() { }, error);

プロパティ

This interface inherits properties from its parent interface, EventTarget.

RTCPeerConnection.iceConnectionState 読取専用
Returns an enum of type RTCIceConnectionState that describes the ICE connection state for the connection. When this value changes, a iceconnectionstatechange event is fired on the object. The possible values are:
  • "new": the ICE agent is gathering addresses or waiting for remote candidates (or both).
  • "checking": the ICE agent has remote candidates, on at least one component, and is check them, though it has not found a connection yet. At the same time, it may still be gathering candidates.
  • "connected": the ICE agent has found a usable connection for each component, but is still testing more remote candidates for a better connection. At the same time, it may still be gathering candidates.
  • "completed": the ICE agent has found a usable connection for each component, and is no more testing remote candidates.
  • "failed": the ICE agent has checked all the remote candidates and didn't find a match for at least one component. Connections may have been found for some components.
  • "disconnected": liveness check has failed for at least one component. This may be a transient state, e. g. on a flaky network, that can recover by itself.
  • "closed": the ICE agent has shutdown and is not answering to requests.
RTCPeerConnection.iceGatheringState 読取専用
Returns an enum of type RTCIceGatheringState that describes the ICE gathering state for the connection. The possible values are:
  • "new": the object was just created, and no networking has occurred yet.
  • "gathering": the ICE engine is in the process of gathering candidates for this connection.
  • "complete": the ICE engine has completed gathering. Events such as adding a new interface or a new TURN server will cause the state to go back to gathering.
RTCPeerConnection.localDescription 読取専用
Returns a RTCSessionDescription describing the session for the local end of the connection. If it has not yet been set, it can be null.
RTCPeerConnection.peerIdentity 読取専用
Returns a RTCIdentityAssertion, that is a couple of a domain name (idp) and a name (name) representing the identity of the remote peer of this connection, once set and verified. If no peer has yet been set and verified, this property will return null. Once set, via the appropriate method, it can't be changed.
RTCPeerConnection.remoteDescription 読取専用
Returns a RTCSessionDescription describing the session for the remote end of the connection. If it has not yet been set, it can be null.
RTCPeerConnection.signalingState 読取専用
Returns an enum of type RTCSignalingState that describes the signaling state of the local connection. This state describes the SDP offer, that defines the configuration of the connections like the description of the locally associated objects of type MediaStream, the codec/RTP/RTCP options, the candidates gathered by the ICE Agent. When this value changes, a signalingstatechange event is fired on the object. The possible values are:
  • "stable": there is no SDP offer/answer exchange in progress. This is also the initial state of the connection.
  • "have-local-offer": the local end of the connection has locally applied a SDP offer.
  • "have-remote-offer": the remote end of the connection has locally applied a SDP offer.
  • "have-local-pranswer": a remote SDP offer has been applied, and a SDP pranswer applied locally.
  • "have-remote-pranswer": a local SDP offer has been applied, and a SDP pranswer applied remotely.
  • "closed": the connection is closed.

イベントハンドラ

RTCPeerConnection.onaddstream
Is the event handler called when the addstream event is received. Such an event is sent when a MediaStream is added to this connection by the remote peer. The event is sent immediately after the call RTCPeerConnection.setRemoteDescription() and doesn't wait for the result of the SDP negotiation.
RTCPeerConnection.ondatachannel
Is the event handler called when the datachannel event is received. Such an event is sent when a RTCDataChannel is added to this connection.
RTCPeerConnection.onicecandidate
Is the event handler called when the icecandidate event is received. Such an event is sent when a RTCICECandidate object is added to the script.
RTCPeerConnection.oniceconnectionstatechange
Is the event handler called when the iceconnectionstatechange event is received. Such an event is sent when the value of iceConnectionState changes.
RTCPeerConnection.onidentityresult
Is the event handler called when the identityresult event is received. Such an event is sent when an identity assertion is generated, via getIdentityAssertion(), or during the creation of an offer or an answer.
RTCPeerConnection.onidpassertionerror
Is the event handler called when the idpassertionerror event is received. Such an event is sent when the associated identity provider (IdP) encounters an error while generating an identity assertion.
RTCPeerConnection.onidpvalidationerror
Is the event handler alled when the idpvalidationerror event is received. Such an event is sent when the associated identity provider (IdP) encounters an error while validating an identity assertion.
RTCPeerConnection.onnegotiationneeded
Is the event handler called when the negotiationneeded event, sent by the browser to inform that negotiation will be required at some point in the future, is received.
RTCPeerConnection.onpeeridentity
Is the event handler called when the peeridentity event, sent when a peer identity has been set and verified on this connection, is received.
RTCPeerConnection.onremovestream
Is the event handler called when the removestream event, sent when a MediaStream is removed from this connection, is received.
RTCPeerConnection.onsignalingstatechange
Is the event handler called when the signalingstatechange event, sent when the value of signalingState changes, is received.

メソッド

RTCPeerConnection()
Constructor; returns a new RTCPeerConnection object.
RTCPeerConnection.createOffer()
Creates an offer that is a request to find a remote peer with a specific configuration. The two first parameters of this methods are respectively success and error callbacks, the optional third one are options the user want to have, like audio or video streams.
RTCPeerConnection.createAnswer()
Creates an answer to the offer received by the remote peer, in a two-part offer/answer negotiation of a connection. The two first parameters are respectively success and error callbacks, the optional third one represent options for the answer to be created.
RTCPeerConnection.setLocalDescription()
Changes the local description associated with the connection. The description defines the properties of the connection like its codec. The connection is affected by this change and must be able to support both old and new descriptions. The method takes three parameters, a RTCSessionDescription object to set, and two callbacks, one called if the change of description succeeds, another called if it failed.
RTCPeerConnection.setRemoteDescription()
Changes the remote description associated with the connection. The description defines the properties of the connection like its codec. The connection is affected by this change and must be able to support both old and new descriptions. The method takes three parameters, a RTCSessionDescription object to set, and two callbacks, one called if the change of description succeeds, another called if it failed.
RTCPeerConnection.updateIce()
 
RTCPeerConnection.addIceCandidate()
 
RTCPeerConnection.getConfiguration()
 
RTCPeerConnection.getLocalStreams()
Returns an array of MediaStream associated with the local end of the connection. The array may be empty.
RTCPeerConnection.getRemoteStreams()
Returns an array of MediaStream associated with the remote end of the connection. The array may be empty.
RTCPeerConnection.getStreamById()
Returns the MediaStream with the given id that is associated with local or remote end of the connection. If no stream matches, it returns null.
RTCPeerConnection.addStream()
Adds a MediaStream as a local source of audio or video. If the negotiation already happened, a new one will be needed for the remote peer to be able to use it.
RTCPeerConnection.removeStream()
Removes a MediaStream as a local source of audio or video. If the negotiation already happened, a new one will be needed for the remote peer to stop using it.
RTCPeerConnection.close()
Abruptly closes a connection.
RTCPeerConnection.createDataChannel()
Creates a new RTCDataChannel associated with this connection. The method takes a dictionary as parameter, with the configuration required for the underlying data channel, like its reliability.
RTCPeerConnection.createDTMFSender()
Creates a new RTCDTMFSender, associated to a specific MediaStreamTrack, that will be able to send DTMF phone signaling over the connection.
RTCPeerConnection.getStats()
Creates a new RTCStatsReport that contains and allows access to statistics regarding the connection.
RTCPeerConnection.setIdentityProvider()
Sets the Identity Provider (IdP) to the triplet given in parameter: its name, the protocol used to communicate with it (optional) and an optional username. The IdP will be used only when an assertion will be needed.
RTCPeerConnection.getIdentityAssertion()
Initiates the gathering of an identity assertion. This has an effect only if the signalingState is not "closed". It is not expected for the application dealing with the RTCPeerConnection: this is automatically done; an explicit call only allows to anticipate the need.

コンストラクタ

new RTCPeerConnection(RTCConfiguration configuration, optional MediaConstraints constraints);

注釈: While the PeerConnection specification reads like passing an RTCConfiguration object is required, Firefox will supply a default if you don't.

メソッド

createOffer

void createOffer(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback, optional MediaConstraints constraints);

オファーの作成は、ローカルマシンのPeerConnectionを容易に扱えるようにするためのディスクリプションデータのblobを生成します。リモートのピアコネクションを得たときローカルピアコネクションをセットアップしたい場合に使用してください。

var pc = new PeerConnection();
pc.addStream(video);
pc.createOffer(function(desc){
  pc.setLocalDescription(desc, function() {
    // リモートクライアントとネゴシエーション可能なオファーをサーバーへ送信します。
  });
}

引数

successCallback
RTCSessionDescriptionCallback は1つの RTCSessionDescription オブジェクトを渡します。
errorCallback
RTCPeerConnectionErrorCallback は1つの DOMError オブジェクトを渡します。
[optional] constraints
任意の {domxref("MediaConstraints")}} オブジェクトです。

createAnswer

void createAnswer(RTCSessionDescriptionCallback successCallback, RTCPeerConnectionErrorCallback failureCallback, optional MediaConstraints constraints)")

リモートコネクションから送信されたオファーに対して応答します。

var pc = new PeerConnection();
pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
  pc.createAnswer(function(answer) {
    pc.setLocalDescription(answer, function() {
      // リモートコネクションにアンサーを送信します。
    })
  })
});

引数

successCallback
RTCSessionDescriptionCallback は1つの RTCSessionDescription オブジェクトを渡します。
errorCallback
RTCPeerConnectionErrorCallback は1つの DOMError オブジェクトを渡します。
[optional] constraints
任意の MediaConstraints オブジェクトです。

updateIce()

updateIce(optional RTCConfiguration configuration, optional MediaConstraints constraints)

updateIce メソッドは、 ICEエージェントのローカル候補の収集とリモート候補のパイピングの処理を更新します。"IceTransports"と呼ばれる必須の制約が存在する場合、ICEエンジンがどのように動作するかを制御します。被受信者によって位置情報が漏れるのを防ぐため、呼び出しが受理される前に、TURN候補の使用を制限することができます。このメソッドの呼び出しは、ICEエージェントの状態を変更し、また接続可能性が確立された場合はメディア状態を変更するでしょう。

 

addIceCandidate()

addIceCandidate (RTCIceCandidate candidate, Function successCallback, RTCPeerConnectionErrorCallback failureCallback);

addIceCandidate() メソッドはICEエージェントのリモート候補を提供します。加えて、リモートディスクリプションの追加、"IceTransports"制約が"none"に設定されていない場合、接続可能性の確認は新しい候補として送信されるでしょう。これはICEエージェントの接続状態を変更し、異なる接続可能性が確立された場合メディアの状態を変更するでしょう。

pc.addIceCandidate(new RTCIceCandidate(candidate));

createDataChannel

RTCDataChannel createDataChannel (DOMString label, optional RTCDataChannelInit dataChannelDict);

ピアコネクション上で動画や音声でないデータを送信するためのデータチャンネルを作成します。

var pc = new PeerConnection();
var channel = pc.createDataChannel("Mydata");
channel.onopen = function(event) {
  channel.send('sending a message');
}
channel.onmessage = function(event) { console.log(event.data); }

その他の記事

ドキュメントのタグと貢献者

このページの貢献者: takamin, dreissig.jahrhundert
最終更新者: takamin,