Skip to content

Commit

Permalink
fix: function.parameters may cause error
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed May 19, 2021
1 parent af92b84 commit 927f8d6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

Expand Down Expand Up @@ -56,17 +63,18 @@ class AgoraSurfaceView(
this.javaClass.declaredMethods.find { it.name == call.method }?.let { function ->
function.let { method ->
val parameters = mutableListOf<Any?>()
function.parameters.forEach { parameter ->
val map = call.arguments<Map<*, *>>()
if (map.containsKey(parameter.name)) {
parameters.add(map[parameter.name])
call.arguments<Map<*, *>>()?.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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

Expand Down Expand Up @@ -54,17 +61,18 @@ class AgoraTextureView(
this.javaClass.declaredMethods.find { it.name == call.method }?.let { function ->
function.let { method ->
val parameters = mutableListOf<Any?>()
function.parameters.forEach { parameter ->
val map = call.arguments<Map<*, *>>()
if (map.containsKey(parameter.name)) {
parameters.add(map[parameter.name])
call.arguments<Map<*, *>>()?.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)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

#include "generated_plugin_registrant.h"

#include <agora_rtc_engine/agora_rtc_engine_plugin.h>

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);
}
1 change: 0 additions & 1 deletion example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
agora_rtc_engine
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
2 changes: 0 additions & 2 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import FlutterMacOS
import Foundation

import agora_rtc_engine

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AgoraRtcEnginePlugin.register(with: registry.registrar(forPlugin: "AgoraRtcEnginePlugin"))
}
3 changes: 0 additions & 3 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

#include "generated_plugin_registrant.h"

#include <agora_rtc_engine/agora_rtc_engine_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AgoraRtcEnginePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AgoraRtcEnginePlugin"));
}
1 change: 0 additions & 1 deletion example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
agora_rtc_engine
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down

0 comments on commit 927f8d6

Please sign in to comment.