PeerConnection

PeerConnection

Manage the WebRTC connection and SDP information between peers.

Constructor

# new PeerConnection()

Example
const peerConnection = new PeerConnection()

Extends

  • EventEmitter

Methods

# (static) getCapabilities(kind) → {WowzaCapability}

Get the user's browser media capabilities as compared to Wowza Video support.

Parameters:
Name Type Description
kind "audio" | "video"

The type of media to get sender media capabilities for.

Returns:

An object with all media capabilities supported by the user's browser and Wowza Video.

Type
WowzaCapability

# (async) addRemoteTrack(media, streams) → {Promise.<RTCRtpTransceiver>}

Add a remote receiving track.

Parameters:
Name Type Description
media String

The media type ('audio' | 'video').

streams Array.<MediaStream>

Streams the track will belong to.

Returns:

Promise that will be resolved when the RTCRtpTransceiver is assigned an mid value.

Type
Promise.<RTCRtpTransceiver>

# (async) closeRTCPeer()

Close the RTCPeerConnection.

# (async) createRTCPeer(config)

Create a new RTCPeerConnection instance.

Parameters:
Name Type Default Description
config RTCConfiguration null

The peer configuration.

# (async) getRTCLocalSDP(options) → {Promise.<String>}

Get a modified SDP based on the specified options. Optionally, set the SDP information to the local peer.

Parameters:
Name Type Description
options Object
Properties
Name Type Description
stereo Boolean

Enable SDP support for stereo.

dtx Boolean

Enable SDP support for DTX in Opus.

mediaStream MediaStream | Array.<MediaStreamTrack>

The MediaStream to offer in a stream. This object must have one audio track or one video track. Alternatively, you can provide both tracks in an array.

codec VideoCodec

The selected video codec to support simulcast.

simulcast Boolean

Enable SDP support for simulcast. Only available in Google Chrome and with H.264 or VP8 video codecs.

scalabilityMode String

The selected scalability mode. You can get the available capabilities using the PeerConnection.getCapabilities method. Only available in Google Chrome.

absCaptureTime Boolean

Enable SDP support for an absolute capture time header extension.

dependencyDescriptor Boolean

Enable SDP support for an AOM dependency descriptor header extension.

disableAudio Boolean

Disable support for audio.

disableVideo Boolean

Disable support for video.

setSDPToPeer Boolean

Enable to set the SDP to local peer.

Returns:

A promise object that represents the SDP information of the created offer.

Type
Promise.<String>

# getRTCPeer() → {RTCPeerConnection}

Get the current RTCPeerConnection.

Returns:

The RTCPeerConnection.

Type
RTCPeerConnection

# getRTCPeerStatus() → (nullable) {RTCPeerConnectionState}

Get the peer connection state.

Returns:

A promise object that represents the peer connection state.

Type
RTCPeerConnectionState

# getTracks() → {Array.<MediaStreamTrack>}

Get the sender tracks.

Returns:

An array with all tracks in the sender peer.

Type
Array.<MediaStreamTrack>

# initStats()

Initialize the statistics monitoring of the RTCPeerConnection and emit every second.

Examples
peerConnection.initStats()
import Publish from '@wowzamediasystems/sdk-rts'

//Initialize and connect your Publisher
const wowzaPublish = new Publish(streamName, tokenGenerator)
await wowzaPublish.connect(options)

//Initialize get stats
wowzaPublish.webRTCPeer.initStats()

//Capture new stats from event every second
wowzaPublish.webRTCPeer.on('stats', (stats) => {
  console.log('Stats from event: ', stats)
})
import View from '@wowzamediasystems/sdk-rts'

//Initialize and connect your Viewer
const wowzaView = new View(streamName, tokenGenerator)
await wowzaView.connect()

//Initialize get stats
wowzaView.webRTCPeer.initStats()

//Capture new stats from event every second
wowzaView.webRTCPeer.on('stats', (stats) => {
  console.log('Stats from event: ', stats)
})

# replaceTrack(mediaStreamTrack)

Replace the current audio or video track that is being broadcast.

Parameters:
Name Type Description
mediaStreamTrack MediaStreamTrack

The new audio or video track to replace the current one.

# (async) setRTCRemoteSDP(sdp) → {Promise.<void>}

Set the SDP information in the remote peer.

Parameters:
Name Type Description
sdp String

The new SDP to be set in the remote peer.

Returns:

A promise object that resolves when SDP information was successfully set.

Type
Promise.<void>

# stopStats()

Stop monitoring of RTCPeerConnection statistics.

Example
peerConnection.stopStats()

# updateBandwidthRestriction(sdp, bitrate) → {String}

Update remote SDP information to restrict bandwidth.

Parameters:
Name Type Description
sdp String

The remote SDP.

bitrate Number

The new bitrate value, in kbps, or 0 for unlimited bitrate.

Returns:

The updated SDP information with the new bandwidth restriction.

Type
String

# (async) updateBitrate(bitrate) → {Promise.<void>}

Update remote SDP information to restrict bitrate.

Parameters:
Name Type Default Description
bitrate Number 0

The new bitrate value, in kbps, or 0 for unlimited bitrate.

Returns:

A promise object that resolves when bitrate was successfully updated.

Type
Promise.<void>

Events

# connectionStateChange

Peer connection state change. States include new, connecting, connected, disconnected, failed, or closed.

Type:
  • RTCPeerConnectionState

# stats

Peer connection incoming statistics.

# track

New track event.

Type:
  • RTCTrackEvent