Skip to content

Commit

Permalink
feat: Full support for native sdk 3.5.1 (#484)
Browse files Browse the repository at this point in the history
* feat: Full support for native sdk 3.5.1
  • Loading branch information
littleGnAl authored Oct 30, 2021
1 parent 9b31d9f commit 227cade
Show file tree
Hide file tree
Showing 16 changed files with 457 additions and 15 deletions.
9 changes: 5 additions & 4 deletions android/src/main/java/io/agora/rtc/base/Annotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ public class Annotations {
Constants.RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE,
Constants.RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_IS_NULL,
Constants.RELAY_EVENT_VIDEO_PROFILE_UPDATE,
// Constants.RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS,
// Constants.RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_FAILED,
// Constants.RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS,
// Constants.RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_FAILED,
Constants.RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS,
Constants.RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_FAILED,
Constants.RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS,
Constants.RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_FAILED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraChannelMediaRelayEvent {
Expand Down Expand Up @@ -973,6 +973,7 @@ public class Annotations {
@IntDef({
VirtualBackgroundSource.BACKGROUND_COLOR,
VirtualBackgroundSource.BACKGROUND_IMG,
VirtualBackgroundSource.BACKGROUND_BLUR,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraVirtualBackgroundSourceType {
Expand Down
1 change: 1 addition & 0 deletions android/src/main/java/io/agora/rtc/base/BeanCovertor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@ fun mapToVirtualBackgroundSource(map: Map<*, *>): VirtualBackgroundSource {
(map["backgroundSourceType"] as? Number)?.let { backgroundSourceType = it.toInt() }
(map["color"] as? Map<*, *>)?.let { color = mapToColor(it) }
(map["source"] as? String)?.let { source = it }
(map["blur_degree"] as? Int)?.let { blur_degree = it }
}
}
7 changes: 7 additions & 0 deletions android/src/main/java/io/agora/rtc/base/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ fun AgoraFacePositionInfo.toMap(): Map<String, Any?> {
)
}

fun AudioFileInfo.toMap(): Map<String, Any?> {
return hashMapOf(
"filePath" to filePath,
"durationMs" to durationMs
)
}

fun Array<out AgoraFacePositionInfo>.toMapList(): List<Map<String, Any?>> {
return List(size) { this[it].toMap() }
}
Expand Down
30 changes: 26 additions & 4 deletions android/src/main/java/io/agora/rtc/base/RtcEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ class IRtcEngine {
fun setAudioMixingPosition(params: Map<String, *>, callback: Callback)

fun setAudioMixingPitch(params: Map<String, *>, callback: Callback)

fun setAudioMixingPlaybackSpeed(params: Map<String, *>, callback: Callback)

fun getAudioTrackCount(callback: Callback)

fun selectAudioTrack(params: Map<String, *>, callback: Callback)

fun setAudioMixingDualMonoMode(params: Map<String, *>, callback: Callback)
}

interface RtcAudioEffectInterface {
Expand Down Expand Up @@ -841,6 +849,22 @@ open class RtcEngineManager(
callback.code(engine?.setAudioMixingPitch((params["pitch"] as Number).toInt()))
}

override fun setAudioMixingPlaybackSpeed(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setAudioMixingPlaybackSpeed((params["speed"] as Number).toInt()))
}

override fun getAudioTrackCount(callback: Callback) {
callback.code(engine?.audioTrackCount) { it }
}

override fun selectAudioTrack(params: Map<String, *>, callback: Callback) {
callback.code(engine?.selectAudioTrack((params["audioIndex"] as Number).toInt()))
}

override fun setAudioMixingDualMonoMode(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setAudioMixingDualMonoMode((params["mode"] as Number).toInt()))
}

override fun getEffectsVolume(callback: Callback) {
callback.resolve(engine) { it.audioEffectManager.effectsVolume }
}
Expand Down Expand Up @@ -1053,13 +1077,11 @@ open class RtcEngineManager(
}

override fun pauseAllChannelMediaRelay(callback: Callback) {
callback.code(-Constants.ERR_NOT_SUPPORTED)
// callback.code(engine?.pauseAllChannelMediaRelay())
callback.code(engine?.pauseAllChannelMediaRelay())
}

override fun resumeAllChannelMediaRelay(callback: Callback) {
callback.code(-Constants.ERR_NOT_SUPPORTED)
// callback.code(engine?.resumeAllChannelMediaRelay())
callback.code(engine?.resumeAllChannelMediaRelay())
}

override fun setDefaultAudioRoutetoSpeakerphone(params: Map<String, *>, callback: Callback) {
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/io/agora/rtc/base/RtcEngineEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RtcEngineEvents {
const val LocalVideoStateChanged = "LocalVideoStateChanged"
const val RemoteAudioStateChanged = "RemoteAudioStateChanged"
const val LocalAudioStateChanged = "LocalAudioStateChanged"
const val RequestAudioFileInfo = "RequestAudioFileInfo"
const val LocalPublishFallbackToAudioOnly = "LocalPublishFallbackToAudioOnly"
const val RemoteSubscribeFallbackToAudioOnly = "RemoteSubscribeFallbackToAudioOnly"
const val AudioRouteChanged = "AudioRouteChanged"
Expand Down Expand Up @@ -116,6 +117,7 @@ class RtcEngineEvents {
"LocalVideoStateChanged" to LocalVideoStateChanged,
"RemoteAudioStateChanged" to RemoteAudioStateChanged,
"LocalAudioStateChanged" to LocalAudioStateChanged,
"RequestAudioFileInfo" to RequestAudioFileInfo,
"LocalPublishFallbackToAudioOnly" to LocalPublishFallbackToAudioOnly,
"RemoteSubscribeFallbackToAudioOnly" to RemoteSubscribeFallbackToAudioOnly,
"AudioRouteChanged" to AudioRouteChanged,
Expand Down Expand Up @@ -325,6 +327,10 @@ class RtcEngineEventHandler(
callback(RtcEngineEvents.LocalAudioStateChanged, state, error)
}

override fun onRequestAudioFileInfo(info: AudioFileInfo?, error: Int) {
callback(RtcEngineEvents.RequestAudioFileInfo, info?.toMap(), error)
}

override fun onLocalPublishFallbackToAudioOnly(isFallbackOrRecover: Boolean) {
callback(RtcEngineEvents.LocalPublishFallbackToAudioOnly, isFallbackOrRecover)
}
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/Base/BeanCovertor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,10 @@ func mapToVirtualBackgroundSource(_ map: [String: Any]) -> AgoraVirtualBackgroun
backgroundSource.color = UInt(red * 255.0) << 16 + UInt(green * 255.0) << 8 + UInt(blue * 255.0)
}
backgroundSource.source = map["source"] as? String
if let blurDegree = map["blur_degree"] as? NSNumber {
if let blurDegree = AgoraBlurDegree(rawValue: blurDegree.uintValue) {
backgroundSource.blur_degree = blurDegree
}
}
return backgroundSource
}
9 changes: 9 additions & 0 deletions ios/Classes/Base/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ extension AgoraFacePositionInfo {
}
}

extension AgoraRtcAudioFileInfo {
func toMap() -> [String: Any?] {
return [
"filePath": filePath,
"durationMs": durationMs,
]
}
}

extension Array where Element: AgoraFacePositionInfo {
func toMapList() -> [[String: Any?]] {
var list = [[String: Any?]]()
Expand Down
33 changes: 29 additions & 4 deletions ios/Classes/Base/RtcEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ protocol RtcEngineAudioMixingInterface {
func setAudioMixingPosition(_ params: NSDictionary, _ callback: Callback)

func setAudioMixingPitch(_ params: NSDictionary, _ callback: Callback)

func setAudioMixingPlaybackSpeed(_ params: NSDictionary, _ callback: Callback)

func getAudioTrackCount(_ callback: Callback)

func selectAudioTrack(_ params: NSDictionary, _ callback: Callback)

func setAudioMixingDualMonoMode(_ params: NSDictionary, _ callback: Callback)
}

protocol RtcEngineAudioEffectInterface {
Expand Down Expand Up @@ -736,6 +744,25 @@ class RtcEngineManager: NSObject, RtcEngineInterface {
@objc func setAudioMixingPitch(_ params: NSDictionary, _ callback: Callback) {
callback.code(engine?.setAudioMixingPitch((params["pitch"] as! NSNumber).intValue))
}

@objc func setAudioMixingPlaybackSpeed(_ params: NSDictionary, _ callback: Callback) {
callback.code(engine?.setAudioMixingPlaybackSpeed(Int32((params["speed"] as! NSNumber).intValue)))
}

@objc func getAudioTrackCount(_ callback: Callback) {
callback.code(engine?.getAudioTrackCount()) {
$0
}
}

@objc func selectAudioTrack(_ params: NSDictionary, _ callback: Callback) {
callback.code(engine?.selectAudioTrack((params["audioIndex"] as! NSNumber).intValue))
}

@objc func setAudioMixingDualMonoMode(_ params: NSDictionary, _ callback: Callback) {
let mode = AgoraAudioMixingDualMonoMode(rawValue: UInt((params["mode"] as! NSNumber).intValue))
callback.code(engine?.setAudioMixingDualMonoMode(mode!))
}

@objc func getEffectsVolume(_ callback: Callback) {
callback.resolve(engine) {
Expand Down Expand Up @@ -1173,13 +1200,11 @@ class RtcEngineManager: NSObject, RtcEngineInterface {
}

@objc func pauseAllChannelMediaRelay(_ callback: Callback) {
callback.code(-Int32(AgoraErrorCode.notSupported.rawValue))
// callback.code(engine?.pauseAllChannelMediaRelay())
callback.code(engine?.pauseAllChannelMediaRelay())
}

@objc func resumeAllChannelMediaRelay(_ callback: Callback) {
callback.code(-Int32(AgoraErrorCode.notSupported.rawValue))
// callback.code(engine?.resumeAllChannelMediaRelay())
callback.code(engine?.resumeAllChannelMediaRelay())
}

@objc func enableVirtualBackground(_ params: NSDictionary, _ callback: Callback) {
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/Base/RtcEngineEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RtcEngineEvents {
static let LocalVideoStateChanged = "LocalVideoStateChanged"
static let RemoteAudioStateChanged = "RemoteAudioStateChanged"
static let LocalAudioStateChanged = "LocalAudioStateChanged"
static let RequestAudioFileInfo = "RequestAudioFileInfo"
static let LocalPublishFallbackToAudioOnly = "LocalPublishFallbackToAudioOnly"
static let RemoteSubscribeFallbackToAudioOnly = "RemoteSubscribeFallbackToAudioOnly"
static let AudioRouteChanged = "AudioRouteChanged"
Expand Down Expand Up @@ -120,6 +121,7 @@ class RtcEngineEvents {
"LocalVideoStateChanged": LocalVideoStateChanged,
"RemoteAudioStateChanged": RemoteAudioStateChanged,
"LocalAudioStateChanged": LocalAudioStateChanged,
"RequestAudioFileInfo": RequestAudioFileInfo,
"LocalPublishFallbackToAudioOnly": LocalPublishFallbackToAudioOnly,
"RemoteSubscribeFallbackToAudioOnly": RemoteSubscribeFallbackToAudioOnly,
"AudioRouteChanged": AudioRouteChanged,
Expand Down Expand Up @@ -297,6 +299,10 @@ extension RtcEngineEventHandler: AgoraRtcEngineDelegate {
public func rtcEngine(_: AgoraRtcEngineKit, localAudioStateChange state: AgoraAudioLocalState, error: AgoraAudioLocalError) {
callback(RtcEngineEvents.LocalAudioStateChanged, state.rawValue, error.rawValue)
}

func rtcEngine(_ engine: AgoraRtcEngineKit, didRequest info: AgoraRtcAudioFileInfo, error: AgoraAudioFileInfoError) {
callback(RtcEngineEvents.RequestAudioFileInfo, info.toMap(), error.rawValue)
}

public func rtcEngine(_: AgoraRtcEngineKit, didLocalPublishFallbackToAudioOnly isFallbackOrRecover: Bool) {
callback(RtcEngineEvents.LocalPublishFallbackToAudioOnly, isFallbackOrRecover)
Expand Down
49 changes: 48 additions & 1 deletion lib/src/classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:ui' show Color;

import 'package:agora_rtc_engine/src/enum_converter.dart';
import 'package:json_annotation/json_annotation.dart';
import 'events.dart';

import 'enums.dart';

Expand Down Expand Up @@ -1626,8 +1627,29 @@ class VirtualBackgroundSource {
@JsonKey(includeIfNull: false)
String? source;

/// The degree of blurring applied to the custom background image:
///
/// * [VirtualBackgroundBlurDegree.Low]: The degree of blurring applied to the
/// custom background image is low. The user can almost see the background clearly.
/// * [VirtualBackgroundBlurDegree.Medium]: The degree of blurring applied to
/// the custom background image is medium. It is difficult for the user to
/// recognize details in the background.
/// * [VirtualBackgroundBlurDegree.High]: (Default) The degree of blurring applied
/// to the custom background image is high. The user can barely see any
/// distinguishing features in the background.
///
/// **Note**: This parameter takes effect only when the type of the custom
/// background image is [VirtualBackgroundSourceType.Blur].
@JsonKey(name: 'blur_degree')
VirtualBackgroundBlurDegree blurDegree;

/// Constructs a [VirtualBackgroundSource]
VirtualBackgroundSource({this.backgroundSourceType, this.color, this.source});
VirtualBackgroundSource({
this.backgroundSourceType,
this.color,
this.source,
this.blurDegree = VirtualBackgroundBlurDegree.High,
});

/// @nodoc
factory VirtualBackgroundSource.fromJson(Map<String, dynamic> json) =>
Expand All @@ -1636,3 +1658,28 @@ class VirtualBackgroundSource {
/// @nodoc
Map<String, dynamic> toJson() => _$VirtualBackgroundSourceToJson(this);
}

/// The information of an audio file, which is reported in [RtcEngineEventHandler.requestAudioFileInfoCallback].
@JsonSerializable(explicitToJson: true)
class AudioFileInfo {
/// Construct the [AudioFileInfo]
AudioFileInfo({
required this.filePath,
required this.durationMs,
});

/// The file path.
@JsonKey()
String filePath;

/// The file duration (ms).
@JsonKey()
int durationMs;

/// @nodoc
factory AudioFileInfo.fromJson(Map<String, dynamic> json) =>
_$AudioFileInfoFromJson(json);

/// @nodoc
Map<String, dynamic> toJson() => _$AudioFileInfoToJson(this);
}
24 changes: 24 additions & 0 deletions lib/src/classes.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 227cade

Please sign in to comment.