Constructor
new View(streamName, tokenGenerator, mediaElementopt, autoReconnectopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
streamName | String | Millicast existing Stream Name where you want to connect. | ||
tokenGenerator | tokenGeneratorCallback | Callback function executed when a new token is needed. | ||
mediaElement | HTMLMediaElement | <optional> | null | Target HTML media element to mount stream. |
autoReconnect | Boolean | <optional> | true | Enable auto reconnect to stream. |
Extends
Methods
(async) addRemoteTrack(media, streams) → {Promise.<RTCRtpTransceiver>}
Add remote receving track.
Name | Type | Description |
---|---|---|
media | String | Media kind ('audio' | 'video'). |
streams | Array.<MediaStream> | Streams the track will belong to. |
Promise that will be resolved when the RTCRtpTransceiver is assigned an mid value.
- Type:
- Promise.<RTCRtpTransceiver>
(async) connect(optionsopt) → {Promise.<void>}
Connects to an active stream as subscriber.
In the example, addStreamToYourVideoTag
and getYourSubscriberConnectionPath
is your own implementation.
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | General subscriber options. Properties
|
Promise object which resolves when the connection was successfully established.
- Type:
- Promise.<void>
await millicastView.connect(options)
import View from '@millicast/sdk'
// Create media element
const videoElement = document.createElement("video")
//Define callback for generate new token
const tokenGenerator = () => getYourSubscriberInformation(accountId, streamName)
//Create a new instance
const streamName = "Millicast Stream Name where i want to connect"
const millicastView = new View(streamName, tokenGenerator, videoElement)
//Start connection to broadcast
try {
await millicastView.connect()
} catch (e) {
console.log('Connection failed, handle error', e)
}
import View from '@millicast/sdk'
//Define callback for generate new token
const tokenGenerator = () => getYourSubscriberInformation(accountId, streamName)
//Create a new instance
const streamName = "Millicast Stream Name where i want to connect"
const millicastView = new View(streamName, tokenGenerator)
//Set track event handler to receive streams from Publisher.
millicastView.on('track', (event) => {
addStreamToYourVideoTag(event.streams[0])
})
//Start connection to broadcast
try {
await millicastView.connect()
} catch (e) {
console.log('Connection failed, handle error', e)
}
getRTCPeerConnection() → {RTCPeerConnection}
Get current RTC peer connection.
- Inherited From
- Source
Object which represents the RTCPeerConnection.
- Type:
- RTCPeerConnection
isActive() → {Boolean}
Get if the current connection is active.
- Inherited From
- Source
- True if connected, false if not.
- Type:
- Boolean
(async) project(sourceId, mapping)
Start projecting source in selected media ids.
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sourceId | String | Selected source id. | ||||||||||||||||||||||||
mapping | Array.<Object> | Mapping of the source track ids to the receiver mids Properties
|
(async) reconnect(dataopt)
Reconnects to last broadcast.
Name | Type | Attributes | Description |
---|---|---|---|
data | Object | <optional> | This object contains the error property. It may be expanded to contain more information in the future. |
Name | Type | Description |
---|---|---|
error | String | The value sent in the first reconnect event within the error key of the payload |
- Inherited From
- Source
(async) select(layer)
Select the simulcast encoding layer and svc layers for the main video track
Name | Type | Description |
---|---|---|
layer | LayerInfo | leave empty for automatic layer selection based on bandwidth estimation. |
setReconnect()
Sets reconnection if autoReconnect is enabled.
- Inherited From
- Source
stop()
Stops connection.
- Inherited From
- Source
(async) unproject(mediaIds)
Stop projecting attached source in selected media ids.
Name | Type | Description |
---|---|---|
mediaIds | Array.<String> | mid value of the receivers that are going to be detached. |
Events
reconnect
Emits with every reconnection attempt made when an active stream stopped unexpectedly.
- Object
Name | Type | Description |
---|---|---|
timeout | Number | Next retry interval in milliseconds. |
error | Error | Error object with cause of failure. Possible errors are:
|
- Inherited From
- Source