I have, I think, implemented servant-client support for websockets. At least, this code compiles..
data WebSocketClient = WebSocketClient Request
instance RunClient m => HasClient m WebSocket where
type Client m WebSocket = WebSocketClient
clientWithRoute _pm Proxy req = WebSocketClient req
hoistClientMonad _ _ _ w = w
That's enough to allow using client to extract a WebSocket route. Rather than the usual ClientM runner, it will produce a WebSocketClient. To run that, I wrote this function:
runWebSocketClient :: WebSocketClient -> Websocket.ClientApp a -> ClientM a
runWebSocketClient (WebSocketClient req) app = do
clientenv <- ask
let burl = baseUrl clientenv
let creq = defaultMakeClientRequest burl req
case baseUrlScheme burl of
Http -> liftIO $ Websocket.runClient
(baseUrlHost burl)
(baseUrlPort burl)
(decodeBS (path creq))
app
Https -> error "TODO" -- needs wuss
I have, I think, implemented servant-client support for websockets. At least, this code compiles..
That's enough to allow using
client
to extract a WebSocket route. Rather than the usualClientM
runner, it will produce aWebSocketClient
. To run that, I wrote this function: