Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zontan
Last active July 9, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zontan/6c53dbf89558fb4bf9ced995e6ff767c to your computer and use it in GitHub Desktop.
Save zontan/6c53dbf89558fb4bf9ced995e6ff767c to your computer and use it in GitHub Desktop.
var agoraRtm: AgoraRtmKit?
override func viewDidLoad() {
...
agoraRtm = AgoraRtmKit.init(appId: appID, delegate: self)
}
override func viewWillAppear(_ animated: Bool) {
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
self.currentUser = user
if let user = user {
self.joinChannel(channelName: user.uid)
self.agoraRtm?.login(byToken: nil, user: user.displayName ?? user.uid) { (error) in
if (error != .ok) {
print("Failed to login to RTM: ", error.rawValue)
}
}
} else {
self.agoraRtm?.logout(completion: nil)
self.showFUIAuthScreen()
}
}
}
...
extension AgoraVideoViewController: AgoraRtmDelegate {
func rtmKit(_ kit: AgoraRtmKit, connectionStateChanged state: AgoraRtmConnectionState, reason: AgoraRtmConnectionChangeReason) {
if state == .connected {
chatButton.isEnabled = true
} else {
chatButton.isEnabled = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment