I am implementing Cometchat and Agora audio chat in swiftui application and in both cases I am facing the situation which is not typical for me.
Up to a certain method everything works correctly, but in case of calling "join the channel" or "get message list" callback method does not work, although there is no error.
I'm attaching a code example (everything works before method, inside the callback it doesn't). I don't understand how to fix it. Can you advise me in which direction to look for a solution?
print("DEBUG channelName", self.channelName, "uid", self.rtcId, "token", token) // works here
self.rtckit.joinChannel(byToken: token, channelId: self.channelName, info: nil, uid: self.rtcId) { (channel, uid, errCode) in
print("DEBUG Inside AgoraObservable rtckit.joinChannel()") // Doesn't work here
self.rtcId = uid
self.channel = self.rtmkit?.createChannel(withId: self.channelName, delegate: self)
self.channel?.join(completion: { joinStatus in
print("DEBUG Inside self.channel?.join")
if joinStatus == .channelErrorOk {
let user = AgoraUserData(rtmId: self.rtmId, rtcId: self.rtcId, username: self.username)
guard let jsonString = try? user.toJSONString() else {
return
}
self.membersLookup[user.rtmId] = (user.rtcId, user.username)
self.channel?.send(AgoraRtmMessage(text: jsonString))
} else {
self.channel = nil
}
})
}
and
// Works here
messagesRequest.fetchPrevious(onSuccess: { (messages) in
// Doesn't work here
for message in messages!{
if let receivedMessage = (message as ? TextMessage) {
print("Message received successfully. " + receivedMessage.stringValue())
}
else if let receivedMessage = (message as ? MediaMessage) {
print("Message received successfully. " + receivedMessage!.stringValue())
}
}
}) { (error) in
print("Message receiving failed with error: " + error!.errorDescription);
}