Skip to content

Commit

Permalink
feat: add preferCurrentTab support for flutter web. (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Jun 16, 2023
1 parent 0478172 commit 2844648
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/track/local/local.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions lib/src/track/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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
Expand Down

0 comments on commit 2844648

Please sign in to comment.