Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Use WSS protocol when API base url is behind SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
mklkj committed Feb 11, 2024
1 parent 352b769 commit c47d201
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import io.github.mklkj.kommunicator.data.models.MessageRequest
import io.ktor.client.HttpClient
import io.ktor.client.plugins.websocket.DefaultClientWebSocketSession
import io.ktor.client.plugins.websocket.webSocketSession
import io.ktor.client.request.host
import io.ktor.client.request.port
import io.ktor.http.URLBuilder
import io.ktor.http.URLProtocol
import io.ktor.http.path
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.flow
Expand Down Expand Up @@ -108,12 +108,14 @@ class MessagesRepository(
}

suspend fun getChatSession(chatId: UUID): DefaultClientWebSocketSession {
val session = httpClient.webSocketSession("/ws/chats/$chatId/messages") {
val url = URLBuilder(BuildKonfig.BASE_URL)
host = url.host
port = url.port
val url = (URLBuilder(BuildKonfig.BASE_URL)).apply {
protocol = when (protocol) {
URLProtocol.HTTPS -> URLProtocol.WSS
else -> URLProtocol.WS
}
path("/ws/chats/$chatId/messages")
}
return session
return httpClient.webSocketSession(url.buildString())
}

suspend fun handleReceivedMessage(chatId: UUID, message: MessageBroadcast) {
Expand Down

0 comments on commit c47d201

Please sign in to comment.