-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.swift
70 lines (63 loc) · 1.96 KB
/
View.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// View.swift
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = RealtimeViewModel()
var body: some View {
NavigationView {
VStack {
Text("Status: \(viewModel.connectionStatus)")
.font(.headline)
.padding()
ScrollView {
VStack(alignment: .leading) {
ForEach(viewModel.conversation) { item in
MessageView(item: item)
}
}
}
Spacer() // Push the button to the bottom
Button(action: {
viewModel.toggleMute()
}) {
if viewModel.isMuted {
Image(systemName: "mic.slash.fill")
.font(.largeTitle)
.foregroundColor(.red)
} else {
Image(systemName: "mic.fill")
.font(.largeTitle)
.foregroundColor(.blue)
}
}
.padding()
}
.navigationTitle("Realtime AI")
.onAppear {
viewModel.connect()
}
}
}
}
struct MessageView: View {
var item: ConversationItem
var body: some View {
HStack {
if item.role == "user" {
Spacer()
Text(item.text ?? "")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
} else {
Text(item.text ?? "")
.padding()
.background(Color.gray)
.foregroundColor(.white)
.cornerRadius(10)
Spacer()
}
}
.padding(.horizontal)
}
}