Constructor
new View(streamName, tokenGenerator, mediaElementopt, autoReconnectopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
streamName | String | Deprecated: Millicast existing stream name. | ||
tokenGenerator | tokenGeneratorCallback | Callback function executed when a new token is needed. | ||
mediaElement | HTMLMediaElement | <optional> | null | Deprecated: Target HTML media element to mount stream. |
autoReconnect | Boolean | <optional> | true | Enable auto reconnect to stream. |
Extends
Members
isDRMOn
Check if there are any DRM protected Track
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. |
Promise that will be resolved when the RTCRtpTransceiver is assigned an mid value.
- Type:
- Promise.<RTCRtpTransceiver>
configureDRM(options)
Configure DRM protected stream. When there are EncryptionParameters in the payload of 'active' broadcast event, this method should be called
Name | Type | Description |
---|---|---|
options | DRMOptions | the options for DRM playback |
(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'
//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])
})
millicastView.on('error', (error) => {
console.error('Error from Millicast SDK', error)
})
//Start connection to broadcast
try {
await millicastView.connect()
} catch (e) {
console.log('Connection failed, handle error', e)
}
exchangeDRMConfiguration(targetMediaId, sourceMediaId)
Exchange the DRM configuration between two transceivers Both of the transceivers should be used for DRM protected streams
Name | Type | Description |
---|---|---|
targetMediaId | String | |
sourceMediaId | String |
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
removeDRMConfiguration(mediaId)
Remove DRM configuration for a mediaId
Name | Type | Description |
---|---|---|
mediaId | String |
(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.
- Overrides
- 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