Update the old / new UI to work with the server.

This commit is contained in:
Thomas Andres Gomez 2025-02-24 17:12:50 +01:00
parent bd4d65fe6a
commit ed1b27039d
40 changed files with 568 additions and 390 deletions

View file

@ -97,7 +97,7 @@ class CampaignService(
return true
}
// Data manipulation threw WebSocket.
// Data manipulation through WebSocket.
suspend fun updateCharacteristic(
characterId: String,

View file

@ -43,7 +43,7 @@ class CharacterSheetService(
return store.delete(id = characterId)
}
// Data manipulation threw WebSocket.
// Data manipulation through WebSocket.
fun updateCharacterLevel(
characterId: String,

View file

@ -17,9 +17,6 @@ class Engine(
suspend fun handle(message: Message) {
when (val data = message.value) {
RestSynchronisation.Campaign -> Unit // TODO
is RestSynchronisation.CharacterUpdate -> Unit // TODO
is RollMessage -> Unit // Nothing to do here.
@ -34,9 +31,11 @@ class Engine(
skillId = data.skillId
)
is RestSynchronisation.CharacterDelete -> characterService.deleteCharacter(
characterId = data.characterId,
)
RestSynchronisation.Campaign -> Unit // Handle in the Rest
is RestSynchronisation.CharacterUpdate -> Unit // Handle in the Rest
is RestSynchronisation.CharacterDelete -> Unit // Handle in the Rest
}
}
}

View file

@ -72,6 +72,33 @@ class LocalServer {
}
routing {
webSocket(
path = "/ws",
handler = {
val job = launch {
// send local message to the clients
engine.webSocket.collect { message ->
send(json.encodeToFrame(message))
}
}
runCatching {
// watching for clients incoming message
incoming.consumeEach { frame ->
if (frame is Frame.Text) {
val message = Json.decodeFromFrame(frame = frame)
// log the message
engine.handle(message)
// broadcast to clients the message
engine.webSocket.emit(message)
}
}
}.onFailure { exception ->
println("WebSocket exception: ${exception.localizedMessage}")
}.also {
job.cancel()
}
}
)
get(
path = "/characters",
body = engine.getCharacters(),
@ -116,33 +143,6 @@ class LocalServer {
)
}
}
webSocket(
path = "/ws",
handler = {
val job = launch {
// send local message to the clients
engine.webSocket.collect { message ->
send(json.encodeToFrame(message))
}
}
runCatching {
// watching for clients incoming message
incoming.consumeEach { frame ->
if (frame is Frame.Text) {
val message = Json.decodeFromFrame(frame = frame)
// log the message
engine.handle(message)
// broadcast to clients the message
engine.webSocket.emit(message)
}
}
}.onFailure { exception ->
println("WebSocket exception: ${exception.localizedMessage}")
}.also {
job.cancel()
}
}
)
}
}
)
@ -154,7 +154,6 @@ class LocalServer {
try {
server?.start(wait = true)
} catch (exception: Exception) {
// TODO
println("WebSocket exception: ${exception.localizedMessage}")
} finally {
println("Server close")