Skip to content

Commit 565db30

Browse files
committed
Move token inside preconnect
1 parent 6cb1a38 commit 565db30

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/LiveKit/Agent/Session.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,20 @@ open class Session: ObservableObject {
239239
}
240240
}
241241

242-
do {
243-
let response = try await fetchToken()
242+
let connect = { @Sendable in
243+
let response = try await self.fetchToken()
244+
try await self.room.connect(url: response.serverURL.absoluteString,
245+
token: response.participantToken)
246+
}
244247

248+
do {
245249
if options.preConnectAudio {
246250
try await room.withPreConnectAudio(timeout: timeout) {
247251
await MainActor.run { self.agent.listening() }
248-
try await self.room.connect(url: response.serverURL.absoluteString,
249-
token: response.participantToken)
252+
try await connect()
250253
}
251254
} else {
252-
try await room.connect(url: response.serverURL.absoluteString,
253-
token: response.participantToken)
255+
try await connect()
254256
}
255257
} catch {
256258
self.error = .failedToConnect(error)

0 commit comments

Comments
 (0)