Nicolas
06/23/2025, 10:54 AMfun Application.configureWebSocket(){
    install(WebSockets) {
        pingPeriod = 15.seconds
        timeout = 15.seconds
        maxFrameSize = kotlin.Long.MAX_VALUE
        masking = false
    }
}routing {
    webSocket("ws") {
        val token = call.request.queryParameters["token"]
        if (token == null) {
            close(CloseReason(CloseReason.Codes.VIOLATED_POLICY, "No Token"))
            return@webSocket
        }
        val decodedJWT = try { JwtFactory.buildverifier().verify(token) }
        catch (e: Exception) {
            close(CloseReason(CloseReason.Codes.VIOLATED_POLICY, "Invalid Token: ${e.message}"))
            return@webSocket
        }
        val userId: UUID = try { UUID.fromString(decodedJWT.getClaim(JwtClaimConstant.claimUserId).asString())  }
        catch (e: Exception) {
            close(CloseReason(CloseReason.Codes.VIOLATED_POLICY, "Invalid Token: ${e.message}"))
            return@webSocket
        }
        val sessionId = decodedJWT.id?.let {
            runCatching { UUID.fromString(it) }.getOrNull()
        } ?: run {
            close(CloseReason(CloseReason.Codes.VIOLATED_POLICY, "Invalid or missing sessionId (jti)"))
            return@webSocket
        }
        <http://logger.info|logger.info>("$userId is connected")
        try {
            println("$userId start")
            incoming.consumeEach {
                when (it) {
                    is Frame.Text -> {
                        val text = it.readText()
                        println("tototot $userId Received: $text")
                    }
                    is Frame.Close -> {
                        println("tototot $userId WebSocket closed by server with reason: ${it.readReason()}")
                    }
                    is Frame.Ping -> {
                        println("tototot $userId ping: $it")
                    }
                    is Frame.Pong -> {
                        println("tototot $userId pong: $it")
                    }  else -> {
                        println("tototot $userId else: $it")
                    }
                }
            }
        } catch (e: Exception) {
            println("$userId error $e")
         } finally {
            println("$userId finally remove")
        }
        println("$userId end")
    }
}Aleksei Tirman [JB]
06/25/2025, 8:42 AMNicolas
06/25/2025, 11:52 AMNicolas
06/25/2025, 11:53 AMNicolas
06/25/2025, 11:54 AMAleksei Tirman [JB]
06/25/2025, 3:01 PMNicolas
06/25/2025, 3:02 PMAleksei Tirman [JB]
06/25/2025, 3:04 PMNicolas
06/25/2025, 3:04 PMNicolas
06/25/2025, 3:04 PMAleksei Tirman [JB]
06/26/2025, 8:39 AMNicolas
06/30/2025, 6:25 AMNicolas
06/30/2025, 6:25 AMNicolas
06/30/2025, 6:25 AMNicolas
06/30/2025, 6:26 AMNicolas
06/30/2025, 6:26 AMAleksei Tirman [JB]
06/30/2025, 8:55 AMNicolas
06/30/2025, 9:44 AM