Skip to content

Commit ba2d338

Browse files
committed
fix: update SDK
1 parent 11ccaa4 commit ba2d338

File tree

7 files changed

+81
-34
lines changed

7 files changed

+81
-34
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
),
2020
],
2121
dependencies: [
22-
.package(url: "https://github.com/livekit/client-sdk-swift.git", from: "2.6.0"),
22+
.package(url: "https://github.com/livekit/client-sdk-swift.git", from: "2.10.0"),
2323
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.4.3"),
2424
],
2525
targets: [

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
),
2020
],
2121
dependencies: [
22-
.package(url: "https://github.com/livekit/client-sdk-swift.git", from: "2.6.0"),
22+
.package(url: "https://github.com/livekit/client-sdk-swift.git", from: "2.10.0"),
2323
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.4.3"),
2424
],
2525
targets: [

Sources/ElevenLabsComponents/Scopes/ComponentsScope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public extension EnvironmentValues {
2525
#else
2626
private struct UIOptionsKey: EnvironmentKey {
2727
// This is the default value that SwiftUI will fallback to if you don't pass the object
28-
public static var defaultValue: UIOptions = .init()
28+
static var defaultValue: UIOptions = .init()
2929
}
3030

3131
public extension EnvironmentValues {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Original work Copyright 2024 LiveKit, Inc.
3+
* Modifications Copyright 2025 Eleven Labs Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import Foundation
19+
import LiveKit
20+
21+
/// A richer agent state enum specifically for visualizer animations.
22+
/// This enum preserves the full set of states needed for detailed visual feedback,
23+
/// independent of the simplified SDK's `AgentState` enum.
24+
public enum VisualizerAgentState: Sendable, Equatable {
25+
/// Agent is connecting to the session
26+
case connecting
27+
/// Agent is initializing
28+
case initializing
29+
/// Agent is listening to user input
30+
case listening
31+
/// Agent is processing/thinking
32+
case thinking
33+
/// Agent is speaking
34+
case speaking
35+
/// Agent is disconnected
36+
case disconnected
37+
/// Unknown or unspecified state
38+
case unknown
39+
40+
/// Initialize from SDK's AgentState, mapping simplified states to visualizer states
41+
public init(from sdkState: AgentState) {
42+
switch sdkState {
43+
case .listening:
44+
self = .listening
45+
case .speaking:
46+
self = .speaking
47+
@unknown default:
48+
self = .unknown
49+
}
50+
}
51+
}

Sources/ElevenLabsComponents/UI/Participant/ParticipantView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public struct ParticipantView: View {
3838
} else if let microphoneTrack = microphoneReference.resolve(), !microphoneTrack.isMuted,
3939
let audioTrack = microphoneTrack.track as? AudioTrack
4040
{
41-
BarAudioVisualizer(audioTrack: audioTrack, agentState: _participant.agentState).id(_participant.agentState)
41+
BarAudioVisualizer(audioTrack: audioTrack, agentState: VisualizerAgentState(from: _participant.agentState)).id(_participant.agentState)
4242
} else {
4343
_ui.noTrackView()
4444
}

Sources/ElevenLabsComponents/UI/Visualizer/BarAudioVisualizer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import SwiftUI
3232
/// Usage:
3333
/// ```
3434
/// let audioTrack: AudioTrack = ...
35-
/// let agentState: AgentState = ...
35+
/// let agentState: VisualizerAgentState = ...
3636
/// BarAudioVisualizer(audioTrack: audioTrack, agentState: agentState)
3737
/// ```
3838
///
@@ -60,7 +60,7 @@ public struct BarAudioVisualizer: View {
6060
public let barMinOpacity: Double
6161
public let isCentered: Bool
6262

63-
private let agentState: AgentState
63+
private let agentState: VisualizerAgentState
6464

6565
@StateObject private var audioProcessor: AudioProcessor
6666

@@ -69,7 +69,7 @@ public struct BarAudioVisualizer: View {
6969
@State private var animationTask: Task<Void, Never>?
7070

7171
public init(audioTrack: AudioTrack?,
72-
agentState: AgentState = .unknown,
72+
agentState: VisualizerAgentState = .unknown,
7373
barColor: Color = .primary,
7474
barCount: Int = 5,
7575
barCornerRadius: CGFloat = 100,
@@ -163,17 +163,17 @@ extension BarAudioVisualizer {
163163
self.barCount = barCount
164164
}
165165

166-
func duration(agentState: AgentState) -> TimeInterval {
166+
func duration(agentState: VisualizerAgentState) -> TimeInterval {
167167
switch agentState {
168168
case .connecting, .initializing: 2 / Double(barCount)
169169
case .listening: 0.5
170170
case .thinking: 0.15
171171
case .speaking: veryLongDuration
172-
default: veryLongDuration
172+
case .unknown, .disconnected: veryLongDuration
173173
}
174174
}
175175

176-
func highlightingSequence(agentState: AgentState) -> [HighlightedBars] {
176+
func highlightingSequence(agentState: VisualizerAgentState) -> [HighlightedBars] {
177177
switch agentState {
178178
case .connecting, .initializing: (0 ..< barCount).map { HighlightedBars([$0, barCount - 1 - $0]) }
179179
case .thinking: Array((0 ..< barCount) + (0 ..< barCount).reversed()).map { HighlightedBars([$0]) }

Sources/ElevenLabsComponents/UI/Visualizer/OrbVisualizer.swift

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MetalOrbRenderer: NSObject, MTKViewDelegate {
7676

7777
private var uniforms = OrbUniforms()
7878
private var randomOffsets: [Float] = []
79-
private var currentAgentState: AgentState = .unknown
79+
private var currentAgentState: VisualizerAgentState = .unknown
8080

8181
// MARK: - Init
8282

@@ -104,7 +104,7 @@ class MetalOrbRenderer: NSObject, MTKViewDelegate {
104104
uniforms.outputVolume = max(0, min(1, output))
105105
}
106106

107-
func updateAgentState(_ state: AgentState) {
107+
func updateAgentState(_ state: VisualizerAgentState) {
108108
// No longer inverting colors for thinking state
109109
uniforms.inverted = 0
110110
currentAgentState = state
@@ -161,19 +161,17 @@ class MetalOrbRenderer: NSObject, MTKViewDelegate {
161161
// Try to load the Metal library from various sources
162162
var lib: MTLLibrary?
163163

164-
// First try the module bundle (for SwiftPM)
165-
#if SWIFT_PACKAGE
166-
lib = try? device.makeDefaultLibrary(bundle: Bundle.module)
167-
#endif
164+
// Try default library first (works when Metal files are properly compiled)
165+
lib = device.makeDefaultLibrary()
168166

169-
// If not found, try the main bundle
167+
// If that fails, try the class bundle
170168
if lib == nil {
171-
lib = try? device.makeDefaultLibrary(bundle: .main)
169+
lib = try? device.makeDefaultLibrary(bundle: Bundle(for: type(of: self)))
172170
}
173171

174-
// If still not found, try to create default library
172+
// If not found, try the main bundle
175173
if lib == nil {
176-
lib = device.makeDefaultLibrary()
174+
lib = try? device.makeDefaultLibrary(bundle: .main)
177175
}
178176

179177
guard let library = lib else {
@@ -205,7 +203,7 @@ struct _OrbPlatformView: NSViewRepresentable {
205203
var color2: Color
206204
var inputVolume: Float
207205
var outputVolume: Float
208-
var agentState: AgentState
206+
var agentState: VisualizerAgentState
209207

210208
func makeNSView(context: Context) -> MTKView {
211209
let view = MTKView()
@@ -233,7 +231,7 @@ struct _OrbPlatformView: NSViewRepresentable {
233231
}
234232

235233
final class Coordinator: MetalOrbRenderer {
236-
func updateAll(color1: Color, color2: Color, input: Float, output: Float, state: AgentState) {
234+
func updateAll(color1: Color, color2: Color, input: Float, output: Float, state: VisualizerAgentState) {
237235
updateColors(color1: color1, color2: color2)
238236
updateVolumes(input: input, output: output)
239237
updateAgentState(state)
@@ -246,7 +244,7 @@ struct _OrbPlatformView: UIViewRepresentable {
246244
var color2: Color
247245
var inputVolume: Float
248246
var outputVolume: Float
249-
var agentState: AgentState
247+
var agentState: VisualizerAgentState
250248

251249
func makeUIView(context: Context) -> MTKView {
252250
let view = MTKView()
@@ -274,7 +272,7 @@ struct _OrbPlatformView: UIViewRepresentable {
274272
}
275273

276274
final class Coordinator: MetalOrbRenderer {
277-
func updateAll(color1: Color, color2: Color, input: Float, output: Float, state: AgentState) {
275+
func updateAll(color1: Color, color2: Color, input: Float, output: Float, state: VisualizerAgentState) {
278276
updateColors(color1: color1, color2: color2)
279277
updateVolumes(input: input, output: output)
280278
updateAgentState(state)
@@ -288,9 +286,9 @@ public struct Orb: View {
288286
public var color2: Color
289287
public var inputVolume: Float
290288
public var outputVolume: Float
291-
public var agentState: AgentState
289+
public var agentState: VisualizerAgentState
292290

293-
public init(color1: Color, color2: Color, inputVolume: Float, outputVolume: Float, agentState: AgentState = .unknown) {
291+
public init(color1: Color, color2: Color, inputVolume: Float, outputVolume: Float, agentState: VisualizerAgentState = .unknown) {
294292
self.color1 = color1
295293
self.color2 = color2
296294
self.inputVolume = inputVolume
@@ -303,12 +301,12 @@ public struct Orb: View {
303301
let side = max(1, min(geo.size.width, geo.size.height))
304302

305303
// Override input volume to 1.0 when thinking
306-
let effectiveInputVolume = agentState == .thinking ? 1.0 : inputVolume
304+
// (This line removed as per instructions)
307305

308306
_OrbPlatformView(
309307
color1: color1,
310308
color2: color2,
311-
inputVolume: effectiveInputVolume,
309+
inputVolume: inputVolume,
312310
outputVolume: outputVolume,
313311
agentState: agentState
314312
)
@@ -335,7 +333,7 @@ public struct Orb: View {
335333
/// ```
336334
/// let inputTrack: AudioTrack = ...
337335
/// let outputTrack: AudioTrack = ...
338-
/// let agentState: AgentState = ...
336+
/// let agentState: VisualizerAgentState = ...
339337
/// OrbVisualizer(inputTrack: inputTrack, outputTrack: outputTrack, agentState: agentState)
340338
/// ```
341339
///
@@ -352,13 +350,13 @@ public struct Orb: View {
352350
public struct OrbVisualizer: View {
353351
public let colors: (Color, Color)
354352

355-
private let agentState: AgentState
353+
private let agentState: VisualizerAgentState
356354

357355
@StateObject private var inputProcessor: AudioProcessor
358356
@StateObject private var outputProcessor: AudioProcessor
359357

360358
public init(inputTrack: AudioTrack?, outputTrack: AudioTrack?,
361-
agentState: AgentState = .unknown,
359+
agentState: VisualizerAgentState = .unknown,
362360
colors: (Color, Color) = (Color(red: 0.793, green: 0.863, blue: 0.988),
363361
Color(red: 0.627, green: 0.725, blue: 0.820)))
364362
{
@@ -374,8 +372,6 @@ public struct OrbVisualizer: View {
374372
let inputVolume = aggregateVolume(from: inputProcessor.bands)
375373
let outputVolume = aggregateVolume(from: outputProcessor.bands)
376374

377-
let effectiveInputVolume = agentState == .thinking ? 1.0 : Float(inputVolume)
378-
379375
Orb(color1: colors.0,
380376
color2: colors.1,
381377
inputVolume: Float(inputVolume),
@@ -423,7 +419,7 @@ public struct OrbVisualizer: View {
423419
struct OrbVisualizer_Previews: PreviewProvider {
424420
struct AnimatedOrbPreview: View {
425421
let isInput: Bool
426-
let agentState: AgentState
422+
let agentState: VisualizerAgentState
427423
let colors: (Color, Color)
428424

429425
@State private var volume: Float = 0.0

0 commit comments

Comments
 (0)