Skip to content

Commit 54aefa4

Browse files
committed
Naming and convenience
1 parent 8182fad commit 54aefa4

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

VoiceAgent/Agent/AgentSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class AgentSession: ObservableObject {
1212

1313
@Published private(set) var connectionState: ConnectionState = .disconnected
1414
@Published private(set) var isListening = false
15-
var isAvailable: Bool {
15+
var isReady: Bool {
1616
switch connectionState {
1717
case .disconnected where isListening,
1818
.connecting where isListening,

VoiceAgent/App/AppView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct AppView: View {
99

1010
var body: some View {
1111
ZStack(alignment: .top) {
12-
if session.isAvailable {
12+
if session.isReady {
1313
interactions()
1414
} else {
1515
start()
@@ -20,7 +20,7 @@ struct AppView: View {
2020
.environment(\.namespace, namespace)
2121
#if os(visionOS)
2222
.ornament(attachmentAnchor: .scene(.bottom)) {
23-
if session.isAvailable {
23+
if session.isReady {
2424
ControlBar(chat: $chat)
2525
.glassBackgroundEffect()
2626
}
@@ -31,15 +31,15 @@ struct AppView: View {
3131
}
3232
#else
3333
.safeAreaInset(edge: .bottom) {
34-
if session.isAvailable, !keyboardFocus {
34+
if session.isReady, !keyboardFocus {
3535
ControlBar(chat: $chat)
3636
.transition(.asymmetric(insertion: .move(edge: .bottom).combined(with: .opacity), removal: .opacity))
3737
}
3838
}
3939
#endif
4040
.background(.bg1)
4141
.animation(.default, value: chat)
42-
.animation(.default, value: session.isAvailable)
42+
.animation(.default, value: session.isReady)
4343
.animation(.default, value: session.isCameraEnabled)
4444
.animation(.default, value: session.isScreenShareEnabled)
4545
.animation(.default, value: session.error?.localizedDescription)

VoiceAgent/Participant/AgentParticipantView.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct AgentParticipantView: View {
3838
barMinOpacity: 0.1)
3939
.frame(maxWidth: 75 * .grid, maxHeight: 48 * .grid)
4040
.transition(.opacity)
41-
} else if session.isAvailable {
41+
} else if session.isReady {
4242
BarAudioVisualizer(audioTrack: nil,
4343
agentState: .listening,
4444
barCount: 1,
@@ -51,3 +51,16 @@ struct AgentParticipantView: View {
5151
.matchedGeometryEffect(id: "agent", in: namespace!)
5252
}
5353
}
54+
55+
extension BarAudioVisualizer {
56+
init(agent: Agent?,
57+
barColor: Color = .primary,
58+
barCount: Int = 5,
59+
barCornerRadius: CGFloat = 100,
60+
barSpacingFactor: CGFloat = 0.015,
61+
barMinOpacity: CGFloat = 0.16,
62+
isCentered: Bool = true)
63+
{
64+
self.init(audioTrack: agent?.firstAudioTrack, agentState: agent?.agentState ?? .listening, barColor: barColor, barCount: barCount, barCornerRadius: barCornerRadius, barSpacingFactor: barSpacingFactor, barMinOpacity: barMinOpacity, isCentered: isCentered)
65+
}
66+
}

0 commit comments

Comments
 (0)