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:
parent
bf8e591930
commit
408cdaa72d
2 changed files with 25 additions and 8 deletions
|
|
@ -125,6 +125,7 @@ class LiveCallService : Service() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "startCall model=$model voice=$voice convId=$conversationId baseUrl=$baseUrl")
|
||||||
liveClient.connect(model, voice, conversationId)
|
liveClient.connect(model, voice, conversationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,6 +164,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 -> {
|
||||||
|
Log.i(TAG, "EVENT Ready sessionId=${event.sessionId}")
|
||||||
connectTimeoutJob?.cancel()
|
connectTimeoutJob?.cancel()
|
||||||
_status.value = CallStatus.LISTENING
|
_status.value = CallStatus.LISTENING
|
||||||
|
|
||||||
|
|
@ -241,6 +243,7 @@ class LiveCallService : Service() {
|
||||||
}
|
}
|
||||||
|
|
||||||
is ServerEvent.Error -> {
|
is ServerEvent.Error -> {
|
||||||
|
Log.e(TAG, "EVENT Error code=${event.code} msg=${event.message}")
|
||||||
_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", "reconnect_failed")) {
|
if (event.code in setOf("auth_failed", "restricted_model", "restricted_feature", "budget_exceeded", "concurrent_limit", "provider_error", "reconnect_failed")) {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ class LiveClient(
|
||||||
active = true
|
active = true
|
||||||
pendingSetup = SetupParams(model, voice, conversationId)
|
pendingSetup = SetupParams(model, voice, conversationId)
|
||||||
reconnectAttempts.set(0)
|
reconnectAttempts.set(0)
|
||||||
|
Log.i(TAG, "connect() model=$model voice=$voice convId=$conversationId baseUrl=$baseUrl")
|
||||||
openSocket()
|
openSocket()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,9 +80,11 @@ class LiveClient(
|
||||||
.replace("https://", "wss://")
|
.replace("https://", "wss://")
|
||||||
.replace("http://", "ws://") + "/ws/live"
|
.replace("http://", "ws://") + "/ws/live"
|
||||||
|
|
||||||
|
Log.i(TAG, "openSocket() url=$wsUrl")
|
||||||
|
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(wsUrl)
|
.url(wsUrl)
|
||||||
.header("Authorization", "Bearer $token")
|
.header("Authorization", "Bearer ${token.take(10)}…")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val socket = client.newWebSocket(request, Listener())
|
val socket = client.newWebSocket(request, Listener())
|
||||||
|
|
@ -140,20 +143,31 @@ class LiveClient(
|
||||||
private inner class Listener : WebSocketListener() {
|
private inner class Listener : WebSocketListener() {
|
||||||
|
|
||||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||||
Log.d(TAG, "WebSocket opened")
|
Log.i(TAG, "onOpen HTTP=${response.code}")
|
||||||
reconnectAttempts.set(0)
|
reconnectAttempts.set(0)
|
||||||
|
|
||||||
val sid = sessionId.get()
|
val sid = sessionId.get()
|
||||||
if (sid != null) {
|
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 {
|
} else {
|
||||||
val setup = pendingSetup ?: return
|
val setup = pendingSetup ?: run {
|
||||||
webSocket.send(encodeSetup(setup.model, setup.voice, setup.conversationId))
|
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) {
|
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) {
|
when (event) {
|
||||||
is ServerEvent.Ready -> {
|
is ServerEvent.Ready -> {
|
||||||
|
|
@ -197,13 +211,13 @@ class LiveClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
|
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)
|
ws.compareAndSet(webSocket, null)
|
||||||
if (active && code != 1000) scheduleReconnect()
|
if (active && code != 1000) scheduleReconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
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)
|
ws.compareAndSet(webSocket, null)
|
||||||
if (active) scheduleReconnect()
|
if (active) scheduleReconnect()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue