Skip to content

Commit

Permalink
feat: added android methods for zoom support
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Aug 26, 2024
1 parent 7abd2da commit ca03962
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
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 @@ -206,5 +210,98 @@ class HMSCameraControlsAction {
return
}
}

private fun setZoom(
call: MethodCall,
result: Result,
hmssdk: HMSSDK
){
val zoomValue = call.argument<Float>("zoom_value")
zoomValue?.let { _zoomValue ->
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.setZoom(_zoomValue) ?: 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 resetZoom(
result: Result,
hmssdk: HMSSDK,
){
hmssdk.getLocalPeer()?.let { localPeer ->
localPeer.videoTrack?.let { localVideoTrack ->
localVideoTrack.getCameraControl()?.let { cameraControl ->
result.success(HMSResultExtension.toDictionary(true, cameraControl.resetZoom()))
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 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
}
}
}
}
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
45 changes: 45 additions & 0 deletions packages/hmssdk_flutter/lib/src/model/hms_camera_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,49 @@ class HMSCameraControls {
return HMSException.fromMap(result["data"]["error"]);
}
}

static Future<bool> isZoomSupported() async {
var result = await PlatformService.invokeMethod(PlatformMethod.isZoomSupported);
if (result["success"]) {
return result["data"];
} else {
return false;
}
}

static Future<dynamic> setZoom() async {
var result = await PlatformService.invokeMethod(PlatformMethod.setZoom);
if (result["success"]) {
return result["data"];
} else {
return HMSException.fromMap(result["data"]["error"]);
}
}

static Future<dynamic> resetZoom() async {
var result = await PlatformService.invokeMethod(PlatformMethod.resetZoom);
if (result["success"]) {
return result["data"];
} else {
return HMSException.fromMap(result["data"]["error"]);
}
}

static Future<dynamic> getMinZoom() async {
var result = await PlatformService.invokeMethod(PlatformMethod.getMinZoom);
if (result["success"]) {
return result["data"];
} else {
return HMSException.fromMap(result["data"]["error"]);
}
}

static Future<dynamic> getMaxZoom() async {
var result = await PlatformService.invokeMethod(PlatformMethod.getMaxZoom);
if (result["success"]) {
return result["data"];
} else {
return HMSException.fromMap(result["data"]["error"]);
}
}
}

0 comments on commit ca03962

Please sign in to comment.