feat: add preferCurrentTab support for flutter web. (#305)
This commit is contained in:
@@ -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<rtc.MediaStream> createStream(
|
||||
LocalTrackOptions options,
|
||||
) async {
|
||||
final constraints = <String, dynamic>{
|
||||
var constraints = <String, dynamic>{
|
||||
'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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user