connect method Null safety
Connects to an active stream as subscriber.
Object options - General subscriber options.
options'dtx'
= false - True to modify SDP for supporting dtx in opus.
Otherwise False.
options'absCaptureTime'
= false - True to modify SDP for
supporting absolute capture time header extension. Otherwise False.
options'disableVideo'
= false - Disable the opportunity to receive
video stream.
options'disableAudio'
= false - Disable the opportunity to receive
audio stream.
options'multiplexedAudioTracks'
- Number of audio tracks to recieve
VAD multiplexed audio for secondary sources.
options'pinnedSourceId'
- Id of the main source that will be received
by the default MediaStream.
options'excludedSourceIds'
- Do not receive media from the these
source ids.
options'events'
- Override which events will be delivered by the
server (any of "active" | "inactive" | "vad" | "layers").*
options'peerConfig'
- Options to configure the new
RTCPeerConnection.
options'layer'
- Select the simulcast encoding layer and svc layers
for the main video track, leave empty for automatic layer selection
based on bandwidth estimation.
Returns Future object which resolves when the connection was
successfully established.
@example
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:millicast_flutter_sdk/millicast_flutter_sdk.dart';
///Setting subscriber options
DirectorSubscriberOptions directorSubscriberOptions =
DirectorSubscriberOptions(
streamAccountId: Constants.accountId,
streamName: Constants.streamName);
/// Define callback for generate new token
tokenGenerator() => Director.getSubscriber(directorSubscriberOptions);
/// Create a new instance
View view = View(
streamName: Constants.streamName,
tokenGenerator: tokenGenerator,
mediaElement: localRenderer);
//Set track event handler to receive streams from Publisher.
view.webRTCPeer.on('track', this, (ev, context) {
_localRenderer.srcObject = ev.eventData as MediaStream?;
/// Start connection to publisher
try {
await view.connect();
} catch (e) {
rethrow;
}
Implementation
/// /// Define callback for generate new token
/// tokenGenerator() => Director.getSubscriber(directorSubscriberOptions);
/// /// Create a new instance
/// View view = View(
/// streamName: Constants.streamName,
/// tokenGenerator: tokenGenerator,
/// mediaElement: localRenderer);
///
/// //Set track event handler to receive streams from Publisher.
/// view.webRTCPeer.on('track', this, (ev, context) {
/// _localRenderer.srcObject = ev.eventData as MediaStream?;
// / });
/// /// Start connection to publisher
/// try {
/// await view.connect();
/// } catch (e) {
/// rethrow;
/// }
///```
@override
connect({Map<String, dynamic> options = _connectOptions}) async {
this.options = {..._connectOptions, ...options, 'setSDPToPeer': false};
await initConnection({'migrate': false});
}