Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Sep 28, 2020
1 parent 6dc68f2 commit 8b3f434
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## THE CHANGELOG

#### 3.1.2
- support 3.1.2 native sdk
- fix `RejoinChannelSuccess` bug

#### 3.0.1
- release version

Expand Down
7 changes: 7 additions & 0 deletions android/src/main/java/io/agora/rtc/base/Annotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,11 @@ public class Annotations {
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraStreamPublishState {
}

@IntDef({
Constants.RTMP_STREAMING_EVENT_FAILED_LOAD_IMAGE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraRtmpStreamingEvent {
}
}
13 changes: 9 additions & 4 deletions android/src/main/java/io/agora/rtc/base/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ fun LocalAudioStats.toMap(): Map<String, Any?> {
return hashMapOf(
"numChannels" to numChannels,
"sentSampleRate" to sentSampleRate,
"sentBitrate" to sentBitrate
"sentBitrate" to sentBitrate,
"txPacketLossRate" to txPacketLossRate
)
}

Expand Down Expand Up @@ -68,7 +69,8 @@ fun RemoteAudioStats.toMap(): Map<String, Any?> {
"receivedBitrate" to receivedBitrate,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime
"totalActiveTime" to totalActiveTime,
"publishDuration" to publishDuration
)
}

Expand All @@ -85,7 +87,9 @@ fun LocalVideoStats.toMap(): Map<String, Any?> {
"encodedFrameWidth" to encodedFrameWidth,
"encodedFrameHeight" to encodedFrameHeight,
"encodedFrameCount" to encodedFrameCount,
"codecType" to codecType
"codecType" to codecType,
"txPacketLossRate" to txPacketLossRate,
"captureFrameRate" to captureFrameRate
)
}

Expand All @@ -102,7 +106,8 @@ fun RemoteVideoStats.toMap(): Map<String, Any?> {
"rxStreamType" to rxStreamType,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime
"totalActiveTime" to totalActiveTime,
"publishDuration" to publishDuration
)
}

Expand Down
14 changes: 9 additions & 5 deletions android/src/main/java/io/agora/rtc/base/RtcChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.agora.rtc.RtcEngine
import io.agora.rtc.internal.EncryptionConfig
import java.util.*

class RtcChannelInterface {
class IRtcChannel {
interface RtcChannelInterface : RtcAudioInterface, RtcVideoInterface, RtcVoicePositionInterface,
RtcPublishStreamInterface, RtcMediaRelayInterface, RtcDualStreamInterface,
RtcFallbackInterface, RtcMediaMetadataInterface, RtcEncryptionInterface,
Expand Down Expand Up @@ -116,7 +116,7 @@ class RtcChannelInterface {

class RtcChannelManager(
private val emit: (methodName: String, data: Map<String, Any?>?) -> Unit
) : RtcChannelInterface.RtcChannelInterface {
) : IRtcChannel.RtcChannelInterface {
private val rtcChannelMap = Collections.synchronizedMap(mutableMapOf<String, RtcChannel>())
private val mediaObserverMap = Collections.synchronizedMap(mutableMapOf<String, MediaObserver>())

Expand Down Expand Up @@ -315,12 +315,16 @@ class RtcChannelManager(
override fun createDataStream(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code= it.createDataStream(reliable, ordered)
code = it.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)
}
callback.code(manager.createDataStream(channelId, reliable, ordered)) { it }
callback.code(code) { it }
}

override fun sendStreamMessage(params: Map<String, *>, callback: Callback) {
callback.code(manager.sendStreamMessage(channelId, streamId, message))
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())
}
callback.code(code)
}
}
14 changes: 7 additions & 7 deletions android/src/main/java/io/agora/rtc/base/RtcChannelEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class RtcChannelEventHandler(
}

override fun onJoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) {
callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, rtcChannel.channelId(), uid, elapsed)
callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid, elapsed)
}

override fun onRejoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) {
callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, rtcChannel.channelId(), uid, elapsed)
callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid, elapsed)
}

override fun onLeaveChannel(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RtcStats?) {
Expand Down Expand Up @@ -218,22 +218,22 @@ class RtcChannelEventHandler(
}

override fun onAudioPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioPublishStateChanged, rtcChannel, rtcChannel.channelId(), oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.AudioPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState)
}

override fun onVideoPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoPublishStateChanged, rtcChannel, rtcChannel.channelId(), oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.VideoPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState)
}

override fun onAudioSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel.channelId(), uid, oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
}

override fun onVideoSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel.channelId(), uid, oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, errCode: Int) {
override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingEvent errCode: Int) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, errCode)
}
}
4 changes: 2 additions & 2 deletions android/src/main/java/io/agora/rtc/base/RtcEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.agora.rtc.*
import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.models.UserInfo

class RtcEngineInterface {
class IRtcEngine {
interface RtcEngineInterface : RtcUserInfoInterface, RtcAudioInterface, RtcVideoInterface,
RtcAudioMixingInterface, RtcAudioEffectInterface, RtcVoiceChangerInterface,
RtcVoicePositionInterface, RtcPublishStreamInterface, RtcMediaRelayInterface,
Expand Down Expand Up @@ -316,7 +316,7 @@ class RtcEngineInterface {

class RtcEngineManager(
private val emit: (methodName: String, data: Map<String, Any?>?) -> Unit
) : RtcEngineInterface.RtcEngineInterface {
) : IRtcEngine.RtcEngineInterface {
var engine: RtcEngine? = null
private set
private var mediaObserver: MediaObserver? = null
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/java/io/agora/rtc/base/RtcEngineEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class RtcEngineEventHandler(
callback(RtcEngineEvents.VideoSubscribeStateChanged, channel, uid, oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(url: String?, error: Int) {
override fun onRtmpStreamingEvent(url: String?, @Annotations.AgoraRtmpStreamingEvent error: Int) {
callback(RtcEngineEvents.RtmpStreamingEvent, url, error)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.modules.core.DeviceEventManagerModule
import io.agora.rtc.RtcChannel
import io.agora.rtc.RtcEngine
import io.agora.rtc.base.*
import io.agora.rtc.base.RtcChannelEventHandler
import io.agora.rtc.base.RtcChannelManager
import io.agora.rtc.react.RCTAgoraRtcChannelModule.Companion.REACT_CLASS
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.jvm.javaMethod

@ReactModule(name = REACT_CLASS)
class RCTAgoraRtcChannelModule(
Expand All @@ -16,7 +19,7 @@ class RCTAgoraRtcChannelModule(
const val REACT_CLASS = "RCTAgoraRtcChannelModule"
}

private val manager = RtcChannelManager()
private val manager = RtcChannelManager { methodName, data -> emit(methodName, data) }

override fun getName(): String {
return REACT_CLASS
Expand Down Expand Up @@ -46,5 +49,23 @@ class RCTAgoraRtcChannelModule(
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<Any?>()
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()
}
}
}
}
}
13 changes: 9 additions & 4 deletions ios/RCTAgora/Base/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension AgoraRtcLocalAudioStats {
return [
"numChannels": numChannels,
"sentSampleRate": sentSampleRate,
"sentBitrate": sentBitrate
"sentBitrate": sentBitrate,
"txPacketLossRate": txPacketLossRate
]
}
}
Expand Down Expand Up @@ -82,7 +83,8 @@ extension AgoraRtcRemoteAudioStats {
"receivedBitrate": receivedBitrate,
"totalFrozenTime": totalFrozenTime,
"frozenRate": frozenRate,
"totalActiveTime": totalActiveTime
"totalActiveTime": totalActiveTime,
"publishDuration": publishDuration
]
}
}
Expand All @@ -101,7 +103,9 @@ extension AgoraRtcLocalVideoStats {
"encodedFrameWidth": encodedFrameWidth,
"encodedFrameHeight": encodedFrameHeight,
"encodedFrameCount": encodedFrameCount,
"codecType": codecType.rawValue
"codecType": codecType.rawValue,
"txPacketLossRate": txPacketLossRate,
"captureFrameRate": captureFrameRate
]
}
}
Expand All @@ -120,7 +124,8 @@ extension AgoraRtcRemoteVideoStats {
"rxStreamType": rxStreamType.rawValue,
"totalFrozenTime": totalFrozenTime,
"frozenRate": frozenRate,
"totalActiveTime": totalActiveTime
"totalActiveTime": totalActiveTime,
"publishDuration": publishDuration
]
}
}
Expand Down
3 changes: 3 additions & 0 deletions ios/RCTAgora/React/RCTAgoraRtcChannelModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class RCTAgoraRtcChannelModule: RCTEventEmitter {

@objc func callMethod(_ methodName: String, _ params: NSDictionary?, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
if let `params` = params {
if methodName == "create" {
params.setValue(engine(), forKey: "engine")
}
manager.perform(NSSelectorFromString(methodName + "::"), with: params, with: PromiseCallback(resolve, reject))
} else {
manager.perform(NSSelectorFromString(methodName + ":"), with: PromiseCallback(resolve, reject))
Expand Down
3 changes: 2 additions & 1 deletion ios/RCTAgora/React/RCTAgoraRtcChannelModuleBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@interface RCT_EXTERN_MODULE(RCTAgoraRtcChannelModule, NSObject)

RCT_EXTERN_METHOD(callMethod:(NSString *) methodName :(NSDictionary *) params :(RCTPromiseResolveBlock) resolve :(RCTPromiseRejectBlock) reject)
RCT_EXTERN_METHOD(callMethod:
(NSString *) methodName :(NSDictionary *) params :(RCTPromiseResolveBlock) resolve :(RCTPromiseRejectBlock) reject)

@end
3 changes: 2 additions & 1 deletion ios/RCTAgora/React/RCTAgoraRtcEngineModuleBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@interface RCT_EXTERN_MODULE(RCTAgoraRtcEngineModule, NSObject)

RCT_EXTERN_METHOD(callMethod:(NSString *) methodName :(NSDictionary *) params :(RCTPromiseResolveBlock) resolve :(RCTPromiseRejectBlock) reject)
RCT_EXTERN_METHOD(callMethod:
(NSString *) methodName :(NSDictionary *) params :(RCTPromiseResolveBlock) resolve :(RCTPromiseRejectBlock) reject)

@end
2 changes: 1 addition & 1 deletion ios/RCTAgora/React/RCTAgoraRtcSurfaceViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RtcView: RtcSurfaceView {

deinit {
// if let engine = getEngine?() {
// resetVideoCanvas(engine)
// resetVideoCanvas(engine)
// }
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-agora",
"version": "3.0.1",
"version": "3.1.2",
"description": "React Native around the Agora RTC SDKs for Android and iOS agora",
"summary": "agora native sdk for react-native",
"main": "lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions react-native-agora.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
s.source = { :git => package["repository"]["url"] }
s.source_files = 'ios/RCTAgora/**/*.{h,m,swift}'

s.dependency 'React-Core'
s.dependency "AgoraRtcEngine_iOS_Crypto", "3.0.1.1"
s.dependency 'React'
s.dependency "AgoraRtcEngine_iOS_Crypto", "3.1.2"
end

0 comments on commit 8b3f434

Please sign in to comment.