Skip to content

Commit d8a2e04

Browse files
committed
Make devices depend on session
1 parent f39e5da commit d8a2e04

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

VoiceAgent/Devices/DeviceSwitcher.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ final class DeviceSwitcher: ObservableObject {
4242
observeDevices()
4343
}
4444

45+
convenience init(agentSession: AgentSession) {
46+
self.init(room: agentSession._room)
47+
}
48+
4549
private func observeRoom() {
4650
Task { [weak self] in
4751
guard let changes = self?.room.changes else { return }

VoiceAgent/VoiceAgentApp.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ struct VoiceAgentApp: App {
66
// To use the LiveKit Cloud sandbox (development only)
77
// - Enable your sandbox here https://cloud.livekit.io/projects/p_/sandbox/templates/token-server
88
// - Create .env.xcconfig with your LIVEKIT_SANDBOX_ID
9-
private let sandboxID = Bundle.main.object(forInfoDictionaryKey: "LiveKitSandboxId") as! String
10-
private let room = Room(roomOptions: RoomOptions(defaultScreenShareCaptureOptions: ScreenShareCaptureOptions(useBroadcastExtension: true)))
9+
private static let sandboxId = Bundle.main.object(forInfoDictionaryKey: "LiveKitSandboxId") as! String
10+
private let session = AgentSession(credentials: Sandbox(id: Self.sandboxId),
11+
room: Room(roomOptions: RoomOptions(defaultScreenShareCaptureOptions: ScreenShareCaptureOptions(useBroadcastExtension: true))))
1112

1213
var body: some Scene {
1314
WindowGroup {
1415
AppView()
15-
.environmentObject(DeviceSwitcher(room: room))
16-
.environmentObject(AgentSession(credentials: Sandbox(id: sandboxID), room: room))
16+
.environmentObject(session)
17+
.environmentObject(DeviceSwitcher(agentSession: session))
1718
}
1819
#if os(macOS)
1920
.defaultSize(width: 900, height: 900)

0 commit comments

Comments
 (0)