fix: bot name and id return, websocket
Build & Test (NowChessSystems) TeamCity build failed

This commit is contained in:
Lala, Shahd
2026-05-31 21:28:04 +00:00
parent 5c586b9003
commit fd6698c7a7
6 changed files with 21 additions and 7 deletions
@@ -96,6 +96,8 @@ class GameWebSocketResource:
private def resolvePlayerId(handshake: HandshakeRequest): Option[String] =
Option(handshake.header("Authorization"))
.filter(_.nonEmpty)
.map(h => if h.startsWith("Bearer ") then h.drop(7) else h)
.orElse(Option(handshake.query("token")).filter(_.nonEmpty))
.flatMap(token => Try(jwtParser.parse(token)).toOption)
.map(_.getSubject)
@@ -35,8 +35,7 @@ class UserWebSocketResource:
@OnOpen
def onOpen(connection: WebSocketConnection, handshake: HandshakeRequest): Unit =
val userIdOpt = Option(handshake.header("Authorization"))
.filter(_.nonEmpty)
val userIdOpt = resolveToken(handshake)
.flatMap(token => Try(jwtParser.parse(token)).toOption)
.map(_.getSubject)
@@ -52,6 +51,12 @@ class UserWebSocketResource:
val connectedMsg = s"""{"type":"CONNECTED","userId":"$userId"}"""
connection.sendText(connectedMsg).subscribe().`with`(_ => (), _ => ())
private def resolveToken(handshake: HandshakeRequest): Option[String] =
Option(handshake.header("Authorization"))
.filter(_.nonEmpty)
.map(h => if h.startsWith("Bearer ") then h.drop(7) else h)
.orElse(Option(handshake.query("token")).filter(_.nonEmpty))
@OnClose
def onClose(connection: WebSocketConnection): Unit =
log.infof("User WebSocket closed — connectionId=%s", connection.id())