View
Extends: BaseWebRTC
Source: View.js:49
Manages connection with a secure WebSocket path to signal the Millicast server and establishes a WebRTC connection to view a live stream.
Before you can view an active broadcast, you will need:
- A connection path that you can get from Director module or from your own implementation.
Constructor
new View(
streamName: String,
tokenGenerator: tokenGeneratorCallback,
mediaElement?: HTMLMediaElement,
autoReconnect?: Boolean,
): ViewParameters
streamName(String) — Deprecated: Millicast existing stream name.tokenGenerator(tokenGeneratorCallback) — Callback function executed when a new token is needed.mediaElement(HTMLMediaElement, optional, default: null) — Deprecated: Target HTML media element to mount stream.autoReconnect(Boolean, optional, default: true) — Enable auto reconnect to stream.
Instance Methods
connect(options?: Object): Promise.<void>
Connects to an active stream as subscriber.
In the example, addStreamToYourVideoTag and getYourSubscriberConnectionPath is your own implementation.
Parameters
options(Object, optional) — General subscriber options.options.dtx(Boolean, optional, default: false) — True to modify SDP for supporting dtx in opus. Otherwise False.options.absCaptureTime(Boolean, optional, default: false) — True to modify SDP for supporting absolute capture time header extension. Otherwise False.options.metadata(Boolean, optional, default: false) — Enable metadata extraction if stream is compatible.options.drm(Boolean, optional, default: false) — Enable the DRM protected stream playback.options.disableVideo(Boolean, optional, default: false) — Disable the opportunity to receive video stream.options.disableAudio(Boolean, optional, default: false) — Disable the opportunity to receive audio stream.options.multiplexedAudioTracks(Number, optional) — Number of audio tracks to recieve VAD multiplexed audio for secondary sources.options.pinnedSourceId(String, optional) — Id of the main source that will be received by the default MediaStream.options.excludedSourceIds(Array.<String>, optional) — Do not receive media from the these source ids.options.events(Array.<String>, optional) — Override which events will be delivered by the server (any of "active" | "inactive" | "vad" | "layers" | "viewercount" | "updated").*options.peerConfig(PeerConnectionConfig, optional, default: null) — Options to configure the new RTCPeerConnection.options.layer(LayerInfo, optional) — Select the simulcast encoding layer and svc layers for the main video track, leave empty for automatic layer selection based on bandwidth estimation.options.forcePlayoutDelay(Object, optional, default: false) — Ask the server to use the playout delay header extension.options.forcePlayoutDelay.min(Number, optional) — Set minimum playout delay value.options.forcePlayoutDelay.max(Number, optional) — Set maximum playout delay value.
options.enableDRM(Boolean, optional) — Enable DRM, default is false.options.forceSmooth(Boolean, optional) — Enables/Disables force smoothing (less aggressive layer switching) when viewing streams. Defaults to what the server determines.options.abrConfiguration(AbrConfigurationOptions, optional) — The strategy for initial playback behavior. Can be one of ("quality" | "performance" | "bandwidth")options.peerRepair(PeerRepairOptions, optional) — Experimental. Detect a connected but unusable ICE candidate pair and replace the connection when a better pair exists. Disabled by default.
Returns
Promise.<void>— Promise object which resolves when the connection was successfully established.
Fires
PeerConnection#event:trackSignaling#event:broadcastEventPeerConnection#event:connectionStateChange
Example
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)
}select(layer: LayerInfo)
Select the simulcast encoding layer and svc layers for the main video track
Parameters
layer(LayerInfo) — leave empty for automatic layer selection based on bandwidth estimation.
addRemoteTrack(
media: String,
streams: Array.<MediaStream>,
): Promise.<RTCRtpTransceiver>
Add remote receiving track.
Parameters
media(String) — Media kind ('audio' | 'video').streams(Array.<MediaStream>) — Streams the track will belong to.
Returns
Promise.<RTCRtpTransceiver>— Promise that will be resolved when the RTCRtpTransceiver is assigned an mid value.
project(sourceId: String | null, mapping: Array.<Object>)
Start projecting source in selected media ids.
Parameters
sourceId(String | null) — Selected source id.mapping(Array.<Object>) — Mapping of the source track ids to the receiver midsmapping.trackId(String, optional) — Track id from the source (received on the "active" event), if not set the media kind will be used instead.mapping.media(String, optional) — Track kind of the source ('audio' | 'video'), if not set the trackId will be used instead.mapping.mediaId(String, optional) — mid value of the rtp receiver in which the media is going to be projected. If no mediaId is defined, the first track from the main media stream with the same media type as the input source track will be used.mapping.layer(LayerInfo, optional) — Select the simulcast encoding layer and svc layers, only applicable to video tracks.mapping.promote(Boolean, optional) — To remove all existing limitations from the source, such as restricted bitrate or resolution, set this to true.
unproject(mediaIds: Array.<String>)
Stop projecting attached source in selected media ids.
Parameters
mediaIds(Array.<String>) — mid value of the receivers that are going to be detached.
repairConnection(decision: Object)
Replaces the current connection because its selected ICE candidate pair is unusable. The current connection keeps running until the replacement is connected. If the replacement fails, the current connection is kept and the candidate demotions are cleared.
Parameters
decision(Object) — Result of PeerRepairMonitor#evaluate.
Fires
View#event:peerRepair
configureDRM(options: DRMOptions)
Configure DRM protected stream. When there are EncryptionParameters in the payload of 'active' broadcast event, this method should be called
Parameters
options(DRMOptions) — the options for DRM playback
removeDRMConfiguration(mediaId: String)
Remove DRM configuration for a mediaId
Parameters
mediaId(String)
exchangeDRMConfiguration(
targetMediaId: String,
sourceMediaId: String,
)
Exchange the DRM configuration between two transceivers Both of the transceivers should be used for DRM protected streams
Parameters
targetMediaId(String)sourceMediaId(String)
getRTCPeerConnection(): RTCPeerConnection
Inherited from BaseWebRTC#getRTCPeerConnection
Get current RTC peer connection.
Returns
RTCPeerConnection— Object which represents the RTCPeerConnection.
stop()
Inherited from BaseWebRTC#stop
Overrides: BaseWebRTC#stop
Stops connection.
isActive(): Boolean
Inherited from BaseWebRTC#isActive
Get if the current connection is active.
Returns
Boolean
setReconnect()
Inherited from BaseWebRTC#setReconnect
Sets reconnection if autoReconnect is enabled.
reconnect(data?: Object)
Inherited from BaseWebRTC#reconnect
Reconnects to last broadcast.
Parameters
data(Object, optional) — This object contains the error property. It may be expanded to contain more information in the future.
Properties
error(String) — The value sent in the first reconnect event within the error key of the payload
Fires
BaseWebRTC#event:reconnect
Instance Fields
isDRMOn
Check if there are any DRM protected Track
Events
peerRepair: Object
Emits when a peer repair starts, completes or fails.
Properties
state("started" | "completed" | "failed")reason(String) — Why the selected candidate pair was considered bad.selected(Object) — Selected candidate pair (local type, remote address, RTT).alternative(Object) — Candidate pair expected to be used after the repair.demote(Array.<String>) — Remote candidates demoted in the replacement SDP.relayOnly(Boolean) — Whether the replacement uses only relay candidates.
metadata: Object
Emits when metadata have been extracted from the stream.
Properties
mid(String) — Media identifier that contains the metadata.track(Object) — Track object that contains the metadata.uuid(String) — UUID of the metadata.timecode(Date) — Timecode of when the metadata were generated.unregistered(Object) — Unregistered data.
reconnect: Object
Inherited from BaseWebRTC#event:reconnect
Emits with every reconnection attempt made when an active stream stopped unexpectedly.
Properties
timeout(Number) — Next retry interval in milliseconds.error(Error) — Error object with cause of failure. Possible errors are: