From 5c9a270c086bbf33e91b738e47bcae4bfa8ad3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 21 Mar 2026 20:14:15 +0100 Subject: Debug logs for WebSocket connection --- main/WebSocket.hs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'main/WebSocket.hs') diff --git a/main/WebSocket.hs b/main/WebSocket.hs index 48b4483..41ae027 100644 --- a/main/WebSocket.hs +++ b/main/WebSocket.hs @@ -1,5 +1,6 @@ module WebSocket ( WebSocketAddress(..), + WebSocketOptions(..), defaultWebSocketOptions, startWebsocketServer, ) where @@ -34,10 +35,27 @@ instance PeerAddressType WebSocketAddress where | Just WS.ConnectionClosed <- fromException e -> return () | otherwise -> throwIO e -startWebsocketServer :: Server -> String -> Int -> (String -> IO ()) -> IO () -startWebsocketServer server addr port logd = do + +data WebSocketOptions = WebSocketOptions + { wsAddress :: String + , wsPort :: Int + , wsDebugLog :: Bool + } + +defaultWebSocketOptions :: WebSocketOptions +defaultWebSocketOptions = WebSocketOptions + { wsAddress = "::" + , wsPort = 80 + , wsDebugLog = False + } + + +startWebsocketServer :: Server -> (String -> IO ()) -> WebSocketOptions -> IO () +startWebsocketServer server logd WebSocketOptions {..} = do void $ forkIO $ do - WS.runServer addr port $ \pending -> do + WS.runServer wsAddress wsPort $ \pending -> do + when wsDebugLog $ do + logd $ "WebSocket request: " <> show (WS.pendingRequest pending) conn <- WS.acceptRequest pending u <- newUnique let paddr = WebSocketAddress u conn -- cgit v1.2.3