diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2020-12-12 19:56:08 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2020-12-12 19:56:08 +0100 |
commit | 2670da7aa033cd18d38d697739d04ca758008d41 (patch) | |
tree | 3a65dd02d07d58d9717e1f5349fa155b87209769 /sw-client/src/commonMain/kotlin/org | |
parent | Improve logs (diff) | |
download | seven-wonders-2670da7aa033cd18d38d697739d04ca758008d41.tar.gz seven-wonders-2670da7aa033cd18d38d697739d04ca758008d41.tar.bz2 seven-wonders-2670da7aa033cd18d38d697739d04ca758008d41.zip |
Cleanup helper method in sw-client
Diffstat (limited to 'sw-client/src/commonMain/kotlin/org')
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt index 02f7f2da..090d1ee2 100644 --- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt +++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt @@ -1,12 +1,9 @@ package org.luxons.sevenwonders.client -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map -import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.builtins.serializer import org.hildan.krossbow.stomp.StompClient import org.hildan.krossbow.stomp.config.HeartBeat @@ -39,33 +36,24 @@ class SevenWondersClient { } } -// TODO replace these calls by actual HTTP endpoints -@OptIn(ExperimentalCoroutinesApi::class) -private suspend inline fun <reified T : Any, reified U : Any> StompSessionWithKxSerialization.request( - sendDestination: String, - receiveDestination: String, - payload: T? = null, - serializer: SerializationStrategy<T>, - deserializer: DeserializationStrategy<U>, -): U { - val sub = subscribe(receiveDestination, deserializer) - convertAndSend(sendDestination, payload, serializer) - return sub.first() -} - class SevenWondersSession(private val stompSession: StompSessionWithKxSerialization) { suspend fun disconnect() = stompSession.disconnect() suspend fun watchErrors(): Flow<ErrorDTO> = stompSession.subscribe("/user/queue/errors", ErrorDTO.serializer()) - suspend fun chooseName(displayName: String, icon: Icon? = null): ConnectedPlayer = stompSession.request( - sendDestination = "/app/chooseName", - receiveDestination = "/user/queue/nameChoice", - payload = ChooseNameAction(displayName, icon), - serializer = ChooseNameAction.serializer(), - deserializer = ConnectedPlayer.serializer(), - ) + suspend fun chooseName(displayName: String, icon: Icon? = null): ConnectedPlayer { + val sub = stompSession.subscribe( + destination = "/user/queue/nameChoice", + deserializer = ConnectedPlayer.serializer(), + ) + stompSession.convertAndSend( + destination = "/app/chooseName", + body = ChooseNameAction(displayName, icon), + serializer = ChooseNameAction.serializer(), + ) + return sub.first() + } suspend fun watchGames(): Flow<GameListEvent> = stompSession.subscribe("/topic/games", GameListEventWrapper.serializer()).map { it.event } |