Skip to content

Commit

Permalink
Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed May 23, 2024
1 parent 3099f11 commit a43d42e
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ library;
import 'package:badges/badges.dart' as badge;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/poll_and_quiz_bottom_sheet.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/video_effects_bottom_sheet.dart';
import 'package:hms_video_plugin/hms_video_plugin.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';

///Project imports
Expand All @@ -21,6 +17,8 @@ import 'package:hms_room_kit/src/widgets/bottom_sheets/overlay_participants_bott
import 'package:hms_room_kit/src/widgets/common_widgets/hms_cross_button.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_subheading_text.dart';
import 'package:hms_room_kit/src/widgets/tab_widgets/chat_participants_tab_bar.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/poll_and_quiz_bottom_sheet.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/video_effects_bottom_sheet.dart';

///This renders the app utilities bottom sheet for webRTC or broadcaster
///It contains the participants, screen share, brb, raise hand and recording
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class _VideoEffectsBottomSheetState extends State<VideoEffectsBottomSheet> {
HMSVideoPlugin.disable();
AppDebugConfig.isVBEnabled = false;
}
changeBlur(80);
changeBlur(100);
},
optionIcon: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/max_blur.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HmsVideoFilterPlugin: FlutterPlugin, MethodCallHandler {

override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
"enable_virtual_background", "disable_virtual_background", "enable_blur_background", "disable_blur_background", "change_virtual_background" -> {
"enable_virtual_background", "disable_virtual_background", "enable_blur_background", "disable_blur_background", "change_virtual_background", "is_virtual_background_supported" -> {
if(hmssdk == null){
Log.i("VKohli", "hmssdk flutter plugin NULL engine ${engine?.plugins?.has(HmssdkFlutterPlugin::class.java)}")
hmssdkFlutterPlugin = engine?.plugins?.get(HmssdkFlutterPlugin::class.java) as HmssdkFlutterPlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package live.hms.hms_video_plugin.extension
package live.hms.hms_video_plugin

class HMSResultExtension {
companion object {
fun toDictionary(
success: Boolean,
data: Any? = null,
): HashMap<String, Any?> {
val hashMap = HashMap<String, Any?>()
hashMap["success"] = success
hashMap["data"] = data
return hashMap
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class HMSVirtualBackgroundAction {
hmssdk: HMSSDK?,
){
when(call.method){
"is_virtual_background_supported" -> isSupported(result)
"enable_virtual_background" -> enable(call, result, hmssdk)
"disable_virtual_background" -> disable(result, hmssdk)
"enable_blur_background" -> enableBlur(call, result, hmssdk)
"disable_blur_background" -> disableBlur(result, hmssdk)
"change_virtual_background" -> changeVirtualBackground(call,result,hmssdk)
"change_virtual_background" -> changeVirtualBackground(call,result)
else -> result.notImplemented()
}
}
Expand All @@ -33,8 +34,8 @@ class HMSVirtualBackgroundAction {
*/
private var virtualBackgroundPlugin: HMSVirtualBackground? = null
private fun enable(call: MethodCall, result: Result, hmssdk: HMSSDK?){
val imageUint: ByteArray? = call.argument<ByteArray?>("image")
imageUint?.let { imageBitmap ->
val imageByteArray: ByteArray? = call.argument<ByteArray?>("image")
imageByteArray?.let { imageBitmap ->
val vbImage = BitmapFactory.decodeByteArray(imageBitmap, 0, imageBitmap.size)
hmssdk?.let {_hmssdk ->
virtualBackgroundPlugin = HMSVirtualBackground(_hmssdk, vbImage)
Expand All @@ -47,14 +48,15 @@ class HMSVirtualBackgroundAction {
}
}

private fun changeVirtualBackground(call: MethodCall, result: Result, hmssdk: HMSSDK?){
val imageUint: ByteArray? = call.argument<ByteArray?>("image")
imageUint?.let { imageBitmap ->
private fun changeVirtualBackground(call: MethodCall, result: Result){
val imageByteArray: ByteArray? = call.argument<ByteArray?>("image")
imageByteArray?.let { imageBitmap ->
val vbImage = BitmapFactory.decodeByteArray(imageBitmap, 0, imageBitmap.size)
virtualBackgroundPlugin?.setBackground(vbImage)
}?:run{
HMSErrorLogger.returnArgumentsError("image can't be null")
}
result.success(null)
}

private fun disable(result: Result, hmssdk: HMSSDK?){
Expand Down Expand Up @@ -100,5 +102,9 @@ class HMSVirtualBackgroundAction {
HMSErrorLogger.logError("disableBlur","hmssdk is null","NULL ERROR")
}
}

private fun isSupported(result: Result){
result.success(HMSResultExtension.toDictionary(true,virtualBackgroundPlugin?.isSupported()))
}
}
}
3 changes: 3 additions & 0 deletions packages/hms_video_plugin/lib/src/enum/plugin_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enum PluginMethod {
enableVirtualBackground,
disableVirtualBackground,
changeVirtualBackground,
isVirtualBackgroundSupported,
enableBlurBackground,
disableBlurBackground,
}
Expand All @@ -19,6 +20,8 @@ extension PlatformMethodValues on PluginMethod {
return "enable_blur_background";
case PluginMethod.disableBlurBackground:
return "disable_blur_background";
case PluginMethod.isVirtualBackgroundSupported:
return "is_virtual_background_supported";
}
}
}
61 changes: 52 additions & 9 deletions packages/hms_video_plugin/lib/src/hms_video_plugin_controller.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
library;

///Dart imports
import 'dart:io';

///Package imports
import 'package:flutter/foundation.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///Project imports
import 'package:hms_video_plugin/src/enum/plugin_method.dart';
import 'package:hms_video_plugin/src/platform_service.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///[HMSVideoPlugin] is the entry point for the plugin.
abstract class HMSVideoPlugin {
static Future<void> enable({required Uint8List? image}) async {
static Future<HMSException?> enable({required Uint8List? image}) async {
if (Platform.isAndroid) {
return PlatformService.invokeMethod(PluginMethod.enableVirtualBackground,
var result = await PlatformService.invokeMethod(
PluginMethod.enableVirtualBackground,
arguments: {"image": image});
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
} else {
return HMSVideoFilter.enable(image: image);
}
Expand All @@ -26,27 +38,58 @@ abstract class HMSVideoPlugin {
}
}

static Future<void> disable() async {
static Future<bool> isSupported() async {
if (Platform.isAndroid) {
var result = await PlatformService.invokeMethod(
PluginMethod.isVirtualBackgroundSupported);
if (result["success"]) {
return result["data"];
} else {
return false;
}
} else {
return HMSVideoFilter.isSupported();
}
}

static Future<HMSException?> disable() async {
if (Platform.isAndroid) {
return PlatformService.invokeMethod(
var result = await PlatformService.invokeMethod(
PluginMethod.disableVirtualBackground);
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
} else {
return HMSVideoFilter.disable();
}
}

static Future<void> enableBlur({required int blurRadius}) async {
static Future<HMSException?> enableBlur({required int blurRadius}) async {
if (Platform.isAndroid) {
return PlatformService.invokeMethod(PluginMethod.enableBlurBackground,
var result = await PlatformService.invokeMethod(
PluginMethod.enableBlurBackground,
arguments: {"blur_radius": blurRadius});
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
} else {
return HMSVideoFilter.enableBlur(blurRadius: blurRadius);
}
}

static Future<void> disableBlur() async {
static Future<HMSException?> disableBlur() async {
if (Platform.isAndroid) {
return PlatformService.invokeMethod(PluginMethod.disableBlurBackground);
var result = await PlatformService.invokeMethod(
PluginMethod.disableBlurBackground);
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
} else {
return HMSVideoFilter.disableBlur();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class HMSVirtualBackgroundAction{
disableBlurBackground(result)
case "change_virtual_background":
changeBackground(call, result)
case "is_virtual_background_supported":
isSupported(result)
default:
result(FlutterMethodNotImplemented)
}
Expand Down Expand Up @@ -110,4 +112,12 @@ class HMSVirtualBackgroundAction{
}
result(nil)
}

static func isSupported(_ result: @escaping FlutterResult){
if #available(iOS 15.0, *) {
result(HMSResultExtension.toDictionary(true,true))
}else {
result(HMSResultExtension.toDictionary(true,false))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene
case "start_whiteboard", "stop_whiteboard", "add_whiteboard_update_listener", "remove_whiteboard_update_listener":
whiteboardActions(call, result)

case "enable_virtual_background", "disable_virtual_background", "enable_blur_background", "disable_blur_background","change_virtual_background":
case "enable_virtual_background", "disable_virtual_background", "enable_blur_background", "disable_blur_background","change_virtual_background", "is_virtual_background_supported":
HMSVirtualBackgroundAction.virtualBackgroundActions(call, result)

default:
Expand Down
8 changes: 7 additions & 1 deletion packages/hmssdk_flutter/lib/src/common/platform_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ enum PlatformMethod {
disableVirtualBackground,
changeVirtualBackground,
enableBlurBackground,
disableBlurBackground
disableBlurBackground,
isVirtualBackgroundSupported
}

extension PlatformMethodValues on PlatformMethod {
Expand Down Expand Up @@ -622,6 +623,8 @@ extension PlatformMethodValues on PlatformMethod {
return "enable_blur_background";
case PlatformMethod.disableBlurBackground:
return "disable_blur_background";
case PlatformMethod.isVirtualBackgroundSupported:
return "is_virtual_background_supported";

default:
return 'unknown';
Expand Down Expand Up @@ -988,6 +991,7 @@ extension PlatformMethodValues on PlatformMethod {
case "remove_whiteboard_update_listener":
return PlatformMethod.removeWhiteboardUpdateListener;

///Virtual Background Methods
case "enable_virtual_background":
return PlatformMethod.enableVirtualBackground;
case "disable_virtual_background":
Expand All @@ -998,6 +1002,8 @@ extension PlatformMethodValues on PlatformMethod {
return PlatformMethod.enableBlurBackground;
case "disable_blur_background":
return PlatformMethod.disableBlurBackground;
case "is_virtual_background_supported":
return PlatformMethod.isVirtualBackgroundSupported;

default:
return PlatformMethod.unknown;
Expand Down
55 changes: 46 additions & 9 deletions packages/hmssdk_flutter/lib/src/model/hms_video_filter.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,72 @@
///Package imports

Check notice on line 1 in packages/hmssdk_flutter/lib/src/model/hms_video_filter.dart

View workflow job for this annotation

GitHub Actions / check_build

Dangling library doc comment.

Add a 'library' directive after the library comment. See https://dart.dev/lints/dangling_library_doc_comments to learn more about this problem.
import 'package:flutter/foundation.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///Project imports
import 'package:hmssdk_flutter/src/common/platform_methods.dart';
import 'package:hmssdk_flutter/src/service/platform_service.dart';

///[HMSVideoFilter] is used to apply video effects like virtual background and blur
abstract class HMSVideoFilter {
static Future<void> enable({required Uint8List? image}) async {
PlatformService.invokeMethod(PlatformMethod.enableVirtualBackground,
static Future<HMSException?> enable({required Uint8List? image}) async {
var result = await PlatformService.invokeMethod(
PlatformMethod.enableVirtualBackground,
arguments: {"image": image});

if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
}

static Future<void> changeVirtualBackground(
{required Uint8List? image}) async {
PlatformService.invokeMethod(PlatformMethod.changeVirtualBackground,
arguments: {"image": image});
return null;
}

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

static Future<void> disable() async {
PlatformService.invokeMethod(PlatformMethod.disableVirtualBackground);
static Future<HMSException?> disable() async {
var result = await PlatformService.invokeMethod(
PlatformMethod.disableVirtualBackground);

if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
}

static Future<void> enableBlur({required int blurRadius}) async {
static Future<HMSException?> enableBlur({required int blurRadius}) async {
assert(blurRadius >= 0 && blurRadius <= 100,
"blurRadius should be between 0 and 100, current value is $blurRadius");
PlatformService.invokeMethod(PlatformMethod.enableBlurBackground,
var result = await PlatformService.invokeMethod(
PlatformMethod.enableBlurBackground,
arguments: {"blur_radius": blurRadius});
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
}

static Future<void> disableBlur() async {
PlatformService.invokeMethod(PlatformMethod.disableBlurBackground);
static Future<HMSException?> disableBlur() async {
var result = await PlatformService.invokeMethod(
PlatformMethod.disableBlurBackground);
if (result != null) {
return HMSException.fromMap(result["error"]);
} else {
return null;
}
}
}

0 comments on commit a43d42e

Please sign in to comment.