-
-
Save zontan/a80c7021f586d04371d6125469d3e322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CustomAgoraViewController: UITextFieldDelegate { | |
func addMessage(user: String, message: String) { | |
let message = "\(user): \(message)" | |
messageList.append(message) | |
let indexPath = IndexPath(row: self.messageList.count-1, section: 0) | |
self.chatTableView.insertRows(at: [indexPath], with: UITableView.RowAnimation.automatic) | |
self.chatTableView.scrollToRow(at: indexPath, at: .bottom, animated: true) | |
} | |
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
if let text = textField.text, text != "" { | |
rtmChannel?.send(AgoraRtmMessage(text: text), completion: { (error) in | |
if error != .errorOk { | |
print("Failed to send message: ", error) | |
} else { | |
self.addMessage(user: self.currentUser!.displayName ?? self.currentUser!.uid, message: text) | |
} | |
}) | |
textField.text = "" | |
} | |
return true | |
} | |
} | |
extension CustomAgoraViewController: AgoraRtmChannelDelegate { | |
func channel(_ channel: AgoraRtmChannel, messageReceived message: AgoraRtmMessage, from member: AgoraRtmMember) { | |
addMessage(user: member.userId, message: message.text) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment