toggleScreenShare method
Toggles local screen-sharing stream on and off.
Implementation
Future<void> toggleScreenShare(BuildContext context) async {
if (PlatformUtils.isMobile) {
keepUi();
}
final LocalTrackState state = _currentCall.value.screenShareState.value;
if (state == LocalTrackState.enabled || state == LocalTrackState.enabling) {
await _currentCall.value.setScreenShareEnabled(false);
} else {
// TODO: `medea_jason` should have `onScreenChange` callback.
await _currentCall.value.enumerateDevices(media: false);
if (_currentCall.value.displays.length > 1) {
final MediaDisplayDetails? display = await ScreenShareView.show(
router.context!,
_currentCall,
);
if (display != null) {
await _currentCall.value.setScreenShareEnabled(true, device: display);
}
} else {
await _currentCall.value.setScreenShareEnabled(true);
}
}
}