Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added android methods for zoom support #1811

Merged
merged 11 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ library;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_cross_button.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:provider/provider.dart';

///Project imports
Expand Down Expand Up @@ -51,7 +52,10 @@ class _LocalPeerBottomSheetState extends State<LocalPeerBottomSheet> {
@override
Widget build(BuildContext context) {
return FractionallySizedBox(
heightFactor: widget.isInsetTile ? 0.26 : 0.2,
heightFactor:
(AppDebugConfig.isDebugMode && widget.meetingStore.isVideoOn)
? (widget.isInsetTile ? 0.46 : 0.4)
: (widget.isInsetTile ? 0.26 : 0.2),
child: Padding(
padding: const EdgeInsets.only(top: 16.0, left: 24, right: 24),
child: Column(
Expand Down Expand Up @@ -228,6 +232,53 @@ class _LocalPeerBottomSheetState extends State<LocalPeerBottomSheet> {
widget.meetingStore.peerTracks.length > 1
? HMSThemeColors.onSurfaceHighEmphasis
: HMSThemeColors.onSurfaceLowEmphasis)),
if (AppDebugConfig.isDebugMode &&
widget.meetingStore.isVideoOn)
ListTile(
horizontalTitleGap: 2,
onTap: () async {
Navigator.pop(context);
bool isZoomSupported =
await HMSCameraControls.isZoomSupported();
if (isZoomSupported) {
HMSCameraControls.setZoom(zoomValue: 2);
}
},
contentPadding: EdgeInsets.zero,
leading: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/maximize.svg",
semanticsLabel: "fl_local_pin_tile",
height: 20,
width: 20,
colorFilter: ColorFilter.mode(
HMSThemeColors.onSurfaceHighEmphasis,
BlendMode.srcIn),
),
title: HMSSubheadingText(
text: "Zoom In (2x)",
textColor: HMSThemeColors.onSurfaceHighEmphasis)),

if (AppDebugConfig.isDebugMode &&
widget.meetingStore.isVideoOn)
ListTile(
horizontalTitleGap: 2,
onTap: () async {
Navigator.pop(context);
HMSCameraControls.resetZoom();
},
contentPadding: EdgeInsets.zero,
leading: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/minimize.svg",
semanticsLabel: "fl_local_pin_tile",
height: 20,
width: 20,
colorFilter: ColorFilter.mode(
HMSThemeColors.onSurfaceHighEmphasis,
BlendMode.srcIn),
),
title: HMSSubheadingText(
text: "Reset zoom",
textColor: HMSThemeColors.onSurfaceHighEmphasis)),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class HmssdkFlutterPlugin :
"capture_snapshot" -> {
captureSnapshot(call, result)
}
"is_tap_to_focus_supported", "capture_image_at_max_supported_resolution", "is_zoom_supported", "is_flash_supported", "toggle_flash" -> {
"is_tap_to_focus_supported", "capture_image_at_max_supported_resolution", "is_zoom_supported", "is_flash_supported", "toggle_flash", "set_zoom", "reset_zoom", "get_max_zoom", "get_min_zoom" -> {
HMSCameraControlsAction.cameraControlsAction(call, result, hmssdk!!, activity.applicationContext)
}
"get_session_metadata_for_key", "set_session_metadata_for_key" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class HMSCameraControlsAction {
"capture_image_at_max_supported_resolution" -> captureImageAtMaxSupportedResolution(call, result, hmssdk, context)
"is_flash_supported" -> isFlashSupported(result, hmssdk)
"toggle_flash" -> toggleFlash(result, hmssdk)
"set_zoom" -> setZoom(call, result, hmssdk)
"reset_zoom" -> resetZoom(result, hmssdk)
"get_max_zoom" -> getMaxZoom(result, hmssdk)
"get_min_zoom" -> getMinZoom(result, hmssdk)
else -> {
result.notImplemented()
}
Expand Down Expand Up @@ -54,7 +58,7 @@ class HMSCameraControlsAction {
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.let { cameraControl ->
HMSResultExtension.toDictionary(true, cameraControl.isZoomSupported())
result.success(HMSResultExtension.toDictionary(true, cameraControl.isZoomSupported()))
return
}
}
Expand Down Expand Up @@ -206,5 +210,97 @@ class HMSCameraControlsAction {
return
}
}

private fun setZoom(
call: MethodCall,
result: Result,
hmssdk: HMSSDK
){
val zoomValue = call.argument<Double>("zoom_value")
zoomValue?.let { _zoomValue ->
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.setZoom(
_zoomValue.toFloat()
)
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local video track is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local peer is null")))
return
}
}?:run{
HMSErrorLogger.returnArgumentsError("zoom value parameter is null in setZoom method")
return
}
}

private fun resetZoom(
result: Result,
hmssdk: HMSSDK,
){
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.resetZoom() ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("cameraControl is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local video track is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local peer is null")))
return
}
}

private fun getMinZoom(
result: Result,
hmssdk: HMSSDK,
){
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.let { cameraControl ->
result.success(HMSResultExtension.toDictionary(true, cameraControl.getMinZoom()))
return
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("cameraControl is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local video track is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local peer is null")))
return
}
}

private fun getMaxZoom(
result: Result,
hmssdk: HMSSDK,
){
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.let { cameraControl ->
result.success(HMSResultExtension.toDictionary(true, cameraControl.getMaxZoom()))
return
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("cameraControl is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local video track is null")))
return
}
} ?: run {
result.success(HMSResultExtension.toDictionary(false, HMSExceptionExtension.getError("local peer is null")))
return
}
}
}
}
7 changes: 2 additions & 5 deletions packages/hmssdk_flutter/example/ExampleAppChangelog.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
Board: https://app.devrev.ai/100ms/vistas/vista-250

- Change Role on Prebuilt
https://app.devrev.ai/100ms/works/ISS-22877

- Update DateTime parsing with `convertDateFromEpoch` in SDK
https://app.devrev.ai/100ms/works/ISS-22778
- Add support for zoom in camera controls
https://app.devrev.ai/100ms/works/ISS-23282

Room Kit: 1.1.6
Core SDK: 1.10.6
Expand Down
4 changes: 2 additions & 2 deletions packages/hmssdk_flutter/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "live.hms.flutter"
minSdkVersion 21
targetSdkVersion 34
versionCode 520
versionName "1.5.220"
versionCode 523
versionName "1.5.223"
}

signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion packages/hmssdk_flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ SPEC CHECKSUMS:
FirebaseRemoteConfigInterop: 6efda51fb5e2f15b16585197e26eaa09574e8a4d
FirebaseSessions: dbd14adac65ce996228652c1fc3a3f576bdf3ecc
FirebaseSharedSwift: 20530f495084b8d840f78a100d8c5ee613375f6e
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_foreground_task: 21ef182ab0a29a3005cc72cd70e5f45cb7f7f817
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
GoogleMLKit: 2bd0dc6253c4d4f227aad460f69215a504b2980e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = 100ms;
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions packages/hmssdk_flutter/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.220</string>
<string>1.5.223</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -48,7 +48,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>520</string>
<string>523</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ class HMSCameraControlsAction {

case "toggle_flash":
toggleFlash(result, hmsSDK)

case "set_zoom":
setZoom(call, result, hmsSDK)

case "reset_zoom":
resetZoom(result, hmsSDK)

// these method calls return FlutterMethodNotImplemented to indicate that the requested functionality is not yet implemented.
case "is_tap_to_focus_supported", "is_zoom_supported":
case "is_tap_to_focus_supported", "is_zoom_supported", "get_max_zoom", "get_min_zoom":
result(FlutterMethodNotImplemented)

// If the method call does not match any of the above cases, also return FlutterMethodNotImplemented.
Expand Down Expand Up @@ -170,4 +176,51 @@ class HMSCameraControlsAction {
formatter.timeStyle = .medium
return formatter.string(from: Date())
}

static private func setZoom(_ call: FlutterMethodCall, _ result: @escaping FlutterResult, _ hmsSDK: HMSSDK?){
guard let localPeer = hmsSDK?.localPeer else {
result(HMSResultExtension.toDictionary(false, HMSErrorExtension.getError("\(#function) An instance of Local Peer could not be found. Please check if a Room is joined.")))
return
}

guard let localVideoTrack = localPeer.localVideoTrack()
else {
result(HMSResultExtension.toDictionary(false, HMSErrorExtension.getError("\(#function) Video Track of Local Peer could not be found. Please check if the Local Peer has permission to publish video & video is unmuted currently.")))
return
}

let arguments = call.arguments as? [AnyHashable: Any]

guard let zoomValue = arguments?["zoom_value"] as? CGFloat
else{
HMSErrorLogger.returnArgumentsError("zoom value can't be empty")
return
}

localVideoTrack.modifyCaptureDevice { device in

guard let device = device else { return }

device.videoZoomFactor = zoomValue
}
}

static private func resetZoom(_ result: @escaping FlutterResult, _ hmsSDK: HMSSDK?){
guard let localPeer = hmsSDK?.localPeer else {
result(HMSResultExtension.toDictionary(false, HMSErrorExtension.getError("\(#function) An instance of Local Peer could not be found. Please check if a Room is joined.")))
return
}

guard let localVideoTrack = localPeer.localVideoTrack()
else {
result(HMSResultExtension.toDictionary(false, HMSErrorExtension.getError("\(#function) Video Track of Local Peer could not be found. Please check if the Local Peer has permission to publish video & video is unmuted currently.")))
return
}

localVideoTrack.modifyCaptureDevice { device in

guard let device = device else { return }
device.videoZoomFactor = 1.0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene

// MARK: - Advanced Camera Controls

case "capture_image_at_max_supported_resolution", "is_tap_to_focus_supported", "is_zoom_supported", "is_flash_supported", "toggle_flash":
case "capture_image_at_max_supported_resolution", "is_tap_to_focus_supported", "is_zoom_supported", "is_flash_supported", "toggle_flash", "set_zoom", "reset_zoom", "get_max_zoom", "get_min_zoom":
HMSCameraControlsAction.cameraControlsAction(call, result, hmsSDK)

// MARK: - Session Store
Expand Down
28 changes: 28 additions & 0 deletions packages/hmssdk_flutter/lib/src/common/platform_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,17 @@ enum PlatformMethod {
captureSnapshot,
getAllLogs,
getAuthTokenByRoomCode,

///Camera Controls
captureImageAtMaxSupportedResolution,
isFlashSupported,
toggleFlash,
isZoomSupported,
setZoom,
resetZoom,
getMaxZoom,
getMinZoom,

getSessionMetadataForKey,
setSessionMetadataForKey,
addKeyChangeListener,
Expand Down Expand Up @@ -494,6 +502,16 @@ extension PlatformMethodValues on PlatformMethod {
return "is_flash_supported";
case PlatformMethod.toggleFlash:
return "toggle_flash";
case PlatformMethod.isZoomSupported:
return "is_zoom_supported";
case PlatformMethod.setZoom:
return "set_zoom";
case PlatformMethod.resetZoom:
return "reset_zoom";
case PlatformMethod.getMaxZoom:
return "get_max_zoom";
case PlatformMethod.getMinZoom:
return "get_min_zoom";
case PlatformMethod.getSessionMetadataForKey:
return "get_session_metadata_for_key";
case PlatformMethod.setSessionMetadataForKey:
Expand Down Expand Up @@ -881,6 +899,16 @@ extension PlatformMethodValues on PlatformMethod {
return PlatformMethod.isFlashSupported;
case "toggle_flash":
return PlatformMethod.toggleFlash;
case "is_zoom_supported":
return PlatformMethod.isZoomSupported;
case "set_zoom":
return PlatformMethod.setZoom;
case "reset_zoom":
return PlatformMethod.resetZoom;
case "get_max_zoom":
return PlatformMethod.getMaxZoom;
case "get_min_zoom":
return PlatformMethod.getMinZoom;
case "get_session_metadata_for_key":
return PlatformMethod.getSessionMetadataForKey;
case "set_session_metadata_for_key":
Expand Down
Loading