From 3a55997db81dcd16e68ee551d69b9079ff8052b0 Mon Sep 17 00:00:00 2001 From: HUI Date: Tue, 15 Dec 2020 14:41:11 +0800 Subject: [PATCH] feat: add `setClientRole(role: ClientRole, options?: ClientRoleOptions): Promise` --- BeanCovertor.swift | 10 ++++++++++ RtcChannel.swift | 7 ++++++- RtcEngine.swift | 7 ++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/BeanCovertor.swift b/BeanCovertor.swift index f50db5808..fb286dfcd 100644 --- a/BeanCovertor.swift +++ b/BeanCovertor.swift @@ -305,3 +305,13 @@ func mapToEncryptionConfig(_ map: Dictionary) -> AgoraEncryptionCon } return encryptionConfig } + +func mapToClientRoleOptions(_ map: Dictionary) -> AgoraClientRoleOptions { + let clientRoleOptions = AgoraClientRoleOptions() + if let audienceLatencyLevel = map["audienceLatencyLevel"] as? Int { + if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel) { + clientRoleOptions.audienceLatencyLevel = audienceLatencyLevel + } + } + return clientRoleOptions +} diff --git a/RtcChannel.swift b/RtcChannel.swift index 376b2632d..b27ab8094 100644 --- a/RtcChannel.swift +++ b/RtcChannel.swift @@ -171,7 +171,12 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func setClientRole(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.setClientRole(AgoraClientRole(rawValue: params["role"] as! Int)!)) + let role = AgoraClientRole(rawValue: params["role"] as! Int)! + if let options = params["options"] as? Dictionary { + callback.code(self[params["channelId"] as! String]?.setClientRole(role, options: mapToClientRoleOptions(options))) + return + } + callback.code(self[params["channelId"] as! String]?.setClientRole(role)) } @objc func joinChannel(_ params: NSDictionary, _ callback: Callback) { diff --git a/RtcEngine.swift b/RtcEngine.swift index 493036d7c..08d787163 100644 --- a/RtcEngine.swift +++ b/RtcEngine.swift @@ -387,7 +387,12 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setClientRole(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setClientRole(AgoraClientRole(rawValue: params["role"] as! Int)!)) + let role = AgoraClientRole(rawValue: params["role"] as! Int)! + if let options = params["options"] as? Dictionary { + callback.code(engine?.setClientRole(role, options: mapToClientRoleOptions(options))) + return + } + callback.code(engine?.setClientRole(role)) } @objc func joinChannel(_ params: NSDictionary, _ callback: Callback) {