use setScreenShareEnabled for example

This commit is contained in:
Hiroshi Horie
2021-12-07 02:04:08 +07:00
parent d4a37dd720
commit 5ce12dae85
+31 -29
View File
@@ -85,42 +85,44 @@ class _ControlsWidgetState extends State<ControlsWidget> {
} }
void _enableScreenShare() async { void _enableScreenShare() async {
final lp = widget.room.localParticipant; await participant.setScreenShareEnabled(true);
// final lp = widget.room.localParticipant;
for (final track in lp.videoTracks) { // for (final track in lp.videoTracks) {
await lp.unpublishTrack(track.sid); // await lp.unpublishTrack(track.sid);
} // }
try { // try {
// Required for android screenshare. // // Required for android screenshare.
const androidConfig = FlutterBackgroundAndroidConfig( // const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Screen Sharing', // notificationTitle: 'Screen Sharing',
notificationText: 'LiveKit Example is sharing the screen.', // notificationText: 'LiveKit Example is sharing the screen.',
notificationImportance: AndroidNotificationImportance.Default, // notificationImportance: AndroidNotificationImportance.Default,
notificationIcon: // notificationIcon:
AndroidResource(name: 'livekit_ic_launcher', defType: 'mipmap'), // AndroidResource(name: 'livekit_ic_launcher', defType: 'mipmap'),
); // );
await FlutterBackground.initialize(androidConfig: androidConfig); // await FlutterBackground.initialize(androidConfig: androidConfig);
await FlutterBackground.enableBackgroundExecution(); // await FlutterBackground.enableBackgroundExecution();
final screenShareTrack = await LocalVideoTrack.createScreenShareTrack(); // final screenShareTrack = await LocalVideoTrack.createScreenShareTrack();
await widget.room.localParticipant.publishVideoTrack( // await widget.room.localParticipant.publishVideoTrack(
screenShareTrack, // screenShareTrack,
); // );
} catch (e) { // } catch (e) {
print('could not publish video: $e'); // print('could not publish video: $e');
} // }
} }
void _disableScreenShare() async { void _disableScreenShare() async {
final lp = widget.room.localParticipant; await participant.setScreenShareEnabled(false);
// final lp = widget.room.localParticipant;
try { // try {
await lp.setScreenShareEnabled(false); // await lp.setScreenShareEnabled(false);
await FlutterBackground.disableBackgroundExecution(); // await FlutterBackground.disableBackgroundExecution();
} catch (e) { // } catch (e) {
print('error disabling screen share: $e'); // print('error disabling screen share: $e');
} // }
} }
void _onTapDisconnect() async { void _onTapDisconnect() async {