shareScreen function

Future<void> shareScreen({
  1. required SessionController sessionController,
})

Implementation

Future<void> shareScreen({required SessionController sessionController}) async {
  sessionController.value = sessionController.value.copyWith(
      turnOnScreenSharing: !(sessionController.value.turnOnScreenSharing));

  if (sessionController.value.turnOnScreenSharing) {
    await sessionController.value.engine?.startScreenCapture(
      const ScreenCaptureParameters2(
        captureAudio: false,
        audioParams: ScreenAudioParameters(
          sampleRate: 16000,
          channels: 2,
          captureSignalVolume: 100,
        ),
        captureVideo: true,
        videoParams: ScreenVideoParameters(
          dimensions: VideoDimensions(height: 1280, width: 720),
          frameRate: 15,
          bitrate: 600,
        ),
      ),
    );
    await _showRPSystemBroadcastPickerViewIfNeed();
  } else {
    await sessionController.value.engine?.stopScreenCapture();
  }

  // Update channel media options to publish camera or screen capture streams
  ChannelMediaOptions options = ChannelMediaOptions(
    publishCameraTrack: !(sessionController.value.isScreenShared),
    publishMicrophoneTrack: !(sessionController.value.isScreenShared),
    publishScreenTrack: sessionController.value.isScreenShared,
    publishScreenCaptureAudio: sessionController.value.isScreenShared,
    publishScreenCaptureVideo: sessionController.value.isScreenShared,
    clientRoleType: ClientRoleType.clientRoleBroadcaster,
  );

  await sessionController.value.engine?.updateChannelMediaOptions(options);
}