-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIKitCallViewController.swift
47 lines (39 loc) · 1.13 KB
/
UIKitCallViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import UIKit
import Vapi
class CallViewController: UIViewController {
private var vapi: Vapi?
override func viewDidLoad() {
super.viewDidLoad()
setupVapi()
}
private func setupVapi() {
let config = Vapi.Configuration(publicKey: "your_public_key")
vapi = Vapi(configuration: config)
vapi?.eventPublisher.sink { [weak self] event in
switch event {
case .callDidStart:
self?.updateUIForCallStart()
case .callDidEnd:
self?.updateUIForCallEnd()
default:
break
}
}.store(in: &cancellables)
}
@IBAction func startCallPressed(_ sender: UIButton) {
do {
try vapi?.start(assistantId: "your_assistant_id")
} catch {
print("Error starting call: \(error)")
}
}
@IBAction func stopCallPressed(_ sender: UIButton) {
vapi?.stop()
}
private func updateUIForCallStart() {
// Update UI to show call has started
}
private func updateUIForCallEnd() {
// Update UI to show call has ended
}
}