debugs...

This commit is contained in:
dalbodeule 2024-11-25 19:56:22 +09:00
parent 9396e69570
commit 768eadd561
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65

View File

@ -65,7 +65,7 @@ fun Routing.wsSongListRoutes() {
} }
delay(100) // Check every 100 ms delay(100) // Check every 100 ms
} }
return false // Timeout return false // Timeout
} }
suspend fun sendWithRetry(uid: String, res: SongResponse, maxRetries: Int = 5, delayMillis: Long = 3000L) { suspend fun sendWithRetry(uid: String, res: SongResponse, maxRetries: Int = 5, delayMillis: Long = 3000L) {
@ -75,11 +75,15 @@ fun Routing.wsSongListRoutes() {
while (attempt < maxRetries && !sentSuccessfully) { while (attempt < maxRetries && !sentSuccessfully) {
val ws = sessions[uid] val ws = sessions[uid]
try { try {
if(ws == null) {
delay(delayMillis)
continue
}
// Attempt to send the message // Attempt to send the message
ws?.sendSerialized(res) ws.sendSerialized(res)
logger.debug("Message sent successfully to $uid on attempt $attempt") logger.debug("Message sent successfully to $uid on attempt $attempt")
// Wait for ACK // Wait for ACK
val ackReceived = ws?.let { waitForAck(it, res.type) } val ackReceived = waitForAck(ws, res.type)
if (ackReceived == true) { if (ackReceived == true) {
sentSuccessfully = true sentSuccessfully = true
} else { } else {
@ -129,7 +133,7 @@ fun Routing.wsSongListRoutes() {
for (frame in incoming) { for (frame in incoming) {
when (frame) { when (frame) {
is Text -> { is Text -> {
if (frame.readText() == "ping") { if (frame.readText().trim() == "ping") {
send("pong") send("pong")
} else { } else {
val data = frame.readText().let { Json.decodeFromString<SongRequest>(it) } val data = frame.readText().let { Json.decodeFromString<SongRequest>(it) }