Skip to content

Commit 72c33d7

Browse files
committed
Use apiConfig endpoint
1 parent 7d6b4de commit 72c33d7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

FirebaseAI/Sources/Types/Internal/Live/LiveSessionService.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ actor LiveSessionService {
308308
///
309309
/// Will apply the required app check and auth headers, as the backend expects them.
310310
private nonisolated func createWebsocket() async throws -> AsyncWebSocket {
311+
let host = apiConfig.service.endpoint.rawValue.withoutPrefix("https://")
311312
let urlString = switch apiConfig.service {
312313
case .vertexAI:
313-
"wss://firebasevertexai.googleapis.com/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/us-central1"
314+
"wss://\(host)/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/us-central1"
314315
case .googleAI:
315-
"wss://firebasevertexai.googleapis.com/ws/google.firebase.vertexai.v1beta.GenerativeService/BidiGenerateContent"
316+
"wss://\(host)/ws/google.firebase.vertexai.v1beta.GenerativeService/BidiGenerateContent"
316317
}
317318
guard let url = URL(string: urlString) else {
318319
throw NSError(
@@ -378,3 +379,16 @@ private extension Data {
378379
}
379380
}
380381
}
382+
383+
private extension String {
384+
/// Create a new string with the given prefix removed, if it's present.
385+
///
386+
/// If the prefix isn't present, this string will be returned instead.
387+
func withoutPrefix(_ prefix: String) -> String {
388+
if let index = range(of: prefix, options: .anchored) {
389+
return String(self[index.upperBound...])
390+
} else {
391+
return self
392+
}
393+
}
394+
}

0 commit comments

Comments
 (0)