package com.pixelized.desktop.lwa.utils.extention

import io.ktor.client.HttpClient
import io.ktor.client.plugins.websocket.DefaultClientWebSocketSession
import io.ktor.client.plugins.websocket.webSocket
import io.ktor.http.HttpMethod

// https://ktor.io/docs/client-websockets.html#handle-session
suspend fun HttpClient.connectWebSocket(
    host: String,
    port: Int,
    block: suspend DefaultClientWebSocketSession.() -> Unit,
) {
    webSocket(
        method = HttpMethod.Get,
        host = host.removePrefix("http://"),
        port = port,
        path = "/ws",
        block = block,
    )
}