yesod-websockets 0.2.6 → 0.3.0
raw patch · 3 files changed
+115/−94 lines, 3 filesdep +mtldep +unliftiodep −asyncdep −enclosed-exceptionsdep −monad-controldep ~conduitdep ~websocketsdep ~yesod-corePVP ok
version bump matches the API change (PVP)
Dependencies added: mtl, unliftio
Dependencies removed: async, enclosed-exceptions, monad-control
Dependency ranges changed: conduit, websockets, yesod-core
API changes (from Hackage documentation)
+ Yesod.WebSockets: [connectionCompressionOptions] :: ConnectionOptions -> !CompressionOptions
+ Yesod.WebSockets: [connectionFramePayloadSizeLimit] :: ConnectionOptions -> !SizeLimit
+ Yesod.WebSockets: [connectionMessageDataSizeLimit] :: ConnectionOptions -> !SizeLimit
+ Yesod.WebSockets: [connectionStrictUnicode] :: ConnectionOptions -> !Bool
- Yesod.WebSockets: ConnectionOptions :: ~(IO ()) -> ConnectionOptions
+ Yesod.WebSockets: ConnectionOptions :: !IO () -> !CompressionOptions -> !Bool -> !SizeLimit -> !SizeLimit -> ConnectionOptions
- Yesod.WebSockets: [connectionOnPong] :: ConnectionOptions -> ~(IO ())
+ Yesod.WebSockets: [connectionOnPong] :: ConnectionOptions -> !IO ()
- Yesod.WebSockets: concurrently :: MonadBaseControl IO m => m a -> m b -> m (a, b)
+ Yesod.WebSockets: concurrently :: MonadUnliftIO m => m a -> m b -> m (a, b)
- Yesod.WebSockets: concurrently_ :: MonadBaseControl IO m => m a -> m b -> m ()
+ Yesod.WebSockets: concurrently_ :: MonadUnliftIO m => m a -> m b -> m ()
- Yesod.WebSockets: race :: MonadBaseControl IO m => m a -> m b -> m (Either a b)
+ Yesod.WebSockets: race :: MonadUnliftIO m => m a -> m b -> m Either a b
- Yesod.WebSockets: race_ :: MonadBaseControl IO m => m a -> m b -> m ()
+ Yesod.WebSockets: race_ :: MonadUnliftIO m => m a -> m b -> m ()
- Yesod.WebSockets: receiveData :: (MonadIO m, WebSocketsData a) => WebSocketsT m a
+ Yesod.WebSockets: receiveData :: (MonadIO m, MonadReader Connection m, WebSocketsData a) => m a
- Yesod.WebSockets: receiveDataE :: (MonadIO m, WebSocketsData a) => WebSocketsT m (Either SomeException a)
+ Yesod.WebSockets: receiveDataE :: (MonadIO m, MonadReader Connection m, WebSocketsData a) => m (Either SomeException a)
- Yesod.WebSockets: receiveDataMessageE :: (MonadIO m) => WebSocketsT m (Either SomeException DataMessage)
+ Yesod.WebSockets: receiveDataMessageE :: (MonadIO m, MonadReader Connection m) => m (Either SomeException DataMessage)
- Yesod.WebSockets: sendBinaryData :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendBinaryData :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m ()
- Yesod.WebSockets: sendBinaryDataE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendBinaryDataE :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m (Either SomeException ())
- Yesod.WebSockets: sendClose :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendClose :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> WebSocketsT m ()
- Yesod.WebSockets: sendCloseE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendCloseE :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m (Either SomeException ())
- Yesod.WebSockets: sendDataMessageE :: (MonadIO m) => DataMessage -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendDataMessageE :: (MonadIO m, MonadReader Connection m) => DataMessage -> m (Either SomeException ())
- Yesod.WebSockets: sendPing :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendPing :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> WebSocketsT m ()
- Yesod.WebSockets: sendPingE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendPingE :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m (Either SomeException ())
- Yesod.WebSockets: sendTextData :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendTextData :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m ()
- Yesod.WebSockets: sendTextDataE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendTextDataE :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => a -> m (Either SomeException ())
- Yesod.WebSockets: sinkWSBinary :: (MonadIO m, WebSocketsData a) => Consumer a (WebSocketsT m) ()
+ Yesod.WebSockets: sinkWSBinary :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => ConduitT a o m ()
- Yesod.WebSockets: sinkWSText :: (MonadIO m, WebSocketsData a) => Consumer a (WebSocketsT m) ()
+ Yesod.WebSockets: sinkWSText :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => ConduitT a o m ()
- Yesod.WebSockets: sourceWS :: (MonadIO m, WebSocketsData a) => Producer (WebSocketsT m) a
+ Yesod.WebSockets: sourceWS :: (MonadIO m, WebSocketsData a, MonadReader Connection m) => ConduitT i a m ()
- Yesod.WebSockets: webSockets :: (MonadBaseControl IO m, MonadHandler m) => WebSocketsT m () -> m ()
+ Yesod.WebSockets: webSockets :: (MonadUnliftIO m, MonadHandler m) => WebSocketsT m () -> m ()
- Yesod.WebSockets: webSocketsOptions :: (MonadBaseControl IO m, MonadHandler m) => ConnectionOptions -> WebSocketsT m () -> m ()
+ Yesod.WebSockets: webSocketsOptions :: (MonadUnliftIO m, MonadHandler m) => ConnectionOptions -> WebSocketsT m () -> m ()
- Yesod.WebSockets: webSocketsOptionsWith :: (MonadBaseControl IO m, MonadHandler m) => ConnectionOptions -> (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
+ Yesod.WebSockets: webSocketsOptionsWith :: (MonadUnliftIO m, MonadHandler m) => ConnectionOptions -> (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
- Yesod.WebSockets: webSocketsWith :: (MonadBaseControl IO m, MonadHandler m) => (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
+ Yesod.WebSockets: webSocketsWith :: (MonadUnliftIO m, MonadHandler m) => (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
Files
- ChangeLog.md +4/−0
- Yesod/WebSockets.hs +105/−87
- yesod-websockets.cabal +6/−7
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.3.0++* Upgrade to yesod-core 1.6+ ## 0.2.6 * Fix warnings
Yesod/WebSockets.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} module Yesod.WebSockets@@ -34,19 +33,13 @@ , WS.ConnectionOptions (..) ) where -import qualified Control.Concurrent.Async as A-import Control.Monad (forever, void, when)-import Control.Monad.IO.Class (MonadIO (liftIO))-import Control.Monad.Trans.Control (control)-import Control.Monad.Trans.Control (MonadBaseControl (liftBaseWith, restoreM))-import Control.Monad.Trans.Reader (ReaderT (ReaderT, runReaderT))-import qualified Data.Conduit as C-import qualified Data.Conduit.List as CL+import Control.Monad (forever, when)+import Control.Monad.Reader (ReaderT, runReaderT, MonadReader, ask)+import Conduit import qualified Network.Wai.Handler.WebSockets as WaiWS import qualified Network.WebSockets as WS import qualified Yesod.Core as Y-import Control.Exception (SomeException)-import Control.Exception.Enclosed (tryAny)+import UnliftIO (SomeException, tryAny, MonadIO, liftIO, MonadUnliftIO, withRunInIO, race, race_, concurrently, concurrently_) -- | A transformer for a WebSockets handler. --@@ -60,28 +53,28 @@ -- instead. -- -- Since 0.1.0-webSockets :: (Y.MonadBaseControl IO m, Y.MonadHandler m) => WebSocketsT m () -> m ()+webSockets+ :: (MonadUnliftIO m, Y.MonadHandler m)+ => WebSocketsT m ()+ -> m () webSockets = webSocketsOptions WS.defaultConnectionOptions -- | Varient of 'webSockets' which allows you to specify -- the WS.ConnectionOptions setttings when upgrading to a websocket connection. -- -- Since 0.2.5-webSocketsOptions :: (Y.MonadBaseControl IO m, Y.MonadHandler m)- => WS.ConnectionOptions- -> WebSocketsT m ()- -> m ()-#if MIN_VERSION_websockets(0,10,0)+webSocketsOptions+ :: (MonadUnliftIO m, Y.MonadHandler m)+ => WS.ConnectionOptions+ -> WebSocketsT m ()+ -> m () webSocketsOptions opts = webSocketsOptionsWith opts $ const $ return $ Just $ WS.AcceptRequest Nothing []-#else-webSocketsOptions opts = webSocketsOptionsWith opts $ const $ return $ Just $ WS.AcceptRequest Nothing-#endif -- | Varient of 'webSockets' which allows you to specify the 'WS.AcceptRequest' -- setttings when upgrading to a websocket connection. -- -- Since 0.2.4-webSocketsWith :: (Y.MonadBaseControl IO m, Y.MonadHandler m)+webSocketsWith :: (MonadUnliftIO m, Y.MonadHandler m) => (WS.RequestHead -> m (Maybe WS.AcceptRequest)) -- ^ A Nothing indicates that the websocket upgrade request should not happen -- and instead the rest of the handler will be called instead. This allows@@ -98,7 +91,7 @@ -- setttings when upgrading to a websocket connection. -- -- Since 0.2.5-webSocketsOptionsWith :: (Y.MonadBaseControl IO m, Y.MonadHandler m)+webSocketsOptionsWith :: (MonadUnliftIO m, Y.MonadHandler m) => WS.ConnectionOptions -- ^ Custom websockets options -> (WS.RequestHead -> m (Maybe WS.AcceptRequest))@@ -119,7 +112,7 @@ Nothing -> return () Just ar -> Y.sendRawResponseNoConduit- $ \src sink -> control $ \runInIO -> WaiWS.runWebSockets+ $ \src sink -> withRunInIO $ \runInIO -> WaiWS.runWebSockets wsConnOpts rhead (\pconn -> do@@ -130,132 +123,157 @@ sink -- | Wrapper for capturing exceptions-wrapWSE :: MonadIO m => (WS.Connection -> a -> IO ())-> a -> WebSocketsT m (Either SomeException ())-wrapWSE ws x = ReaderT $ liftIO . tryAny . flip ws x+wrapWSE :: (MonadIO m, MonadReader WS.Connection m)+ => (WS.Connection -> a -> IO ())+ -> a+ -> m (Either SomeException ())+wrapWSE ws x = do+ conn <- ask+ liftIO $ tryAny $ ws conn x -wrapWS :: MonadIO m => (WS.Connection -> a -> IO ()) -> a -> WebSocketsT m ()-wrapWS ws x = ReaderT $ liftIO . flip ws x+wrapWS :: (MonadIO m, MonadReader WS.Connection m)+ => (WS.Connection -> a -> IO ())+ -> a+ -> m ()+wrapWS ws x = do+ conn <- ask+ liftIO $ ws conn x -- | Receive a piece of data from the client. -- -- Since 0.1.0-receiveData :: (MonadIO m, WS.WebSocketsData a) => WebSocketsT m a-receiveData = ReaderT $ liftIO . WS.receiveData+receiveData+ :: (MonadIO m, MonadReader WS.Connection m, WS.WebSocketsData a)+ => m a+receiveData = do+ conn <- ask+ liftIO $ WS.receiveData conn -- | Receive a piece of data from the client. -- Capture SomeException as the result or operation -- Since 0.2.2-receiveDataE :: (MonadIO m, WS.WebSocketsData a) => WebSocketsT m (Either SomeException a)-receiveDataE = ReaderT $ liftIO . tryAny . WS.receiveData+receiveDataE+ :: (MonadIO m, MonadReader WS.Connection m, WS.WebSocketsData a)+ => m (Either SomeException a)+receiveDataE = do+ conn <- ask+ liftIO $ tryAny $ WS.receiveData conn -- | Receive an application message. -- Capture SomeException as the result or operation -- Since 0.2.3-receiveDataMessageE :: (MonadIO m) => WebSocketsT m (Either SomeException WS.DataMessage)-receiveDataMessageE = ReaderT $ liftIO . tryAny . WS.receiveDataMessage+receiveDataMessageE+ :: (MonadIO m, MonadReader WS.Connection m)+ => m (Either SomeException WS.DataMessage)+receiveDataMessageE = do+ conn <- ask+ liftIO $ tryAny $ WS.receiveDataMessage conn -- | Send a textual message to the client. -- -- Since 0.1.0-sendTextData :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendTextData+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m () sendTextData = wrapWS WS.sendTextData -- | Send a textual message to the client. -- Capture SomeException as the result or operation--- and can be used like +-- and can be used like -- `either handle_exception return =<< sendTextDataE ("Welcome" :: Text)` -- Since 0.2.2-sendTextDataE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendTextDataE+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m (Either SomeException ()) sendTextDataE = wrapWSE WS.sendTextData -- | Send a binary message to the client. -- -- Since 0.1.0-sendBinaryData :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendBinaryData+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m () sendBinaryData = wrapWS WS.sendBinaryData -- | Send a binary message to the client. -- Capture SomeException as the result of operation -- Since 0.2.2-sendBinaryDataE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendBinaryDataE+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m (Either SomeException ()) sendBinaryDataE = wrapWSE WS.sendBinaryData -- | Send a ping message to the client. -- -- Since 0.2.2-sendPing :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendPing+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> WebSocketsT m () sendPing = wrapWS WS.sendPing --- | Send a ping message to the client. +-- | Send a ping message to the client. -- Capture SomeException as the result of operation -- Since 0.2.2-sendPingE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendPingE+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m (Either SomeException ()) sendPingE = wrapWSE WS.sendPing --- | Send a DataMessage to the client. +-- | Send a DataMessage to the client. -- Capture SomeException as the result of operation -- Since 0.2.3-sendDataMessageE :: (MonadIO m) => WS.DataMessage -> WebSocketsT m (Either SomeException ())-sendDataMessageE x = ReaderT $ liftIO . tryAny . (`WS.sendDataMessage` x)+sendDataMessageE+ :: (MonadIO m, MonadReader WS.Connection m)+ => WS.DataMessage+ -> m (Either SomeException ())+sendDataMessageE x = do+ conn <- ask+ liftIO $ tryAny $ WS.sendDataMessage conn x --- | Send a close request to the client. --- +-- | Send a close request to the client.+-- -- Since 0.2.2-sendClose :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendClose+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> WebSocketsT m () sendClose = wrapWS WS.sendClose --- | Send a close request to the client. +-- | Send a close request to the client. -- Capture SomeException as the result of operation -- Since 0.2.2-sendCloseE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendCloseE+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => a+ -> m (Either SomeException ()) sendCloseE = wrapWSE WS.sendClose -- | A @Source@ of WebSockets data from the user. -- -- Since 0.1.0-sourceWS :: (MonadIO m, WS.WebSocketsData a) => C.Producer (WebSocketsT m) a-sourceWS = forever $ Y.lift receiveData >>= C.yield+sourceWS+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => ConduitT i a m ()+sourceWS = forever $ lift receiveData >>= yield -- | A @Sink@ for sending textual data to the user. -- -- Since 0.1.0-sinkWSText :: (MonadIO m, WS.WebSocketsData a) => C.Consumer a (WebSocketsT m) ()-sinkWSText = CL.mapM_ sendTextData+sinkWSText+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => ConduitT a o m ()+sinkWSText = mapM_C sendTextData -- | A @Sink@ for sending binary data to the user. -- -- Since 0.1.0-sinkWSBinary :: (MonadIO m, WS.WebSocketsData a) => C.Consumer a (WebSocketsT m) ()-sinkWSBinary = CL.mapM_ sendBinaryData---- | Generalized version of 'A.race'.------ Since 0.1.0-race :: MonadBaseControl IO m => m a -> m b -> m (Either a b)-race x y = liftBaseWith (\run -> A.race (run x) (run y))- >>= either (fmap Left . restoreM) (fmap Right . restoreM)---- | Generalized version of 'A.race_'.------ Since 0.1.0-race_ :: MonadBaseControl IO m => m a -> m b -> m ()-race_ x y = void $ race x y---- | Generalized version of 'A.concurrently'. Note that if your underlying--- monad has some kind of mutable state, the state from the second action will--- overwrite the state from the first.------ Since 0.1.0-concurrently :: MonadBaseControl IO m => m a -> m b -> m (a, b)-concurrently x y = do- (resX, resY) <- liftBaseWith $ \run -> A.concurrently (run x) (run y)- x' <- restoreM resX- y' <- restoreM resY- return (x', y')---- | Run two actions concurrently (like 'A.concurrently'), but discard their--- results and any modified monadic state.------ Since 0.1.0-concurrently_ :: MonadBaseControl IO m => m a -> m b -> m ()-concurrently_ x y = void $ liftBaseWith $ \run -> A.concurrently (run x) (run y)+sinkWSBinary+ :: (MonadIO m, WS.WebSocketsData a, MonadReader WS.Connection m)+ => ConduitT a o m ()+sinkWSBinary = mapM_C sendBinaryData
yesod-websockets.cabal view
@@ -1,5 +1,5 @@ name: yesod-websockets-version: 0.2.6+version: 0.3.0 synopsis: WebSockets support for Yesod description: WebSockets support for Yesod homepage: https://github.com/yesodweb/yesod@@ -21,13 +21,12 @@ , wai , wai-websockets >= 2.1- , websockets >= 0.9+ , websockets >= 0.10 , transformers >= 0.2- , yesod-core >= 1.4- , monad-control >= 0.3- , conduit >= 1.0.15.1- , async >= 2.0.1.5- , enclosed-exceptions >= 1.0+ , yesod-core >= 1.6+ , unliftio+ , conduit >= 1.3+ , mtl source-repository head type: git