From bfe83275be3c5179e332b5f997cc347fb9d2b8ec Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 28 Dec 2020 17:03:31 +0800 Subject: [PATCH 1/4] style: format with 2 spaces --- .../rtc/react/RCTAgoraRtcChannelModule.kt | 86 +++++++++--------- .../rtc/react/RCTAgoraRtcEngineModule.kt | 80 ++++++++--------- .../io/agora/rtc/react/RCTAgoraRtcPackage.kt | 32 +++---- .../react/RCTAgoraRtcSurfaceViewManager.kt | 86 +++++++++--------- .../react/RCTAgoraRtcTextureViewManager.kt | 90 +++++++++---------- 5 files changed, 187 insertions(+), 187 deletions(-) diff --git a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcChannelModule.kt b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcChannelModule.kt index 4996d4dd1..a2c8da43b 100644 --- a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcChannelModule.kt +++ b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcChannelModule.kt @@ -13,59 +13,59 @@ import kotlin.reflect.jvm.javaMethod @ReactModule(name = REACT_CLASS) class RCTAgoraRtcChannelModule( - reactContext: ReactApplicationContext + reactContext: ReactApplicationContext ) : ReactContextBaseJavaModule(reactContext) { - companion object { - const val REACT_CLASS = "RCTAgoraRtcChannelModule" - } + companion object { + const val REACT_CLASS = "RCTAgoraRtcChannelModule" + } - private val manager = RtcChannelManager { methodName, data -> emit(methodName, data) } + private val manager = RtcChannelManager { methodName, data -> emit(methodName, data) } - override fun getName(): String { - return REACT_CLASS - } + override fun getName(): String { + return REACT_CLASS + } - override fun getConstants(): MutableMap { - return mutableMapOf( - "prefix" to RtcChannelEventHandler.PREFIX - ) - } + override fun getConstants(): MutableMap { + return mutableMapOf( + "prefix" to RtcChannelEventHandler.PREFIX + ) + } - override fun onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy() - manager.release() - } + override fun onCatalystInstanceDestroy() { + super.onCatalystInstanceDestroy() + manager.release() + } - private fun emit(methodName: String, data: Map?) { - reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit("${RtcChannelEventHandler.PREFIX}$methodName", Arguments.makeNativeMap(data)) - } + private fun emit(methodName: String, data: Map?) { + reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit("${RtcChannelEventHandler.PREFIX}$methodName", Arguments.makeNativeMap(data)) + } - private fun engine(): RtcEngine? { - return reactApplicationContext.getNativeModule(RCTAgoraRtcEngineModule::class.java).engine() - } + private fun engine(): RtcEngine? { + return reactApplicationContext.getNativeModule(RCTAgoraRtcEngineModule::class.java).engine() + } - fun channel(channelId: String): RtcChannel? { - return manager[channelId] - } + fun channel(channelId: String): RtcChannel? { + return manager[channelId] + } - @ReactMethod - fun callMethod(methodName: String, params: ReadableMap?, callback: Promise?) { - manager::class.declaredMemberFunctions.find { it.name == methodName }?.let { function -> - function.javaMethod?.let { method -> - try { - val parameters = mutableListOf() - params?.toHashMap()?.toMutableMap()?.let { - if (methodName == "create") { - it["engine"] = engine() - } - parameters.add(it) - } - method.invoke(manager, *parameters.toTypedArray(), PromiseCallback(callback)) - } catch (e: Exception) { - e.printStackTrace() - } + @ReactMethod + fun callMethod(methodName: String, params: ReadableMap?, callback: Promise?) { + manager::class.declaredMemberFunctions.find { it.name == methodName }?.let { function -> + function.javaMethod?.let { method -> + try { + val parameters = mutableListOf() + params?.toHashMap()?.toMutableMap()?.let { + if (methodName == "create") { + it["engine"] = engine() } + parameters.add(it) + } + method.invoke(manager, *parameters.toTypedArray(), PromiseCallback(callback)) + } catch (e: Exception) { + e.printStackTrace() } + } } + } } diff --git a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcEngineModule.kt b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcEngineModule.kt index 6ac8d4a03..34bb84244 100644 --- a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcEngineModule.kt +++ b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcEngineModule.kt @@ -12,55 +12,55 @@ import kotlin.reflect.jvm.javaMethod @ReactModule(name = REACT_CLASS) class RCTAgoraRtcEngineModule( - reactContext: ReactApplicationContext + reactContext: ReactApplicationContext ) : ReactContextBaseJavaModule(reactContext) { - companion object { - const val REACT_CLASS = "RCTAgoraRtcEngineModule" - } + companion object { + const val REACT_CLASS = "RCTAgoraRtcEngineModule" + } - private val manager = RtcEngineManager { methodName, data -> emit(methodName, data) } + private val manager = RtcEngineManager { methodName, data -> emit(methodName, data) } - override fun getName(): String { - return REACT_CLASS - } + override fun getName(): String { + return REACT_CLASS + } - override fun getConstants(): MutableMap { - return mutableMapOf( - "prefix" to RtcEngineEventHandler.PREFIX - ) - } + override fun getConstants(): MutableMap { + return mutableMapOf( + "prefix" to RtcEngineEventHandler.PREFIX + ) + } - override fun onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy() - manager.release() - } + override fun onCatalystInstanceDestroy() { + super.onCatalystInstanceDestroy() + manager.release() + } - private fun emit(methodName: String, data: Map?) { - reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) - .emit("${RtcEngineEventHandler.PREFIX}$methodName", Arguments.makeNativeMap(data)) - } + private fun emit(methodName: String, data: Map?) { + reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) + .emit("${RtcEngineEventHandler.PREFIX}$methodName", Arguments.makeNativeMap(data)) + } - fun engine(): RtcEngine? { - return manager.engine - } + fun engine(): RtcEngine? { + return manager.engine + } - @ReactMethod - fun callMethod(methodName: String, params: ReadableMap?, callback: Promise?) { - manager::class.declaredMemberFunctions.find { it.name == methodName }?.let { function -> - function.javaMethod?.let { method -> - try { - val parameters = mutableListOf() - params?.toHashMap()?.toMutableMap()?.let { - if (methodName == "create") { - it["context"] = reactApplicationContext.applicationContext - } - parameters.add(it) - } - method.invoke(manager, *parameters.toTypedArray(), PromiseCallback(callback)) - } catch (e: Exception) { - e.printStackTrace() - } + @ReactMethod + fun callMethod(methodName: String, params: ReadableMap?, callback: Promise?) { + manager::class.declaredMemberFunctions.find { it.name == methodName }?.let { function -> + function.javaMethod?.let { method -> + try { + val parameters = mutableListOf() + params?.toHashMap()?.toMutableMap()?.let { + if (methodName == "create") { + it["context"] = reactApplicationContext.applicationContext } + parameters.add(it) + } + method.invoke(manager, *parameters.toTypedArray(), PromiseCallback(callback)) + } catch (e: Exception) { + e.printStackTrace() } + } } + } } diff --git a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcPackage.kt b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcPackage.kt index a0748ef30..66153008e 100644 --- a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcPackage.kt +++ b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcPackage.kt @@ -7,22 +7,22 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.ViewManager class RCTAgoraRtcPackage : ReactPackage { - override fun createNativeModules(reactContext: ReactApplicationContext): List { - return listOf( - RCTAgoraRtcEngineModule(reactContext), - RCTAgoraRtcChannelModule(reactContext) - ) - } + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return listOf( + RCTAgoraRtcEngineModule(reactContext), + RCTAgoraRtcChannelModule(reactContext) + ) + } - // Deprecated in RN 0.47 - fun createJSModules(): List> { - return emptyList() - } + // Deprecated in RN 0.47 + fun createJSModules(): List> { + return emptyList() + } - override fun createViewManagers(reactContext: ReactApplicationContext): List> { - return listOf( - RCTAgoraRtcSurfaceViewManager(), - RCTAgoraRtcTextureViewManager() - ) - } + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + return listOf( + RCTAgoraRtcSurfaceViewManager(), + RCTAgoraRtcTextureViewManager() + ) + } } diff --git a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcSurfaceViewManager.kt b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcSurfaceViewManager.kt index 9aaed148a..42506fbd0 100644 --- a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcSurfaceViewManager.kt +++ b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcSurfaceViewManager.kt @@ -9,59 +9,59 @@ import io.agora.rtc.RtcEngine import io.agora.rtc.base.RtcSurfaceView class RCTAgoraRtcSurfaceViewManager : SimpleViewManager() { - companion object { - const val REACT_CLASS = "RCTAgoraRtcSurfaceView" - } + companion object { + const val REACT_CLASS = "RCTAgoraRtcSurfaceView" + } - private var reactContext: ThemedReactContext? = null + private var reactContext: ThemedReactContext? = null - override fun createViewInstance(reactContext: ThemedReactContext): RtcSurfaceView { - this.reactContext = reactContext - return RtcSurfaceView(reactContext) - } + override fun createViewInstance(reactContext: ThemedReactContext): RtcSurfaceView { + this.reactContext = reactContext + return RtcSurfaceView(reactContext) + } - override fun onDropViewInstance(view: RtcSurfaceView) { - // getEngine()?.let { view.resetVideoCanvas(it) } - super.onDropViewInstance(view) - } + override fun onDropViewInstance(view: RtcSurfaceView) { + // getEngine()?.let { view.resetVideoCanvas(it) } + super.onDropViewInstance(view) + } - override fun getName(): String { - return REACT_CLASS - } + override fun getName(): String { + return REACT_CLASS + } - @ReactProp(name = "zOrderMediaOverlay") - fun setZOrderMediaOverlay(view: RtcSurfaceView, isMediaOverlay: Boolean) { - view.setZOrderMediaOverlay(isMediaOverlay) - } + @ReactProp(name = "zOrderMediaOverlay") + fun setZOrderMediaOverlay(view: RtcSurfaceView, isMediaOverlay: Boolean) { + view.setZOrderMediaOverlay(isMediaOverlay) + } - @ReactProp(name = "zOrderOnTop") - fun setZOrderOnTop(view: RtcSurfaceView, onTop: Boolean) { - view.setZOrderOnTop(onTop) - } + @ReactProp(name = "zOrderOnTop") + fun setZOrderOnTop(view: RtcSurfaceView, onTop: Boolean) { + view.setZOrderOnTop(onTop) + } - @ReactProp(name = "data") - fun setData(view: RtcSurfaceView, data: ReadableMap) { - data.toHashMap().let { map -> - val channel = (map["channelId"] as? String)?.let { getChannel(it) } - getEngine()?.let { view.setData(it, channel, (map["uid"] as Number).toInt()) } - } + @ReactProp(name = "data") + fun setData(view: RtcSurfaceView, data: ReadableMap) { + data.toHashMap().let { map -> + val channel = (map["channelId"] as? String)?.let { getChannel(it) } + getEngine()?.let { view.setData(it, channel, (map["uid"] as Number).toInt()) } } + } - @ReactProp(name = "renderMode") - fun setRenderMode(view: RtcSurfaceView, renderMode: Int) { - getEngine()?.let { view.setRenderMode(it, renderMode) } - } + @ReactProp(name = "renderMode") + fun setRenderMode(view: RtcSurfaceView, renderMode: Int) { + getEngine()?.let { view.setRenderMode(it, renderMode) } + } - @ReactProp(name = "mirrorMode") - fun setMirrorMode(view: RtcSurfaceView, mirrorMode: Int) { - getEngine()?.let { view.setMirrorMode(it, mirrorMode) } - } + @ReactProp(name = "mirrorMode") + fun setMirrorMode(view: RtcSurfaceView, mirrorMode: Int) { + getEngine()?.let { view.setMirrorMode(it, mirrorMode) } + } - private fun getEngine(): RtcEngine? { - return reactContext?.getNativeModule(RCTAgoraRtcEngineModule::class.java)?.engine() - } + private fun getEngine(): RtcEngine? { + return reactContext?.getNativeModule(RCTAgoraRtcEngineModule::class.java)?.engine() + } - private fun getChannel(channelId: String): RtcChannel? { - return reactContext?.getNativeModule(RCTAgoraRtcChannelModule::class.java)?.channel(channelId) - } + private fun getChannel(channelId: String): RtcChannel? { + return reactContext?.getNativeModule(RCTAgoraRtcChannelModule::class.java)?.channel(channelId) + } } diff --git a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcTextureViewManager.kt b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcTextureViewManager.kt index 5e36072e2..e3bf7f8a0 100644 --- a/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcTextureViewManager.kt +++ b/android/src/main/java/io/agora/rtc/react/RCTAgoraRtcTextureViewManager.kt @@ -9,49 +9,49 @@ import io.agora.rtc.RtcEngine import io.agora.rtc.base.RtcTextureView class RCTAgoraRtcTextureViewManager : SimpleViewManager() { - companion object { - const val REACT_CLASS = "RCTAgoraRtcTextureView" - } - - private var reactContext: ThemedReactContext? = null - - override fun createViewInstance(reactContext: ThemedReactContext): RtcTextureView { - this.reactContext = reactContext - return RtcTextureView(reactContext) - } - - override fun onDropViewInstance(view: RtcTextureView) { - // getEngine()?.let { view.resetVideoRender(it) } - super.onDropViewInstance(view) - } - - override fun getName(): String { - return REACT_CLASS - } - - @ReactProp(name = "data") - fun setData(view: RtcTextureView, data: ReadableMap) { - data.toHashMap().let { map -> - val channel = (map["channelId"] as? String)?.let { getChannel(it) } - getEngine()?.let { view.setData(it, channel, (map["uid"] as Number).toInt()) } - } - } - - @ReactProp(name = "renderMode") - fun setRenderMode(view: RtcTextureView, renderMode: Int) { - getEngine()?.let { view.setRenderMode(it, renderMode) } - } - - @ReactProp(name = "mirrorMode") - fun setMirrorMode(view: RtcTextureView, mirrorMode: Int) { - getEngine()?.let { view.setMirrorMode(it, mirrorMode) } - } - - private fun getEngine(): RtcEngine? { - return reactContext?.getNativeModule(RCTAgoraRtcEngineModule::class.java)?.engine() - } - - private fun getChannel(channelId: String): RtcChannel? { - return reactContext?.getNativeModule(RCTAgoraRtcChannelModule::class.java)?.channel(channelId) - } + companion object { + const val REACT_CLASS = "RCTAgoraRtcTextureView" + } + + private var reactContext: ThemedReactContext? = null + + override fun createViewInstance(reactContext: ThemedReactContext): RtcTextureView { + this.reactContext = reactContext + return RtcTextureView(reactContext) + } + + override fun onDropViewInstance(view: RtcTextureView) { + // getEngine()?.let { view.resetVideoRender(it) } + super.onDropViewInstance(view) + } + + override fun getName(): String { + return REACT_CLASS + } + + @ReactProp(name = "data") + fun setData(view: RtcTextureView, data: ReadableMap) { + data.toHashMap().let { map -> + val channel = (map["channelId"] as? String)?.let { getChannel(it) } + getEngine()?.let { view.setData(it, channel, (map["uid"] as Number).toInt()) } + } + } + + @ReactProp(name = "renderMode") + fun setRenderMode(view: RtcTextureView, renderMode: Int) { + getEngine()?.let { view.setRenderMode(it, renderMode) } + } + + @ReactProp(name = "mirrorMode") + fun setMirrorMode(view: RtcTextureView, mirrorMode: Int) { + getEngine()?.let { view.setMirrorMode(it, mirrorMode) } + } + + private fun getEngine(): RtcEngine? { + return reactContext?.getNativeModule(RCTAgoraRtcEngineModule::class.java)?.engine() + } + + private fun getChannel(channelId: String): RtcChannel? { + return reactContext?.getNativeModule(RCTAgoraRtcChannelModule::class.java)?.channel(channelId) + } } From d28c79d18338604cbc6e723baedd9618e8a11374 Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 28 Dec 2020 17:08:33 +0800 Subject: [PATCH 2/4] fix: process resolve value type --- .../io/agora/rtc/react/PromiseCallback.kt | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/android/src/main/java/io/agora/rtc/react/PromiseCallback.kt b/android/src/main/java/io/agora/rtc/react/PromiseCallback.kt index 642d7a842..17360577b 100644 --- a/android/src/main/java/io/agora/rtc/react/PromiseCallback.kt +++ b/android/src/main/java/io/agora/rtc/react/PromiseCallback.kt @@ -5,23 +5,28 @@ import com.facebook.react.bridge.Promise import io.agora.rtc.base.Callback class PromiseCallback( - private val promise: Promise? + private val promise: Promise? ) : Callback() { - override fun success(data: Any?) { - if (data is Map<*, *>) { - val map = mutableMapOf() - data.forEach { - if (it.key is String) { - map[it.key as String] = it.value - } - } - promise?.resolve(Arguments.makeNativeMap(map)) - } else { - promise?.resolve(data) + override fun success(data: Any?) { + when (data) { + null, is Boolean, is Int, is String -> promise?.resolve(data) + is Number -> promise?.resolve(data.toDouble()) + is Array<*> -> promise?.resolve(Arguments.makeNativeArray(arrayOf(data))) + is List<*> -> promise?.resolve(Arguments.makeNativeArray(data)) + is Map<*, *> -> { + val map = mutableMapOf() + data.forEach { + if (it.key is String) { + map[it.key as String] = it.value + } } + promise?.resolve(Arguments.makeNativeMap(map)) + } + else -> promise?.reject(IllegalArgumentException("Could not convert " + data.javaClass)) } + } - override fun failure(code: String, message: String) { - promise?.reject(code, message) - } + override fun failure(code: String, message: String) { + promise?.reject(code, message) + } } From 85c582386a5964e4cab8f99767c9fe611cd4778f Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 28 Dec 2020 17:19:33 +0800 Subject: [PATCH 3/4] chore: release 3.1.7 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72ae4b13f..d80543444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.1.7](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.1.6...v3.1.7) (2020-12-28) + + +### Bug Fixes + +* process resolve value type ([d28c79d](https://github.com/AgoraIO-Community/react-native-agora/commit/d28c79d18338604cbc6e723baedd9618e8a11374)) + ## [3.1.6](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.1.5...v3.1.6) (2020-12-21) diff --git a/package.json b/package.json index 4dc466a0d..a9d8e7f11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-agora", - "version": "3.1.6", + "version": "3.1.7", "description": "Agora RTC SDK For React Native", "main": "lib/commonjs/index", "module": "lib/module/index", From 2627100df6c2af1fdbda682a3e45f9d18e3938eb Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 28 Dec 2020 17:32:29 +0800 Subject: [PATCH 4/4] chore: release 3.2.2 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e79dbe7..2f7f6d93a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.2.2](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.2.1...v3.2.2) (2020-12-28) + + +### Bug Fixes + +* process resolve value type ([d28c79d](https://github.com/AgoraIO-Community/react-native-agora/commit/d28c79d18338604cbc6e723baedd9618e8a11374)) + ## [3.2.1](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.2.0...v3.2.1) (2020-12-24) ## [3.2.0](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.2.0-rc.0...v3.2.0) (2020-12-23) diff --git a/package.json b/package.json index 2c2bf2559..f63370549 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-agora", - "version": "3.2.1", + "version": "3.2.2", "description": "Agora RTC SDK For React Native", "main": "lib/commonjs/index", "module": "lib/module/index",