summaryrefslogtreecommitdiff
path: root/main/WebSocket.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-03-21 20:14:15 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2026-03-21 20:14:15 +0100
commit5c9a270c086bbf33e91b738e47bcae4bfa8ad3b0 (patch)
tree41f05c6d7685b43a6d092dc597a9f55da7d66c38 /main/WebSocket.hs
parent4b050db90586f1670dfd1db5964eeeabbbc74361 (diff)
Debug logs for WebSocket connection
Diffstat (limited to 'main/WebSocket.hs')
-rw-r--r--main/WebSocket.hs24
1 files changed, 21 insertions, 3 deletions
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