-
Notifications
You must be signed in to change notification settings - Fork 0
Opening Chat
This guide will show you how to interact with the ChatViewController. If you are integrating a 3.x version of the SDK you should take a look at this guide instead.
The ChatViewController is the UI component responsible for presenting the user interface of a chat. These are the steps you need to take in order to present it:
- Connect the SDK
- Create an instance.
- Present the user interface
From now on we are assuming you read the previous guides regarding the conference object.
Assuming the SDK is properly configured, you are required to connect it in order to present the chat user interface.
import UIKit
import KaleyraVideoSDK
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var config = Config(appID: "My app id", region: .europe, environment: .sandbox)
config.callKit = .enabled(.init(icon: UIImage(named: "callkit-icon")))
config.voip = .automatic(listenForNotificationsInForeground: false)
do {
try KaleyraVideo.instance.configure(config)
try KaleyraVideo.instance.connect(userId: "USER ALIAS", provider: RestAccessTokenProvider())
} catch {
print("Could not configure the SDK because of \(error)")
}
return true
}
}
In order to tell the SDK who you want to chat with, you must create a ChatViewController instance. You must provide this object the user id for the user you want to chat with, or the id of a chat. You should also provide a configuration object if you want to customize which buttons should be presented in its navigation bar.
let controller = ChatViewController(intent: .chat(participant: "alice"), configuration: .init(audioButton: true, videoButton: true))
Once you have created a ChatViewController instance you can present it modally and respond to its events subscribing as its delegate.
final class MyViewController: UIViewController {
func openChat(with user: String) {
let controller = ChatViewController(intent: .chat(participant: user), configuration: .init(audioButton: true, videoButton: true))
controller.delegate = self
self.controller.present(controller, animated: true)
}
}
extension MyViewController: ChatViewControllerDelegate {
func chatViewControllerDidFinish(_ controller: ChatViewController) {
controller.dismiss(animated: true)
}
func chatViewControllerDidTapAudioCallButton(_ controller: ChatViewController) {
print("Start a voice call with \(controller.participants)")
}
func chatViewControllerDidTapVideoCallButton(_ controller: ChatViewController) {
print("Start a video call with \(controller.participants)")
}
}
That's it! the steps you've seen are the only steps required to start sending/receiving messages.
The next guide In-app notifications will teach you how to show an in-app notification every time a message is received. Also, if you haven't already, we suggest you to take a look at our sample app to see how to start sending/receiving messages in a real app.
Looking for other platforms? Take a look at Android, Flutter, ReactNative, Ionic / Cordova. Anything unclear or inaccurate? Please let us know by submitting an Issue or write us here.