i am build screen sharing using agora here is source code (base)
here is code for switch host
Future<void> _switchHostAndUpdateScreen() async {
if (isHost.value) {
// Switch to audience role
await engine!.setClientRole(role: ClientRoleType.clientRoleAudience);
engine!.enableLocalAudio(false);
engine!.enableLocalVideo(false);
engine!.disableVideo();
engine!.stopScreenCapture();
isHost.value = false;
} else {
// Switch to host role
await engine!.setClientRole(role: ClientRoleType.clientRoleBroadcaster);
if (isJoined.value) {
await engine!.enableAudio();
await engine!.startScreenCapture(const ScreenCaptureParameters2(captureAudio: true, captureVideo: true));
isHost.value = true;
await engine!.startPreview(sourceType: VideoSourceType.videoSourceScreen);
// Update channel media options
await _updateScreenShareChannelMediaOptions();
}
_updateScreenShareChannelMediaOptions();
}
setState(() {});
}
got update screen
Future<void> _updateScreenShareChannelMediaOptions() async {
final shareShareUid = int.tryParse(widget.localUidController);
sharingRemoteUid.value = shareShareUid ?? 0;
if (shareShareUid == null) return;
await engine!.updateChannelMediaOptionsEx(
options: ChannelMediaOptions(
publishScreenTrack: true,
publishSecondaryScreenTrack: true,
publishCameraTrack: false,
publishMicrophoneTrack: true,
publishScreenCaptureAudio: true,
publishScreenCaptureVideo: true,
autoSubscribeAudio: true,
publishMediaPlayerAudioTrack: true,
clientRoleType: isHost.value ? ClientRoleType.clientRoleBroadcaster : ClientRoleType.clientRoleAudience,
),
connection: RtcConnection(channelId: widget.channelId, localUid: shareShareUid),
);
}
now i i want to switch user then current host become audience and audience become host but new host screen is not visible even after allowing and start screen sharing
Thanks in advance