feat: add preferCurrentTab support for flutter web. (#305)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
@@ -119,7 +120,7 @@ abstract class LocalTrack extends Track {
|
|||||||
static Future<rtc.MediaStream> createStream(
|
static Future<rtc.MediaStream> createStream(
|
||||||
LocalTrackOptions options,
|
LocalTrackOptions options,
|
||||||
) async {
|
) async {
|
||||||
final constraints = <String, dynamic>{
|
var constraints = <String, dynamic>{
|
||||||
'audio': options is AudioCaptureOptions
|
'audio': options is AudioCaptureOptions
|
||||||
? options.toMediaConstraintsMap()
|
? options.toMediaConstraintsMap()
|
||||||
: options is ScreenShareCaptureOptions
|
: options is ScreenShareCaptureOptions
|
||||||
@@ -132,6 +133,14 @@ abstract class LocalTrack extends Track {
|
|||||||
|
|
||||||
final rtc.MediaStream stream;
|
final rtc.MediaStream stream;
|
||||||
if (options is ScreenShareCaptureOptions) {
|
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);
|
stream = await rtc.navigator.mediaDevices.getDisplayMedia(constraints);
|
||||||
} else {
|
} else {
|
||||||
// options is CameraVideoTrackOptions
|
// options is CameraVideoTrackOptions
|
||||||
|
|||||||
@@ -84,11 +84,21 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions {
|
|||||||
/// See instructions on how to setup your Broadcast Extension here:
|
/// 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
|
/// https://github.com/flutter-webrtc/flutter-webrtc/wiki/iOS-Screen-Sharing#broadcast-extension-quick-setup
|
||||||
final bool useiOSBroadcastExtension;
|
final bool useiOSBroadcastExtension;
|
||||||
|
|
||||||
|
// for browser only, if true, will capture screen audio.
|
||||||
final bool captureScreenAudio;
|
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({
|
const ScreenShareCaptureOptions({
|
||||||
this.useiOSBroadcastExtension = false,
|
this.useiOSBroadcastExtension = false,
|
||||||
this.captureScreenAudio = false,
|
this.captureScreenAudio = false,
|
||||||
|
this.preferCurrentTab = true,
|
||||||
|
this.selfBrowserSurface,
|
||||||
String? sourceId,
|
String? sourceId,
|
||||||
double? maxFrameRate,
|
double? maxFrameRate,
|
||||||
VideoParameters params = VideoParametersPresets.screenShareH1080FPS15,
|
VideoParameters params = VideoParametersPresets.screenShareH1080FPS15,
|
||||||
@@ -97,6 +107,8 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions {
|
|||||||
ScreenShareCaptureOptions.from(
|
ScreenShareCaptureOptions.from(
|
||||||
{this.useiOSBroadcastExtension = false,
|
{this.useiOSBroadcastExtension = false,
|
||||||
this.captureScreenAudio = false,
|
this.captureScreenAudio = false,
|
||||||
|
this.preferCurrentTab = true,
|
||||||
|
this.selfBrowserSurface,
|
||||||
required VideoCaptureOptions captureOptions})
|
required VideoCaptureOptions captureOptions})
|
||||||
: super(params: captureOptions.params);
|
: super(params: captureOptions.params);
|
||||||
|
|
||||||
@@ -105,12 +117,16 @@ class ScreenShareCaptureOptions extends VideoCaptureOptions {
|
|||||||
VideoParameters? params,
|
VideoParameters? params,
|
||||||
String? sourceId,
|
String? sourceId,
|
||||||
double? maxFrameRate,
|
double? maxFrameRate,
|
||||||
|
bool? preferCurrentTab,
|
||||||
|
String? selfBrowserSurface,
|
||||||
}) =>
|
}) =>
|
||||||
ScreenShareCaptureOptions(
|
ScreenShareCaptureOptions(
|
||||||
captureScreenAudio: captureScreenAudio ?? this.captureScreenAudio,
|
captureScreenAudio: captureScreenAudio ?? this.captureScreenAudio,
|
||||||
params: params ?? this.params,
|
params: params ?? this.params,
|
||||||
sourceId: sourceId ?? deviceId,
|
sourceId: sourceId ?? deviceId,
|
||||||
maxFrameRate: maxFrameRate ?? this.maxFrameRate,
|
maxFrameRate: maxFrameRate ?? this.maxFrameRate,
|
||||||
|
preferCurrentTab: preferCurrentTab ?? this.preferCurrentTab,
|
||||||
|
selfBrowserSurface: selfBrowserSurface ?? this.selfBrowserSurface,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user