Skip to content

Commit

Permalink
feat: support 3.3.0 for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jan 27, 2021
1 parent c8a08e5 commit b422ce8
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 81 deletions.
69 changes: 60 additions & 9 deletions BeanCovertor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,22 @@ func mapToLiveInjectStreamConfig(_ map: Dictionary<String, Any>) -> AgoraLiveInj

func mapToCameraCapturerConfiguration(_ map: Dictionary<String, Any>) -> AgoraCameraCapturerConfiguration {
let config = AgoraCameraCapturerConfiguration()
config.preference = AgoraCameraCaptureOutputPreference(rawValue: map["preference"] as! Int)!
config.cameraDirection = AgoraCameraDirection(rawValue: map["cameraDirection"] as! Int)!
if let preference = map["preference"] as? Int {
if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference) {
config.preference = preference
}
}
if let captureWidth = map["captureWidth"] as? Int32 {
config.captureWidth = captureWidth
}
if let captureHeight = map["captureHeight"] as? Int32 {
config.captureHeight = captureHeight
}
if let cameraDirection = map["cameraDirection"] as? Int {
if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection) {
config.cameraDirection = cameraDirection
}
}
return config
}

Expand All @@ -293,25 +307,62 @@ func mapToChannelMediaOptions(_ map: Dictionary<String, Any>) -> AgoraRtcChannel
return options
}

func mapToRtcEngineConfig(_ map: Dictionary<String, Any>) -> AgoraRtcEngineConfig {
let config = AgoraRtcEngineConfig()
config.appId = map["appId"] as? String
if let areaCode = map["areaCode"] as? UInt {
config.areaCode = areaCode
}
if let logConfig = map["logConfig"] as? Dictionary<String, Any> {
config.logConfig = mapToLogConfig(logConfig)
}
return config
}

func mapToEncryptionConfig(_ map: Dictionary<String, Any>) -> AgoraEncryptionConfig {
let encryptionConfig = AgoraEncryptionConfig()
let config = AgoraEncryptionConfig()
if let encryptionMode = map["encryptionMode"] as? Int {
if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode) {
encryptionConfig.encryptionMode = encryptionMode
config.encryptionMode = encryptionMode
}
}
if let encryptionKey = map["encryptionKey"] as? String {
encryptionConfig.encryptionKey = encryptionKey
config.encryptionKey = encryptionKey
}
return encryptionConfig
return config
}

func mapToClientRoleOptions(_ map: Dictionary<String, Any>) -> AgoraClientRoleOptions {
let clientRoleOptions = AgoraClientRoleOptions()
let options = AgoraClientRoleOptions()
if let audienceLatencyLevel = map["audienceLatencyLevel"] as? Int {
if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel) {
clientRoleOptions.audienceLatencyLevel = audienceLatencyLevel
options.audienceLatencyLevel = audienceLatencyLevel
}
}
return clientRoleOptions
return options
}

func mapToLogConfig(_ map: Dictionary<String, Any>) -> AgoraLogConfig {
let config = AgoraLogConfig()
config.filePath = map["filePath"] as? String
if let fileSize = map["fileSize"] as? Int {
config.fileSize = fileSize
}
if let level = map["level"] as? Int {
if let level = AgoraLogLevel.init(rawValue: level) {
config.level = level;
}
}
return config
}

func mapToDataStreamConfig(_ map: Dictionary<String, Any>) -> AgoraDataStreamConfig {
let config = AgoraDataStreamConfig()
if let syncWithAudio = map["syncWithAudio"] as? Bool {
config.syncWithAudio = syncWithAudio
}
if let ordered = map["ordered"] as? Bool {
config.ordered = ordered
}
return config
}
7 changes: 5 additions & 2 deletions Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ extension AgoraRtcRemoteAudioStats {
"totalFrozenTime": totalFrozenTime,
"frozenRate": frozenRate,
"totalActiveTime": totalActiveTime,
"publishDuration": publishDuration
"publishDuration": publishDuration,
"qoeQuality": qoeQuality,
"qualityChangedReason": qualityChangedReason
]
}
}
Expand All @@ -105,7 +107,8 @@ extension AgoraRtcLocalVideoStats {
"encodedFrameCount": encodedFrameCount,
"codecType": codecType.rawValue,
"txPacketLossRate": txPacketLossRate,
"captureFrameRate": captureFrameRate
"captureFrameRate": captureFrameRate,
"captureBrightnessLevel": captureBrightnessLevel.rawValue
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion MediaObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AgoraRtcKit

class MediaObserver: NSObject {
private var emitter: (_ data: Dictionary<String, Any?>?) -> Void
private var maxMetadataSize = 0
private var maxMetadataSize = 1024
private var metadataList = [String]()

init(_ emitter: @escaping (_ data: Dictionary<String, Any?>?) -> Void) {
Expand Down
66 changes: 32 additions & 34 deletions RtcChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protocol RtcChannelAudioInterface {

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

@available(*, deprecated)
func setDefaultMuteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback)
}

Expand All @@ -59,7 +60,10 @@ protocol RtcChannelVideoInterface {

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

@available(*, deprecated)
func setDefaultMuteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback)

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

protocol RtcChannelVoicePositionInterface {
Expand Down Expand Up @@ -103,8 +107,10 @@ protocol RtcChannelMediaMetadataInterface {
}

protocol RtcChannelEncryptionInterface {
@available(*, deprecated)
func setEncryptionSecret(_ params: NSDictionary, _ callback: Callback)

@available(*, deprecated)
func setEncryptionMode(_ params: NSDictionary, _ callback: Callback)

func enableEncryption(_ params: NSDictionary, _ callback: Callback)
Expand Down Expand Up @@ -163,11 +169,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
}

@objc func destroy(_ params: NSDictionary, _ callback: Callback) {
var code: Int32? = -Int32(AgoraErrorCode.notInitialized.rawValue)
if let it = self[params["channelId"] as! String] {
code = rtcChannelMap.removeValue(forKey: it.getId()!)?.destroy()
}
callback.code(code)
callback.code(rtcChannelMap.removeValue(forKey:params["channelId"] as! String)?.destroy())
}

@objc func setClientRole(_ params: NSDictionary, _ callback: Callback) {
Expand Down Expand Up @@ -284,28 +286,29 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
}

@objc func registerMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) {
var code = -AgoraErrorCode.notInitialized.rawValue
if let it = self[params["channelId"] as! String] {
let mediaObserver = MediaObserver { [weak self] in
self?.emitter(RtcEngineEvents.MetadataReceived, $0)
let channelId = params["channelId"] as! String
let mediaObserver = MediaObserver { [weak self] in
if var data = $0 {
data["channelId"] = channelId;
self?.emitter(RtcEngineEvents.MetadataReceived, data)
}
if it.setMediaMetadataDelegate(mediaObserver, with: .video) {
mediaObserverMap[it.getId()!] = mediaObserver
code = AgoraErrorCode.noError.rawValue
}
callback.resolve(self[channelId]) {
if $0.setMediaMetadataDelegate(mediaObserver, with: .video) {
mediaObserverMap[channelId] = mediaObserver
}
return nil
}
callback.code(Int32(code))
}

@objc func unregisterMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) {
var code = -AgoraErrorCode.notInitialized.rawValue
if let it = self[params["channelId"] as! String] {
if it.setMediaMetadataDelegate(nil, with: .video) {
mediaObserverMap.removeValue(forKey: it.getId()!)
code = AgoraErrorCode.noError.rawValue
let channelId = params["channelId"] as! String
callback.resolve(self[channelId]) {
if $0.setMediaMetadataDelegate(nil, with: .video) {
mediaObserverMap.removeValue(forKey: channelId)
}
return nil
}
callback.code(Int32(code))
}

@objc func setMaxMetadataSize(_ params: NSDictionary, _ callback: Callback) {
Expand Down Expand Up @@ -351,25 +354,20 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
}

@objc func createDataStream(_ params: NSDictionary, _ callback: Callback) {
var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue)
let channel = self[params["channelId"] as! String]
var streamId = 0
if let it = self[params["channelId"] as! String] {
code = it.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)
}
callback.code(code) { ignore in
streamId
if let config = params["config"] as? Dictionary<String, Any> {
callback.code(channel?.createDataStream(&streamId, config: mapToDataStreamConfig(config))) { _ in streamId }
return
}
callback.code(channel?.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)) { _ in streamId }
}

@objc func sendStreamMessage(_ params: NSDictionary, _ callback: Callback) {
var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue)
if let it = self[params["channelId"] as! String] {
if let data = (params["message"] as! String).data(using: .utf8) {
code = it.sendStreamMessage(params["streamId"] as! Int, data: data)
} else {
code = -Int32(AgoraErrorCode.invalidArgument.rawValue)
}
}
callback.code(code)
callback.code(self[params["channelId"] as! String]?.sendStreamMessage(params["streamId"] as! Int, data: (params["message"] as! String).data(using: .utf8)!))
}

@objc func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) {
callback.code(self[params["channelId"] as! String]?.enableRemoteSuperResolution(params["uid"] as! UInt, enabled: params["enable"] as! Bool))
}
}
6 changes: 6 additions & 0 deletions RtcChannelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RtcChannelEvents {
static let AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
static let VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
static let RtmpStreamingEvent = "RtmpStreamingEvent"
static let UserSuperResolutionEnabled = "UserSuperResolutionEnabled"

static func toMap() -> Dictionary<String, String> {
return [
Expand Down Expand Up @@ -83,6 +84,7 @@ class RtcChannelEvents {
"AudioSubscribeStateChanged": AudioSubscribeStateChanged,
"VideoSubscribeStateChanged": VideoSubscribeStateChanged,
"RtmpStreamingEvent": RtmpStreamingEvent,
"UserSuperResolutionEnabled": UserSuperResolutionEnabled
]
}
}
Expand Down Expand Up @@ -240,4 +242,8 @@ extension RtcChannelEventHandler: AgoraRtcChannelDelegate {
func rtcChannel(_ rtcChannel: AgoraRtcChannel, rtmpStreamingEventWithUrl url: String, eventCode: AgoraRtmpStreamingEvent) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, eventCode.rawValue)
}

func rtcChannel(_ rtcChannel: AgoraRtcChannel, superResolutionEnabledOfUid uid: UInt, enabled: Bool, reason: AgoraSuperResolutionStateReason) {
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason.rawValue)
}
}
Loading

0 comments on commit b422ce8

Please sign in to comment.