diff --git a/lib/src/track/local/local.dart b/lib/src/track/local/local.dart index 69387b97..f735b60d 100644 --- a/lib/src/track/local/local.dart +++ b/lib/src/track/local/local.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; @@ -119,7 +120,7 @@ abstract class LocalTrack extends Track { static Future createStream( LocalTrackOptions options, ) async { - final constraints = { + var constraints = { 'audio': options is AudioCaptureOptions ? options.toMediaConstraintsMap() : options is ScreenShareCaptureOptions @@ -132,6 +133,14 @@ abstract class LocalTrack extends Track { final rtc.MediaStream stream; if (options is ScreenShareCaptureOptions) { + if (kIsWeb) { + if (options.preferCurrentTab) { + constraints['preferCurrentTab'] = true; + } + if (options.selfBrowserSurface != null) { + constraints['selfBrowserSurface'] = options.selfBrowserSurface!; + } + } stream = await rtc.navigator.mediaDevices.getDisplayMedia(constraints); } else { // options is CameraVideoTrackOptions diff --git a/lib/src/track/options.dart b/lib/src/track/options.dart index 2eb93842..cb5c02f3 100644 --- a/lib/src/track/options.dart +++ b/lib/src/track/options.dart @@ -84,11 +84,21 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions { /// See instructions on how to setup your Broadcast Extension here: /// https://github.com/flutter-webrtc/flutter-webrtc/wiki/iOS-Screen-Sharing#broadcast-extension-quick-setup final bool useiOSBroadcastExtension; + + // for browser only, if true, will capture screen audio. final bool captureScreenAudio; + /// for browser only, if true, will capture current tab. + final bool preferCurrentTab; + + /// for browser only, include or exclude self browser surface. + final String? selfBrowserSurface; + const ScreenShareCaptureOptions({ this.useiOSBroadcastExtension = false, this.captureScreenAudio = false, + this.preferCurrentTab = true, + this.selfBrowserSurface, String? sourceId, double? maxFrameRate, VideoParameters params = VideoParametersPresets.screenShareH1080FPS15, @@ -97,6 +107,8 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions { ScreenShareCaptureOptions.from( {this.useiOSBroadcastExtension = false, this.captureScreenAudio = false, + this.preferCurrentTab = true, + this.selfBrowserSurface, required VideoCaptureOptions captureOptions}) : super(params: captureOptions.params); @@ -105,12 +117,16 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions { VideoParameters? params, String? sourceId, double? maxFrameRate, + bool? preferCurrentTab, + String? selfBrowserSurface, }) => ScreenShareCaptureOptions( captureScreenAudio: captureScreenAudio ?? this.captureScreenAudio, params: params ?? this.params, sourceId: sourceId ?? deviceId, maxFrameRate: maxFrameRate ?? this.maxFrameRate, + preferCurrentTab: preferCurrentTab ?? this.preferCurrentTab, + selfBrowserSurface: selfBrowserSurface ?? this.selfBrowserSurface, ); @override