createScreenShareTracksWithAudio static method

Future<List<LocalTrack>> createScreenShareTracksWithAudio(
  1. [ScreenShareCaptureOptions? options]
)

Creates a LocalTracks(audio/video) from the display.

The current API is mainly used to capture audio when chrome captures tab, but in the future it can also be used for flutter native to open audio capture device when capturing screen

Implementation

static Future<List<LocalTrack>> createScreenShareTracksWithAudio([
  ScreenShareCaptureOptions? options,
]) async {
  if (options == null) {
    options = const ScreenShareCaptureOptions(captureScreenAudio: true);
  } else {
    options = options.copyWith(captureScreenAudio: true);
  }
  final stream = await LocalTrack.createStream(options);

  List<LocalTrack> tracks = [
    LocalVideoTrack._(
      TrackSource.screenShareVideo,
      stream,
      stream.getVideoTracks().first,
      options,
    )
  ];

  if (stream.getAudioTracks().isNotEmpty) {
    tracks.add(LocalAudioTrack(TrackSource.screenShareAudio, stream,
        stream.getAudioTracks().first, const AudioCaptureOptions()));
  }
  return tracks;
}