diff --git a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt index 04b750656..5a24a2619 100644 --- a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt +++ b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt @@ -51,15 +51,25 @@ class AgoraRtcEnginePlugin : FlutterPlugin, MethodCallHandler, EventChannel.Stre } } - private fun initPlugin(context: Context, binaryMessenger: BinaryMessenger, platformViewRegistry: PlatformViewRegistry) { + private fun initPlugin( + context: Context, + binaryMessenger: BinaryMessenger, + platformViewRegistry: PlatformViewRegistry + ) { applicationContext = context.applicationContext methodChannel = MethodChannel(binaryMessenger, "agora_rtc_engine") methodChannel.setMethodCallHandler(this) eventChannel = EventChannel(binaryMessenger, "agora_rtc_engine/events") eventChannel.setStreamHandler(this) - platformViewRegistry.registerViewFactory("AgoraSurfaceView", AgoraSurfaceViewFactory(binaryMessenger, this, rtcChannelPlugin)) - platformViewRegistry.registerViewFactory("AgoraTextureView", AgoraTextureViewFactory(binaryMessenger, this, rtcChannelPlugin)) + platformViewRegistry.registerViewFactory( + "AgoraSurfaceView", + AgoraSurfaceViewFactory(binaryMessenger, this, rtcChannelPlugin) + ) + platformViewRegistry.registerViewFactory( + "AgoraTextureView", + AgoraTextureViewFactory(binaryMessenger, this, rtcChannelPlugin) + ) } override fun onAttachedToEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { diff --git a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt index 9cfad10ed..b7302ade0 100644 --- a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt +++ b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt @@ -18,7 +18,14 @@ class AgoraSurfaceViewFactory( private val rtcChannelPlugin: AgoraRtcChannelPlugin ) : PlatformViewFactory(StandardMessageCodec.INSTANCE) { override fun create(context: Context, viewId: Int, args: Any?): PlatformView { - return AgoraSurfaceView(context.applicationContext, messenger, viewId, args as? Map<*, *>, rtcEnginePlugin, rtcChannelPlugin) + return AgoraSurfaceView( + context.applicationContext, + messenger, + viewId, + args as? Map<*, *>, + rtcEnginePlugin, + rtcChannelPlugin + ) } } @@ -56,17 +63,18 @@ class AgoraSurfaceView( this.javaClass.declaredMethods.find { it.name == call.method }?.let { function -> function.let { method -> val parameters = mutableListOf() - function.parameters.forEach { parameter -> - val map = call.arguments>() - if (map.containsKey(parameter.name)) { - parameters.add(map[parameter.name]) + call.arguments>()?.let { args -> + args.values.forEach { + parameters.add(it) } } try { method.invoke(this, *parameters.toTypedArray()) + result.success(null) return@onMethodCall } catch (e: Exception) { e.printStackTrace() + result.error(e.toString(), null, null) } } } diff --git a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt index 9bdb909e8..0e70f2913 100644 --- a/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt +++ b/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt @@ -18,7 +18,14 @@ class AgoraTextureViewFactory( private val rtcChannelPlugin: AgoraRtcChannelPlugin ) : PlatformViewFactory(StandardMessageCodec.INSTANCE) { override fun create(context: Context, viewId: Int, args: Any?): PlatformView { - return AgoraTextureView(context.applicationContext, messenger, viewId, args as? Map<*, *>, rtcEnginePlugin, rtcChannelPlugin) + return AgoraTextureView( + context.applicationContext, + messenger, + viewId, + args as? Map<*, *>, + rtcEnginePlugin, + rtcChannelPlugin + ) } } @@ -54,17 +61,18 @@ class AgoraTextureView( this.javaClass.declaredMethods.find { it.name == call.method }?.let { function -> function.let { method -> val parameters = mutableListOf() - function.parameters.forEach { parameter -> - val map = call.arguments>() - if (map.containsKey(parameter.name)) { - parameters.add(map[parameter.name]) + call.arguments>()?.let { args -> + args.values.forEach { + parameters.add(it) } } try { method.invoke(this, *parameters.toTypedArray()) + result.success(null) return@onMethodCall } catch (e: Exception) { e.printStackTrace() + result.error(e.toString(), null, null) } } } diff --git a/example/linux/flutter/generated_plugin_registrant.cc b/example/linux/flutter/generated_plugin_registrant.cc index cc90d98d5..d38195aa0 100644 --- a/example/linux/flutter/generated_plugin_registrant.cc +++ b/example/linux/flutter/generated_plugin_registrant.cc @@ -4,10 +4,6 @@ #include "generated_plugin_registrant.h" -#include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) agora_rtc_engine_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "AgoraRtcEnginePlugin"); - agora_rtc_engine_plugin_register_with_registrar(agora_rtc_engine_registrar); } diff --git a/example/linux/flutter/generated_plugins.cmake b/example/linux/flutter/generated_plugins.cmake index e67a0de8c..51436ae8c 100644 --- a/example/linux/flutter/generated_plugins.cmake +++ b/example/linux/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - agora_rtc_engine ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index aaa660f41..cccf817a5 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,6 @@ import FlutterMacOS import Foundation -import agora_rtc_engine func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - AgoraRtcEnginePlugin.register(with: registry.registrar(forPlugin: "AgoraRtcEnginePlugin")) } diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 4085c18bc..4bfa0f3a3 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -4,9 +4,6 @@ #include "generated_plugin_registrant.h" -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - AgoraRtcEnginePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("AgoraRtcEnginePlugin")); } diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake index bee76c9f8..4d10c2518 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/example/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - agora_rtc_engine ) set(PLUGIN_BUNDLED_LIBRARIES)