diff options
Diffstat (limited to 'sw-ui/src/main/kotlin')
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt index 5c426a51..7b56594c 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt @@ -22,8 +22,8 @@ typealias SwSagaContext = SagaContext<SwState, RAction, WrapperAction> @OptIn(ExperimentalCoroutinesApi::class) suspend fun SwSagaContext.rootSaga() = coroutineScope { val action = next<RequestChooseName>() - val serverHost = if (isProdEnv()) window.location.host else "localhost:8000" - val session = SevenWondersClient().connect(serverHost) + val serverUrl = sevenWondersWebSocketUrl() + val session = SevenWondersClient().connect(serverUrl) console.info("Connected to Seven Wonders web socket API") launch(start = CoroutineStart.UNDISPATCHED) { @@ -43,6 +43,15 @@ suspend fun SwSagaContext.rootSaga() = coroutineScope { } } +private fun sevenWondersWebSocketUrl(): String { + if (!isProdEnv()) { + return "ws://localhost:8000" + } + // prevents mixed content requests + val scheme = if (window.location.protocol.startsWith("https")) "wss" else "ws" + return "$scheme://${window.location.host}" +} + private suspend fun serverErrorSaga(session: SevenWondersSession) { session.watchErrors().collect { err -> // TODO use blueprintjs toaster |