add Live Call debug logging for diagnosing connection issues

Logs WS URL, setup message, every server event (first 200 chars),
onOpen/onClosed/onFailure with codes, and service-level events.
Filter logcat by "LiveClient" or "LiveCallService".
This commit is contained in:
Bruno Deanoz 2026-06-24 12:49:11 +02:00
parent bf8e591930
commit 408cdaa72d
2 changed files with 25 additions and 8 deletions

View file

@ -125,6 +125,7 @@ class LiveCallService : Service() {
}
}
Log.i(TAG, "startCall model=$model voice=$voice convId=$conversationId baseUrl=$baseUrl")
liveClient.connect(model, voice, conversationId)
}
@ -163,6 +164,7 @@ class LiveCallService : Service() {
private fun handleEvent(event: ServerEvent, pipeline: AudioPipeline) {
when (event) {
is ServerEvent.Ready -> {
Log.i(TAG, "EVENT Ready sessionId=${event.sessionId}")
connectTimeoutJob?.cancel()
_status.value = CallStatus.LISTENING
@ -241,6 +243,7 @@ class LiveCallService : Service() {
}
is ServerEvent.Error -> {
Log.e(TAG, "EVENT Error code=${event.code} msg=${event.message}")
_subtitle.value = event.message ?: event.code
onError?.invoke(event.code, event.message)
if (event.code in setOf("auth_failed", "restricted_model", "restricted_feature", "budget_exceeded", "concurrent_limit", "provider_error", "reconnect_failed")) {

View file

@ -69,6 +69,7 @@ class LiveClient(
active = true
pendingSetup = SetupParams(model, voice, conversationId)
reconnectAttempts.set(0)
Log.i(TAG, "connect() model=$model voice=$voice convId=$conversationId baseUrl=$baseUrl")
openSocket()
}
@ -79,9 +80,11 @@ class LiveClient(
.replace("https://", "wss://")
.replace("http://", "ws://") + "/ws/live"
Log.i(TAG, "openSocket() url=$wsUrl")
val request = Request.Builder()
.url(wsUrl)
.header("Authorization", "Bearer $token")
.header("Authorization", "Bearer ${token.take(10)}")
.build()
val socket = client.newWebSocket(request, Listener())
@ -140,20 +143,31 @@ class LiveClient(
private inner class Listener : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {
Log.d(TAG, "WebSocket opened")
Log.i(TAG, "onOpen HTTP=${response.code}")
reconnectAttempts.set(0)
val sid = sessionId.get()
if (sid != null) {
webSocket.send(encodeResume(sid, lastSeqId.get()))
val msg = encodeResume(sid, lastSeqId.get())
Log.i(TAG, ">> resume sid=$sid")
webSocket.send(msg)
} else {
val setup = pendingSetup ?: return
webSocket.send(encodeSetup(setup.model, setup.voice, setup.conversationId))
val setup = pendingSetup ?: run {
Log.w(TAG, "onOpen but no pendingSetup!")
return
}
val msg = encodeSetup(setup.model, setup.voice, setup.conversationId)
Log.i(TAG, ">> setup model=${setup.model} voice=${setup.voice} convId=${setup.conversationId}")
webSocket.send(msg)
}
}
override fun onMessage(webSocket: WebSocket, text: String) {
val event = parseServerEvent(text) ?: return
Log.d(TAG, "<< ${text.take(200)}")
val event = parseServerEvent(text) ?: run {
Log.w(TAG, "Failed to parse server event")
return
}
when (event) {
is ServerEvent.Ready -> {
@ -197,13 +211,13 @@ class LiveClient(
}
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
Log.d(TAG, "WebSocket closed: $code $reason")
Log.w(TAG, "onClosed code=$code reason=$reason")
ws.compareAndSet(webSocket, null)
if (active && code != 1000) scheduleReconnect()
}
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Log.w(TAG, "WebSocket failure: ${t.message}")
Log.e(TAG, "onFailure: ${t::class.simpleName}: ${t.message} httpCode=${response?.code}")
ws.compareAndSet(webSocket, null)
if (active) scheduleReconnect()
}