Constructor
new PeerConnection()
- Source
const peerConnection = new PeerConnection()
Extends
- EventEmitter
Methods
(async) addRemoteTrack(media, streams) → {Promise.<RTCRtpTransceiver>}
Add remote receiving track.
Name | Type | Description |
---|---|---|
media | String | Media kind ('audio' | 'video'). |
streams | Array.<MediaStream> | Streams the track will belong to. |
- Source
Promise that will be resolved when the RTCRtpTransceiver is assigned an mid value.
- Type:
- Promise.<RTCRtpTransceiver>
(async) closeRTCPeer()
Close RTC peer connection.
- Source
(async) createRTCPeer(config, modeopt)
Instance new RTCPeerConnection.
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config | RTCConfiguration | Peer configuration. Properties
| |||||||||||||||||
mode | String | <optional> | "Viewer" | Type of connection that is trying to be created, either 'Viewer' or 'Publisher'. |
- Source
(async) getRTCLocalSDP(options) → {Promise.<String>}
Get the SDP modified depending the options. Optionally set the SDP information to local peer.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | Properties
|
- Source
Promise object which represents the SDP information of the created offer.
- Type:
- Promise.<String>
getRTCPeer() → {RTCPeerConnection}
Get current RTC peer connection.
- Source
Object which represents the RTCPeerConnection.
- Type:
- RTCPeerConnection
getRTCPeerStatus() → (nullable) {RTCPeerConnectionState}
Get peer connection state.
- Source
Promise object which represents the peer connection state.
- Type:
- RTCPeerConnectionState
getTracks() → {Array.<MediaStreamTrack>}
Get sender tracks
- Source
An array with all tracks in sender peer.
- Type:
- Array.<MediaStreamTrack>
initStats()
Initialize the statistics monitoring of the RTCPeerConnection.
It will be emitted every second.
- Source
- PeerConnection#event:stats
peerConnection.initStats()
import Publish from '@millicast/sdk'
//Initialize and connect your Publisher
const millicastPublish = new Publish(streamName, tokenGenerator)
await millicastPublish.connect(options)
//Initialize get stats
millicastPublish.webRTCPeer.initStats()
//Capture new stats from event every second
millicastPublish.webRTCPeer.on('stats', (stats) => {
console.log('Stats from event: ', stats)
})
import View from '@millicast/sdk'
//Initialize and connect your Viewer
const millicastView = new View(streamName, tokenGenerator)
await millicastView.connect()
//Initialize get stats
millicastView.webRTCPeer.initStats()
//Capture new stats from event every second
millicastView.webRTCPeer.on('stats', (stats) => {
console.log('Stats from event: ', stats)
})
replaceTrack(mediaStreamTrack)
Replace current audio or video track that is being broadcasted.
Name | Type | Description |
---|---|---|
mediaStreamTrack | MediaStreamTrack | New audio or video track to replace the current one. |
- Source
(async) setRTCRemoteSDP(sdp) → {Promise.<void>}
Set SDP information to remote peer.
Name | Type | Description |
---|---|---|
sdp | String | New SDP to be set in the remote peer. |
- Source
Promise object which resolves when SDP information was successfully set.
- Type:
- Promise.<void>
stopStats()
Stops the monitoring of RTCPeerConnection statistics.
- Source
peerConnection.stopStats()
updateBandwidthRestriction(sdp, bitrate) → {String}
Update remote SDP information to restrict bandwidth.
Name | Type | Description |
---|---|---|
sdp | String | Remote SDP. |
bitrate | Number | New bitrate value in kbps or 0 unlimited bitrate. |
- Source
Updated SDP information with new bandwidth restriction.
- Type:
- String
(async) updateBitrate(bitrate) → {Promise.<void>}
Set SDP information to remote peer with bandwidth restriction.
Name | Type | Default | Description |
---|---|---|---|
bitrate | Number | 0 | New bitrate value in kbps or 0 unlimited bitrate. |
- Source
Promise object which resolves when bitrate was successfully updated.
- Type:
- Promise.<void>
(static) getCapabilities(kind) → {MillicastCapability}
Gets user's browser media capabilities compared with Millicast Media Server support.
Name | Type | Description |
---|---|---|
kind | "audio" | | Type of media for which you wish to get sender capabilities. |
- Source
Object with all capabilities supported by user's browser and Millicast Media Server.
- Type:
- MillicastCapability
Events
connectionStateChange
Peer connection state change. Could be new, connecting, connected, disconnected, failed or closed.
- RTCPeerConnectionState
- Source
track
New track event.
- RTCTrackEvent
- Source