fixed some enum types mapping in parent toMap methods, added getCameraCaptureState, setCameraCaptureState, getMicrophoneCaptureState, setMicrophoneCaptureState WebView controller methods for iOS

This commit is contained in:
Lorenzo Pichilli 2022-05-02 00:18:55 +02:00
parent fef47e7930
commit 060fb00368
9 changed files with 149 additions and 8 deletions

View File

@ -2,7 +2,7 @@
- Deprecated old classes/properties/methods to make them eventually compatible with other Platforms and WebView engines.
- Added Web support
- Added `pauseAllMediaPlayback`, `setAllMediaPlaybackSuspended`, `closeAllMediaPresentations`, `requestMediaPlaybackState`, `isInFullscreen` WebView controller methods
- Added `pauseAllMediaPlayback`, `setAllMediaPlaybackSuspended`, `closeAllMediaPresentations`, `requestMediaPlaybackState`, `isInFullscreen`, `getCameraCaptureState`, `setCameraCaptureState`, `getMicrophoneCaptureState`, `setMicrophoneCaptureState` WebView controller methods
- Added `underPageBackgroundColor`, `isTextInteractionEnabled`, `isSiteSpecificQuirksModeEnabled`, `upgradeKnownHostsToHTTPS` WebView settings
- Added support for `onPermissionRequest` event on iOS 15.0+
- Updated `getMetaThemeColor` on iOS 15.0+

View File

@ -114,7 +114,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
InAppWebView(
key: webViewKey,
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
URLRequest(url: Uri.parse('https://www.onlinemictest.com/')),
// initialUrlRequest:
// URLRequest(url: Uri.parse(Uri.base.toString().replaceFirst("/#/", "/") + 'page.html')),
// initialFile: "assets/index.html",

View File

@ -603,6 +603,40 @@ public class InAppWebViewMethodHandler: FlutterMethodCallDelegate {
result(false)
}
break
case "getCameraCaptureState":
if let webView = webView, #available(iOS 15.0, *) {
result(webView.cameraCaptureState.rawValue)
} else {
result(nil)
}
break
case "setCameraCaptureState":
if let webView = webView, #available(iOS 15.0, *) {
let state = WKMediaCaptureState.init(rawValue: arguments!["state"] as! Int) ?? WKMediaCaptureState.none
webView.setCameraCaptureState(state) {
result(true)
}
} else {
result(false)
}
break
case "getMicrophoneCaptureState":
if let webView = webView, #available(iOS 15.0, *) {
result(webView.microphoneCaptureState.rawValue)
} else {
result(nil)
}
break
case "setMicrophoneCaptureState":
if let webView = webView, #available(iOS 15.0, *) {
let state = WKMediaCaptureState.init(rawValue: arguments!["state"] as! Int) ?? WKMediaCaptureState.none
webView.setMicrophoneCaptureState(state) {
result(true)
}
} else {
result(false)
}
break
default:
result(FlutterMethodNotImplemented)
break

View File

@ -3244,6 +3244,56 @@ class InAppWebViewController {
return await _channel.invokeMethod('isInFullscreen', args);
}
///Returns a [MediaCaptureState] that indicates whether the webpage is using the camera to capture images or video.
///
///**NOTE for iOS**: available on iOS 15.0+.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - WKWebView.cameraCaptureState](https://developer.apple.com/documentation/webkit/wkwebview/3763093-cameracapturestate)).
Future<MediaCaptureState?> getCameraCaptureState() async {
Map<String, dynamic> args = <String, dynamic>{};
return MediaCaptureState.fromValue(
await _channel.invokeMethod('getCameraCaptureState', args));
}
///Changes whether the webpage is using the camera to capture images or video.
///
///**NOTE for iOS**: available on iOS 15.0+.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - WKWebView.setCameraCaptureState](https://developer.apple.com/documentation/webkit/wkwebview/3763097-setcameracapturestate)).
Future<void> setCameraCaptureState(
{required MediaCaptureState state}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('state', () => state.toValue());
await _channel.invokeMethod('setCameraCaptureState', args);
}
///Returns a [MediaCaptureState] that indicates whether the webpage is using the microphone to capture audio.
///
///**NOTE for iOS**: available on iOS 15.0+.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - WKWebView.microphoneCaptureState](https://developer.apple.com/documentation/webkit/wkwebview/3763096-microphonecapturestate)).
Future<MediaCaptureState?> getMicrophoneCaptureState() async {
Map<String, dynamic> args = <String, dynamic>{};
return MediaCaptureState.fromValue(
await _channel.invokeMethod('getMicrophoneCaptureState', args));
}
///Changes whether the webpage is using the microphone to capture audio.
///
///**NOTE for iOS**: available on iOS 15.0+.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - WKWebView.setMicrophoneCaptureState](https://developer.apple.com/documentation/webkit/wkwebview/3763098-setmicrophonecapturestate)).
Future<void> setMicrophoneCaptureState(
{required MediaCaptureState state}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('state', () => state.toValue());
await _channel.invokeMethod('setMicrophoneCaptureState', args);
}
///Returns the iframe `id` attribute used on the Web platform.
///
///**Supported Platforms/Implementations**:

View File

@ -143,4 +143,5 @@ export 'webview_package_info.dart';
export 'webview_render_process_action.dart';
export 'window_features.dart';
export 'web_resource_error.dart';
export 'web_resource_error_type.dart';
export 'web_resource_error_type.dart';
export 'media_capture_state.dart';

View File

@ -0,0 +1,56 @@
///Class that describes whether a media device, like a camera or microphone, is currently capturing audio or video.
class MediaCaptureState {
final int _value;
const MediaCaptureState._internal(this._value);
///Set of all values of [MediaCaptureState].
static final Set<MediaCaptureState> values = [
MediaCaptureState.NONE,
MediaCaptureState.ACTIVE,
MediaCaptureState.MUTED,
].toSet();
///Gets a possible [MediaCaptureState] instance from an [int] value.
static MediaCaptureState? fromValue(int? value) {
if (value != null) {
try {
return MediaCaptureState.values
.firstWhere((element) => element.toValue() == value);
} catch (e) {
return null;
}
}
return null;
}
///Gets [int] value.
int toValue() => _value;
@override
String toString() {
switch (_value) {
case 1:
return "ACTIVE";
case 2:
return "MUTED";
case 0:
default:
return "NONE";
}
}
///The media device is off.
static const NONE = const MediaCaptureState._internal(0);
///The media device is actively capturing audio or video.
static const ACTIVE = const MediaCaptureState._internal(1);
///The media device is muted, and not actively capturing audio or video.
static const MUTED = const MediaCaptureState._internal(2);
bool operator ==(value) => value == _value;
@override
int get hashCode => _value.hashCode;
}

View File

@ -46,7 +46,7 @@ class PermissionRequest {
Map<String, dynamic> toMap() {
return {
"origin": origin.toString(),
"resources": resources.map((e) => e.toValue()).toList(),
"resources": resources.map((e) => e.toNativeValue()).toList(),
"frame": frame?.toMap()
};
}

View File

@ -18,7 +18,7 @@ class PermissionResponse {
///Converts instance to a map.
Map<String, dynamic> toMap() {
return {
"resources": resources.map((e) => e.toValue()).toList(),
"resources": resources.map((e) => e.toNativeValue()).toList(),
"action": action?.toValue()
};
}

View File

@ -47,11 +47,11 @@ class SslError {
Map<String, dynamic> toMap() {
return {
// ignore: deprecated_member_use_from_same_package
"androidError": code?.toValue() ?? androidError?.toValue(),
"androidError": code?.toNativeValue() ?? androidError?.toValue(),
// ignore: deprecated_member_use_from_same_package
"iosError": code?.toValue() ?? iosError?.toValue(),
"iosError": code?.toNativeValue() ?? iosError?.toValue(),
// ignore: deprecated_member_use_from_same_package
"code": code?.toValue() ?? androidError?.toValue() ?? iosError?.toValue(),
"code": code?.toNativeValue() ?? androidError?.toValue() ?? iosError?.toValue(),
"message": message,
};
}