Skip to content

Instantly share code, notes, and snippets.

@zontan
Created September 23, 2019 18:56
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/04e6a54072fc2a578275b70ea0ae88cd to your computer and use it in GitHub Desktop.
Save zontan/04e6a54072fc2a578275b70ea0ae88cd to your computer and use it in GitHub Desktop.
var handle: AuthStateDidChangeListenerHandle?
var userName: String?
var channelName = "default"
override func viewDidAppear(_ animated: Bool) {
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
if user == nil {
self.navigationController?.popToRootViewController(animated: true)
} else {
self.userName = user?.displayName
}
}
joinChannel()
}
override func viewWillDisappear(_ animated: Bool) {
leaveChannel()
if let handle = handle {
Auth.auth().removeStateDidChangeListener(handle)
}
}
func setUserName(name: String?) {
userName = name
if let name = name {
getAgoraEngine().registerLocalUserAccount(name, appId: appID)
}
}
func setChannelName(channel: String) {
channelName = channel
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment