restartTrack method
Restarts the track with new options. This is useful when switching between front and back cameras.
Implementation
Future<void> restartTrack([
LocalTrackOptions? options,
]) async {
if (sender == null) throw TrackCreateException('could not restart track');
if (options != null && currentOptions.runtimeType != options.runtimeType) {
throw Exception('options must be a ${currentOptions.runtimeType}');
}
currentOptions = options ?? currentOptions;
// stop if not already stopped...
await stop();
// create new track with options
final newStream = await LocalTrack.createStream(currentOptions);
final newTrack = newStream.getTracks().first;
// replace track on sender
try {
await sender?.replaceTrack(newTrack);
} catch (error) {
logger.severe('RTCRtpSender.replaceTrack() did throw $error');
}
// set new stream & track to this object
updateMediaStreamAndTrack(newStream, newTrack);
// mark as started
await start();
}