fix Live Call: 20s connect timeout + reconnect_failed ends call
CONNECTING state could hang forever if the server never responded or kept failing silently. Now: 20s timeout ends the call with a visible error, and reconnect_failed is treated as terminal.
This commit is contained in:
parent
57cc69c999
commit
bf8e591930
1 changed files with 14 additions and 1 deletions
|
|
@ -93,6 +93,8 @@ class LiveCallService : Service() {
|
||||||
|
|
||||||
// ─── Start / End ──────────────────────────────────────────────────────
|
// ─── Start / End ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private var connectTimeoutJob: Job? = null
|
||||||
|
|
||||||
fun startCall(baseUrl: String, token: String, model: String, voice: String, conversationId: String?) {
|
fun startCall(baseUrl: String, token: String, model: String, voice: String, conversationId: String?) {
|
||||||
if (_status.value != CallStatus.IDLE) return
|
if (_status.value != CallStatus.IDLE) return
|
||||||
|
|
||||||
|
|
@ -114,6 +116,15 @@ class LiveCallService : Service() {
|
||||||
|
|
||||||
pipeline.onChunk = { base64 -> liveClient.sendAudio(base64) }
|
pipeline.onChunk = { base64 -> liveClient.sendAudio(base64) }
|
||||||
|
|
||||||
|
connectTimeoutJob = scope.launch {
|
||||||
|
delay(20_000)
|
||||||
|
if (_status.value == CallStatus.CONNECTING) {
|
||||||
|
_subtitle.value = "Verbindung fehlgeschlagen"
|
||||||
|
onError?.invoke("timeout", "Connection timeout after 20s")
|
||||||
|
endCall()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
liveClient.connect(model, voice, conversationId)
|
liveClient.connect(model, voice, conversationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,6 +134,7 @@ class LiveCallService : Service() {
|
||||||
client?.end()
|
client?.end()
|
||||||
audio?.release()
|
audio?.release()
|
||||||
durationJob?.cancel()
|
durationJob?.cancel()
|
||||||
|
connectTimeoutJob?.cancel()
|
||||||
|
|
||||||
client?.dispose()
|
client?.dispose()
|
||||||
client = null
|
client = null
|
||||||
|
|
@ -151,6 +163,7 @@ class LiveCallService : Service() {
|
||||||
private fun handleEvent(event: ServerEvent, pipeline: AudioPipeline) {
|
private fun handleEvent(event: ServerEvent, pipeline: AudioPipeline) {
|
||||||
when (event) {
|
when (event) {
|
||||||
is ServerEvent.Ready -> {
|
is ServerEvent.Ready -> {
|
||||||
|
connectTimeoutJob?.cancel()
|
||||||
_status.value = CallStatus.LISTENING
|
_status.value = CallStatus.LISTENING
|
||||||
|
|
||||||
if (!pipeline.initPlayback()) {
|
if (!pipeline.initPlayback()) {
|
||||||
|
|
@ -230,7 +243,7 @@ class LiveCallService : Service() {
|
||||||
is ServerEvent.Error -> {
|
is ServerEvent.Error -> {
|
||||||
_subtitle.value = event.message ?: event.code
|
_subtitle.value = event.message ?: event.code
|
||||||
onError?.invoke(event.code, event.message)
|
onError?.invoke(event.code, event.message)
|
||||||
if (event.code in setOf("auth_failed", "restricted_model", "restricted_feature", "budget_exceeded", "concurrent_limit", "provider_error")) {
|
if (event.code in setOf("auth_failed", "restricted_model", "restricted_feature", "budget_exceeded", "concurrent_limit", "provider_error", "reconnect_failed")) {
|
||||||
endCall()
|
endCall()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue