Skip to content

Commit

Permalink
updating to RTM 2.1.8 with user channels, more error codes, fix encry…
Browse files Browse the repository at this point in the history
…pt salt string, and RtmTopicMessageOptions object
  • Loading branch information
maxxfrazer committed Dec 7, 2023
1 parent 83838e8 commit e2d681b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let package = Package(
// .binaryTarget(name: "AgoraRtmKit-OC", path: "AgoraRtmKit.xcframework.zip"),
.binaryTarget(
name: "AgoraRtmKit-OC",
url: "https://github.com/AgoraIO/AgoraRtm_Apple/releases/download/2.1.7-beta.1/AgoraRtmKit.xcframework.zip",
checksum: "4e6c6dc8e02ed3b3acf52806f38c9cb41a51a99c1182036507352e591b896922"
url: "https://github.com/AgoraIO/AgoraRtm_Apple/releases/download/2.1.8-beta.1/AgoraRtmKit.xcframework.zip",
checksum: "b180e27e9cad4f2bb4787e2cb383f1cc7d2e6455da2f04ca930cb8f0746b0e09"
),
.testTarget(
name: "AgoraRtmTests",
Expand Down
8 changes: 6 additions & 2 deletions Sources/AgoraRtm/RtmClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ import AgoraRtmKit
}

public static func encryptSaltString(salt: String?) -> Data? {
guard let salt else { return nil }
return Data(base64Encoded: salt, options: .ignoreUnknownCharacters)
if let salt, let data = salt.data(using: .utf8) {
let base64Encoded = data.base64EncodedString()
// Now use base64Encoded in your function call
return Data(base64Encoded: base64Encoded, options: .ignoreUnknownCharacters)
}
return nil
}
}
11 changes: 11 additions & 0 deletions Sources/AgoraRtm/RtmClientDelegate+Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public enum RtmChannelType: Int {
case message = 1
/// Stream channel type.
case stream = 2
/// User channel type.
case user = 3

var ocChannelType: AgoraRtmChannelType {
switch self {
case .stream: .stream
case .message: .message
case .user: .user
case .none: .none
}
}
}

/// The type of an RTM message.
Expand Down
8 changes: 8 additions & 0 deletions Sources/AgoraRtm/RtmErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public enum RtmErrorCode: Int, ErrorCode {
case duplicateOperation = -10017
/// Already called destroy or release, this instance is forbidden to call any API. Please create a new instance.
case instanceAlreadyReleased = -10018
/// Invalid channel type
case invalidChannelType = -10019
/// The encryption parameter is invalid.
case invalidEncryptionParameter = -10020
/// The operation is too frequent.
case operationRateExceedLimitation = -10021
/// The user has not joined the channel.
case channelNotJoined = -11001
/// The user has not subscribed to the channel.
Expand Down Expand Up @@ -193,6 +199,8 @@ public enum RtmErrorCode: Int, ErrorCode {
case channelUnsupportedMessageType = -11031
/// The channel presence is not ready.
case channelPresenceNotReady = -11032
/// The destination user of publish message is offline.
case channelReceiverOffline = -11033
/// The storage operation failed.
case storageOperationFailed = -12001
/// The metadata item count exceeds the limit.
Expand Down
23 changes: 11 additions & 12 deletions Sources/AgoraRtm/RtmLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@ public enum RtmChannelDetails {
case none(String)
case messageChannel(String)
case streamChannel(String)
case user(String)
internal var objcVersion: (channelName: String, channelType: AgoraRtmChannelType) {
switch self {
case .none(let name):
return (name, .none)
case .messageChannel(let name):
return (name, .message)
case .streamChannel(let name):
return (name, .stream)
case .none(let name): (name, .none)
case .messageChannel(let name): (name, .message)
case .streamChannel(let name): (name, .stream)
case .user(let username): (username, .user)
}
}
/// Initializes an instance of `RtmChannelInfo`.
///
/// - Parameters:
/// - agoraChannelInfo: The `AgoraRtmChannelInfo` instance.
internal init(_ agoraChannelInfo: AgoraRtmChannelInfo) {
switch agoraChannelInfo.channelType {
case .message: self = .messageChannel(agoraChannelInfo.channelName)
case .stream: self = .streamChannel(agoraChannelInfo.channelName)
case .none: self = .none(agoraChannelInfo.channelName)
@unknown default:
self = .none(agoraChannelInfo.channelName)
self = switch agoraChannelInfo.channelType {
case .message: .messageChannel(agoraChannelInfo.channelName)
case .stream: .streamChannel(agoraChannelInfo.channelName)
case .none: .none(agoraChannelInfo.channelName)
case .user: .user(agoraChannelInfo.channelName)
@unknown default: .none(agoraChannelInfo.channelName)
}
}
}
Expand Down
34 changes: 32 additions & 2 deletions Sources/AgoraRtm/RtmStreamChannel+ChannelOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ public class RtmPublishOptions {
/// The custom type of the message, up to 32 bytes for customization.
public let customType: String

/// Type of channel we are publishing to.
public var channelType: RtmChannelType

/// Initializes an instance of `AgoraRtmPublishOptions`.
///
/// - Parameters:
/// - customType: The custom type of the message, up to 32 bytes for customization.
/// - channelType: Type of channel we are publishing to.
/// Valid types for this are ``RtmChannelType/message`` and ``RtmChannelType/user``.
public init(customType: String, channelType: RtmChannelType = .message) {
self.customType = customType
self.channelType = channelType
}

/// Converts the `AgoraRtmPublishOptions` to the corresponding `RtmPublishOptions` object.
///
/// - Returns: The `RtmPublishOptions` object with the options set based on the `AgoraRtmPublishOptions`.
internal var objcVersion: AgoraRtmPublishOptions {
let objcOpt = AgoraRtmPublishOptions()
objcOpt.customType = customType
objcOpt.channelType = channelType.ocChannelType
return objcOpt
}
}

/// Options for publishing a message to a topic in Agora Real-Time Messaging (RTM) system.
public class RtmTopicMessageOptions {
/// The custom type of the message, up to 32 bytes for customization.
public let customType: String

/// The time to calibrate data with media, only valid when a user joins the topic
/// with ``RtmJoinTopicOption/syncWithMedia`` in a stream channel.
public var sendTs: UInt64 = 0
Expand All @@ -30,8 +60,8 @@ public class RtmPublishOptions {
/// Converts the `AgoraRtmPublishOptions` to the corresponding `RtmPublishOptions` object.
///
/// - Returns: The `RtmPublishOptions` object with the options set based on the `AgoraRtmPublishOptions`.
internal var objcVersion: AgoraRtmPublishOptions {
let objcOpt = AgoraRtmPublishOptions()
internal var objcVersion: AgoraRtmTopicMessageOptions {
let objcOpt = AgoraRtmTopicMessageOptions()
objcOpt.customType = customType
objcOpt.sendTs = sendTs
return objcOpt
Expand Down
8 changes: 4 additions & 4 deletions Sources/AgoraRtm/RtmStreamChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ open class RtmStreamChannel: NSObject {
/// - Parameters:
/// - message: The message to be published. Must be `Codable`.
/// - topic: The name of the topic to which the message will be published.
/// - options: Optional configurations for publishing the message. Defaults to `nil`.
/// - options: Optional configurations for publishing the message to a topic. Defaults to `nil`.
/// - completion: A completion block that returns a result containing an ``RtmCommonResponse``
/// or ``RtmErrorInfo``.
public func publishTopicMessage(
_ message: Codable, in topic: String, with options: RtmPublishOptions?,
_ message: Codable, in topic: String, with options: RtmTopicMessageOptions?,
completion: ((Result<RtmCommonResponse, RtmErrorInfo>) -> Void)? = nil
) {
let msgString: String
Expand Down Expand Up @@ -283,15 +283,15 @@ open class RtmStreamChannel: NSObject {
/// - Parameters:
/// - message: The message to be published. Must be `Codable`.
/// - topic: The name of the topic to which the message will be published.
/// - options: Optional configurations for publishing the message. Defaults to `nil`.
/// - options: Optional configurations for publishing the message to a topic. Defaults to `nil`.
///
/// - Returns: An ``RtmCommonResponse`` containing information about the published message.
///
/// - Throws: ``RtmErrorInfo`` if an error occurs during the publishing process.
@available(iOS 13.0.0, *) @discardableResult
public func publishTopicMessage(
message: Codable,
inTopic topic: String, with options: RtmPublishOptions?
inTopic topic: String, with options: RtmTopicMessageOptions?
) async throws -> RtmCommonResponse {
let msgString: String
do {
Expand Down

0 comments on commit e2d681b

Please sign in to comment.