1

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);
}
Asperi
  • 228,894
  • 20
  • 464
  • 690
Kanzafarov S.
  • 43
  • 1
  • 3
  • could you add what the first print fires? And the callback at the end of joinChannel never fires at all? it should reach there and have a value in errCode that might tell you why it doesn't fire. – maxxfrazer Jul 13 '21 at 16:30
  • Make sure that your channel name, app ID, and token are all valid – maxxfrazer Jul 13 '21 at 16:31

0 Answers0