JavaScripture
Contribute via GitHub Feedback

RTCPeerConnection : EventTarget

Enables Real Time Communication of audio, video, and data to another browser/computer using the WebRTC peer to peer protocol.

Although WebRTC is a peer to peer protocol, the peers need some information about each other before they can communicate. Typically this is done with a Signaling Server, but any mechanism to transfer data can be used. The following demonstrates setting up the peer connection using the clipboard (via copy/paste) to transfer the connection data.

Offerer

This example demonstrates the peer that creates the offer.

Example:

Run

Results:

 

Answerer

This example demonstrates the peer that receives the offer and creates the answer.

Example:

Run

Results:

 

Constructors

new RTCPeerConnection([configuration : Object]) : RTCPeerConnection
configuration : {
iceServers :Iterable
iceTransportPolicy :StringEither 'relay' or 'all'.
bundlePolicy :StringOne of 'balanced', 'max-compat', or 'max-bundle'.
rtcpMuxPolicy :StringMust be 'require'
certificates :Iterable<RTCCertificate>
iceCandidatePoolSize :Number
}

The elements of the iceServers property in the configuration argument should be of type: { url : (String or Iterable<String>), username : String, credential : String, credentialType : String }

Instance Properties

canTrickleIceCandidates : Boolean  

Returns true if the remote peer accepts trickled ice candidates. Only valid after calling setRemoteDescription().

connectionState : String  

One of 'closed', 'failed', 'disconnected', 'new', 'connecting', or 'connected'.

currentLocalDescription : RTCSessionDescription  

currentRemoteDescription : RTCSessionDescription  

iceConnectionState : String  

One of 'closed', 'failed', 'disconnected', 'new', 'checking', 'completed', or 'connected'.

iceGatheringState : String  

One of 'new', 'gathering', or 'complete'.

localDescription : RTCSessionDescription  

pendingLocalDescription : RTCSessionDescription  

pendingRemoteDescription : RTCSessionDescription  

remoteDescription : RTCSessionDescription  

sctp : RTCSctpTransport  

signalingState : String  

One of 'stable', 'have-local-offer', 'have-remote-offer', 'have-local-pranswer', 'have-remote-pranswer', or 'closed'

Instance Methods

addIceCandidate([candidate : Object]) : Promise<undefined>
candidate : {
candidate :String
sdpMid :String
sdpMLineIndex :Number
usernameFragment :String
}

addTrack(track : MediaStreamTrack, [stream1 : MediaStream, [stream2 : MediaStream, [...]]]) : RTCRtpSender

addTransceiver(kind : String, configuration : Object) : RTCRtpTransceiver
configuration : {
direction :StringOne of 'sendrecv', 'sendonly', 'recvonly', 'inactive', or 'stopped'. Defaults to 'sendrecv'.
streams :Iterable<MediaStream>
sendEncodings :Iterable
}

The elements of the sendEncodings property in the configuration argument should be of type: { rid : String, active : Boolean /* Default = true */, maxBitrate : Number, scalingResolutionDownBy : Number }

close() : undefined

createAnswer([options : Object]) : Promise<RTCSessionDescriptionInit>
options : {
}

createDataChannel(label : String, [options : Object]) : RTCDataChannel
options : {
ordered :BooleanDefaults to true
maxPacketLifeTime :Number
maxRetransmits :Number
protocl :String
negotiated :String
id :Number
}

createOffer([options : Object]) : Promise<RTCSessionDescriptionInit>
options : {
iceRestart :Boolean
}

getConfiguration() : RTCConfiguration

getReceivers() : Array<RTCRtpReceiver>

getSenders() : Array<RTCRtpSender>

getStats([selector : MediaStreamTrack]) : Promise<RTCStatsReport>

getTransceivers() : Array<RTCRtpTransceiver>

removeTrack(sender : RTCRtpSender) : undefined

restartIce() : undefined

setConfiguration([configuration : RTCConfiguration]) : undefined

setLocalDescription([description : RTCSessionDescriptionInit]) : Promise<undefined>

setRemoteDescription(description : RTCSessionDescriptionInit) : Promise<undefined>

Instance Events

onconnectionstatechange / 'connectionstatechange'  
listener(event : Event) : undefined

ondatachannel / 'datachannel'  
listener(event : RTCDataChannelEvent) : undefined

onicecandidate / 'icecandidate'  
listener(event : RTCPeerConnectionIceEvent) : undefined

onicecandidateerror / 'icecandidateerror'  

oniceconnectionstatechange / 'iceconnectionstatechange'  
listener(event : Event) : undefined

onicegatheringstatechange / 'icegatheringstatechange'  
listener(event : Event) : undefined

onnegotiationneeded / 'negotiationneeded'  
listener(event : Event) : undefined

onsignalingstatechange / 'signalingstatechange'  
listener(event : Event) : undefined

ontrack / 'track'  
listener(event : RTCTrackEvent) : undefined