Skip to content

Commit c0b8076

Browse files
authored
Prevent screen-sharing on flutter web mobile. (#486)
* Prevent screen-sharing on flutter web mobile. * import sorter.
1 parent 65b52e9 commit c0b8076

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

example/lib/widgets/controls.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ class _ControlsWidgetState extends State<ControlsWidget> {
197197
await participant.publishVideoTrack(track);
198198
return;
199199
}
200+
201+
if (lkPlatformIsWebMobile()) {
202+
await context
203+
.showErrorDialog('Screen share is not supported on mobile web');
204+
return;
205+
}
206+
200207
await participant.setScreenShareEnabled(true, captureScreenAudio: true);
201208
}
202209

lib/src/participant/local.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
537537
CameraCaptureOptions? cameraCaptureOptions,
538538
ScreenShareCaptureOptions? screenShareCaptureOptions}) async {
539539
logger.fine('setSourceEnabled(source: $source, enabled: $enabled)');
540+
541+
if (TrackSource.screenShareVideo == source && lkPlatformIsWebMobile()) {
542+
throw TrackCreateException(
543+
'Screen sharing is not supported on mobile devices');
544+
}
545+
540546
final publication = getTrackPublicationBySource(source);
541547
if (publication != null) {
542548
if (enabled) {

lib/src/support/platform.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ bool lkPlatformIs(PlatformType type) => lkPlatform() == type;
2424
bool lkPlatformIsMobile() =>
2525
[PlatformType.iOS, PlatformType.android].contains(lkPlatform());
2626

27+
bool lkPlatformIsWebMobile() => lkPlatformIsWebMobileImplementation();
28+
2729
bool lkPlatformIsDesktop() => [
2830
PlatformType.macOS,
2931
PlatformType.windows,

lib/src/support/platform/io.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PlatformType lkPlatformImplementation() {
2626
throw UnsupportedError('Unknown Platform');
2727
}
2828

29+
bool lkPlatformIsWebMobileImplementation() {
30+
return false;
31+
}
32+
2933
bool lkE2EESupportedImplementation() {
3034
return [
3135
PlatformType.windows,

lib/src/support/platform/web.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414

1515
import 'dart:js' as js;
1616

17+
import 'package:flutter/foundation.dart';
18+
1719
import 'package:platform_detect/platform_detect.dart';
1820

1921
import '../platform.dart';
2022

2123
PlatformType lkPlatformImplementation() => PlatformType.web;
2224

25+
bool lkPlatformIsWebMobileImplementation() {
26+
return (defaultTargetPlatform == TargetPlatform.iOS ||
27+
defaultTargetPlatform == TargetPlatform.android);
28+
}
29+
2330
bool lkE2EESupportedImplementation() {
2431
return isInsertableStreamSupported() || isScriptTransformSupported();
2532
}

lib/src/track/local/video.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:collection/collection.dart';
1818
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
1919

2020
import '../../events.dart';
21+
import '../../exceptions.dart';
2122
import '../../logger.dart';
2223
import '../../options.dart';
2324
import '../../proto/livekit_models.pb.dart' as lk_models;
@@ -187,6 +188,10 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
187188
static Future<LocalVideoTrack> createScreenShareTrack([
188189
ScreenShareCaptureOptions? options,
189190
]) async {
191+
if (lkPlatformIsWebMobile()) {
192+
throw TrackCreateException(
193+
'Screen sharing is not supported on mobile devices');
194+
}
190195
options ??= const ScreenShareCaptureOptions();
191196

192197
final stream = await LocalTrack.createStream(options);
@@ -206,6 +211,10 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
206211
static Future<List<LocalTrack>> createScreenShareTracksWithAudio([
207212
ScreenShareCaptureOptions? options,
208213
]) async {
214+
if (lkPlatformIsWebMobile()) {
215+
throw TrackCreateException(
216+
'Screen sharing is not supported on mobile devices');
217+
}
209218
if (options == null) {
210219
options = const ScreenShareCaptureOptions(captureScreenAudio: true);
211220
} else {

0 commit comments

Comments
 (0)