-
Notifications
You must be signed in to change notification settings - Fork 0
Making an outgoing call
This guide will show you how to make an outgoing call and how to present the call UI using the Kaleyra Video iOS SDK 4.x version. If you are looking for the 3.x version guide take a look here.
- Overview
- Connect the SDK
- Create an outgoing call
- Present the call user interface
- Where to go from here
- What's next
Making an outgoing call with the Kaleyra Video iOS SDK it's a simple and straightforward process. It requires you to do make few simple steps in your code to setup the call and the SDK will take care of the rest. From now on we are assuming you read the previous guides regarding the conference object and its lifecycle.
The steps required to place an outgoing call are the following:
- Connect the sdk
- Create an outgoing call
- Present the call user interface
Assuming the SDK is properly configured, you are required to connect it in order to start an outgoing call.
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 create a call you must get the conference object from the singleton instance, then you can create the call:
KaleyraVideo.instance.conference?.call(callees: ["alice", "bob"], options: .init(type: .audioVideo), chatId: nil) { result in
do {
try result.get()
debugPrint("Call created successfully")
} catch {
debugPrint("An error occurred while creating the call \(error)")
}
}
The conference call method takes several parameters:
- An array containing the id of the users you want to create a call with
- The options of the call
- The id of the chat associated with the call being created (if you don't provide an id a new chat will be created)
The CallOptions as the name implies contains the creation options for the call. Here's the options you can provide:
- Call type
- Recording type
- Maximum duration of the call
Here's an example showing you how to create an audio upgradable call with automatic recording and a maximum duration of 5 minutes:
KaleyraVideo.instance.conference?.call(callees: ["alice", "bob"], options: .init(type: .audioVideo, recording: .automatic, maxDuration: 300), chatId: nil) { result in
do {
try result.get()
debugPrint("Call created successfully")
} catch {
debugPrint("An error occurred while creating the call \(error)")
}
}
There are three call types supported:
- Audio / Video
- Audio Upgradable
- Audio Only
The audioVideo call type, as the name suggests, will make the Kaleyra Video iOS SDK start a video call. The audioOnly call type will make the Kaleyra Video iOS SDK start a voice call which cannot be updated to a video call. The audioUpgradable call type, is a special call type which will start as a voice call and can be upgraded to a video call at any time by one of the call participants.
You can provide three possible values:
- Automatic, the call will be recorded from start to end.
- Manual, the call will be recorded when the administrator of the call starts the recording until the administrator interrupts the recording.
- None (nil), the call won't be recorded
The maximum duration expressed in seconds after which the call will end. If you don't provide a duration, the call will end when all participants have left like a normal phone call.
The last step needed in order to show the call to the user is to present the call user interface. Let's pretend you have a view controller from which you want to present the call user interface; once the callPublisher emits a call object you can present the CallViewController associated with it:
import UIKit
import KaleyraVideoSDK
class MyViewController: UIViewController {
lazy var callWindow: CallWindow = .init(windowScene: view.window!.windowScene!)
override func viewDidLoad() {
super.viewDidLoad()
KaleyraVideo.instance.conference?.callPublisher.compactMap({ $0 }).receive(on: DispatchQueue.main).sink { [weak self] call in
self?.presentCall(call)
}.store(in: &subscriptions)
}
private func present(call: Call) {
let controller = CallViewController(call: call, configuration: .init())
controller.delegate = self
callWindow.makeKeyAndVisible()
callWindow.set(rootViewController: controller, animated: true)
}
}
extension MyViewController: CallViewControllerDelegate {
func callViewControllerDidFinish(_ controller: CallViewController) {
callWindow.set(rootViewController: nil, animated: true) { _ in
self.callWindow.isHidden = true
}
}
}
That's it! the steps you've seen are the only steps required to make an outgoing call.
The next guide Receiving an incoming call will show you how to receive an incoming call. Also, if you haven't already, we suggest you to take a look at our sample app to see how to make an outgoing call 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.