Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example] Pick some example changes that help internal testing #2013

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions example/lib/examples/advanced/screen_sharing/screen_sharing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ScreenSharing extends StatefulWidget {
class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
late final RtcEngineEx _engine;
bool _isReadyPreview = false;
bool _isStartedPreview = false;
String channelId = config.channelId;
bool isJoined = false;
late TextEditingController _controller;
Expand Down Expand Up @@ -99,8 +100,9 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
_engine.registerEventHandler(_rtcEngineEventHandler);

await _engine.enableVideo();
await _engine.startPreview();
await _engine.setClientRole(role: ClientRoleType.clientRoleBroadcaster);
await _engine
.setScreenCaptureScenario(ScreenScenarioType.screenScenarioGaming);

setState(() {
_isReadyPreview = true;
Expand Down Expand Up @@ -170,7 +172,11 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
Widget build(BuildContext context) {
return ExampleActionsWidget(
displayContentBuilder: (context, isLayoutHorizontal) {
if (!_isReadyPreview) return Container();
if (!_isStartedPreview) {
return const Center(
child: Text('Press the "Start Preview" button to preview'),
);
}
final children = <Widget>[
Expanded(
flex: 1,
Expand All @@ -196,6 +202,7 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
canvas: const VideoCanvas(
uid: 0,
sourceType: VideoSourceType.videoSourceScreen,
renderMode: RenderModeType.renderModeFit,
),
))
: Container(
Expand Down Expand Up @@ -276,6 +283,35 @@ class _State extends State<ScreenSharing> with KeepRemoteVideoViewsMixin {
const SizedBox(
height: 20,
),
Row(
children: [
Expanded(
flex: 1,
child: ElevatedButton(
onPressed: () {
if (_isStartedPreview) {
_engine.stopPreview();
_engine.stopPreview(
sourceType: VideoSourceType.videoSourceScreen);
} else {
_engine.startPreview();
_engine.startPreview(
sourceType: VideoSourceType.videoSourceScreen);
}

setState(() {
_isStartedPreview = !_isStartedPreview;
});
},
child:
Text('${_isStartedPreview ? 'Stop' : 'Start'} Preview'),
),
)
],
),
const SizedBox(
height: 20,
),
Row(
children: [
Expanded(
Expand Down Expand Up @@ -385,7 +421,6 @@ class _ScreenShareWebState extends State<ScreenShareWeb>

await rtcEngine.startScreenCapture(
const ScreenCaptureParameters2(captureAudio: true, captureVideo: true));
await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen);
onStartScreenShared();
}

Expand Down Expand Up @@ -458,7 +493,6 @@ class _ScreenShareMobileState extends State<ScreenShareMobile>

await rtcEngine.startScreenCapture(
const ScreenCaptureParameters2(captureAudio: true, captureVideo: true));
await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen);
_showRPSystemBroadcastPickerViewIfNeed();
onStartScreenShared();
}
Expand Down Expand Up @@ -504,6 +538,8 @@ class _ScreenShareDesktopState extends State<ScreenShareDesktop>
List<ScreenCaptureSourceInfo> _screenCaptureSourceInfos = [];
late ScreenCaptureSourceInfo _selectedScreenCaptureSourceInfo;

late final TextEditingController _screenShareFrameRateController;

@override
bool get isScreenShared => widget.isScreenShared;

Expand Down Expand Up @@ -588,6 +624,8 @@ class _ScreenShareDesktopState extends State<ScreenShareDesktop>
void initState() {
super.initState();

_screenShareFrameRateController = TextEditingController(text: '30');

_initScreenCaptureSourceInfos();
}

Expand All @@ -598,6 +636,14 @@ class _ScreenShareDesktopState extends State<ScreenShareDesktop>
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: _screenShareFrameRateController,
decoration:
const InputDecoration(hintText: 'Screen Sharing frame rate'),
),
const SizedBox(
height: 20,
),
_createDropdownButton(),
if (_screenCaptureSourceInfos.isNotEmpty)
Row(
Expand Down Expand Up @@ -628,18 +674,18 @@ class _ScreenShareDesktopState extends State<ScreenShareDesktop>
await rtcEngine.startScreenCaptureByDisplayId(
displayId: sourceId!,
regionRect: const Rectangle(x: 0, y: 0, width: 0, height: 0),
captureParams: const ScreenCaptureParameters(
captureParams: ScreenCaptureParameters(
captureMouseCursor: true,
frameRate: 30,
frameRate: int.parse(_screenShareFrameRateController.text),
));
} else if (_selectedScreenCaptureSourceInfo.type ==
ScreenCaptureSourceType.screencapturesourcetypeWindow) {
await rtcEngine.startScreenCaptureByWindowId(
windowId: sourceId!,
regionRect: const Rectangle(x: 0, y: 0, width: 0, height: 0),
captureParams: const ScreenCaptureParameters(
captureParams: ScreenCaptureParameters(
captureMouseCursor: true,
frameRate: 30,
frameRate: int.parse(_screenShareFrameRateController.text),
),
);
}
Expand Down
Loading