yesod-websockets 0.2.4.1 → 0.2.5
raw patch · 3 files changed
+44/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Yesod.WebSockets: ConnectionOptions :: ~(IO ()) -> ConnectionOptions
+ Yesod.WebSockets: [connectionOnPong] :: ConnectionOptions -> ~(IO ())
+ Yesod.WebSockets: data ConnectionOptions :: *
+ Yesod.WebSockets: defaultConnectionOptions :: ConnectionOptions
+ Yesod.WebSockets: webSocketsOptions :: (MonadBaseControl IO m, MonadHandler m) => ConnectionOptions -> WebSocketsT m () -> m ()
+ Yesod.WebSockets: webSocketsOptionsWith :: (MonadBaseControl IO m, MonadHandler m) => ConnectionOptions -> (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
Files
- ChangeLog.md +4/−0
- Yesod/WebSockets.hs +39/−5
- yesod-websockets.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.5++* Allow to start websockets with custom ConnectionOptions with `webSocketsOptions` and `webSocketsOptionsWith`+ ## 0.2.4.1 * Support for websockets 0.10
Yesod/WebSockets.hs view
@@ -6,6 +6,8 @@ WebSocketsT , webSockets , webSocketsWith+ , webSocketsOptions+ , webSocketsOptionsWith , receiveData , receiveDataE , receiveDataMessageE@@ -27,6 +29,9 @@ , race_ , concurrently , concurrently_+ -- * Re-exports from websockets+ , WS.defaultConnectionOptions+ , WS.ConnectionOptions (..) ) where import qualified Control.Concurrent.Async as A@@ -56,10 +61,20 @@ -- -- Since 0.1.0 webSockets :: (Y.MonadBaseControl IO 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)-webSockets = webSocketsWith $ const $ return $ Just $ WS.AcceptRequest Nothing []+webSocketsOptions opts = webSocketsOptionsWith opts $ const $ return $ Just $ WS.AcceptRequest Nothing [] #else-webSockets = webSocketsWith $ const $ return $ Just $ WS.AcceptRequest Nothing+webSocketsOptions opts = webSocketsOptionsWith opts $ const $ return $ Just $ WS.AcceptRequest Nothing #endif -- | Varient of 'webSockets' which allows you to specify the 'WS.AcceptRequest'@@ -76,17 +91,36 @@ -- actions such as 'Y.invalidArgs'. -> WebSocketsT m () -> m ()-webSocketsWith buildAr inner = do+webSocketsWith = webSocketsOptionsWith WS.defaultConnectionOptions++-- | Varient of 'webSockets' which allows you to specify both+-- the WS.ConnectionOptions and the 'WS.AcceptRequest'+-- setttings when upgrading to a websocket connection.+--+-- Since 0.2.5+webSocketsOptionsWith :: (Y.MonadBaseControl IO m, Y.MonadHandler m)+ => WS.ConnectionOptions+ -- ^ Custom websockets options+ -> (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+ -- you to use 'WS.getRequestSubprotocols' and only accept the request if+ -- a compatible subprotocol is given. Also, the action runs before upgrading+ -- the request to websockets, so you can also use short-circuiting handler+ -- actions such as 'Y.invalidArgs'.+ -> WebSocketsT m ()+ -> m ()+webSocketsOptionsWith wsConnOpts buildAr inner = do req <- Y.waiRequest when (WaiWS.isWebSocketsReq req) $ do let rhead = WaiWS.getRequestHead req mar <- buildAr rhead case mar of Nothing -> return ()- Just ar -> do+ Just ar -> Y.sendRawResponseNoConduit $ \src sink -> control $ \runInIO -> WaiWS.runWebSockets- WS.defaultConnectionOptions+ wsConnOpts rhead (\pconn -> do conn <- WS.acceptRequestWith pconn ar
yesod-websockets.cabal view
@@ -1,5 +1,5 @@ name: yesod-websockets-version: 0.2.4.1+version: 0.2.5 synopsis: WebSockets support for Yesod description: WebSockets support for Yesod homepage: https://github.com/yesodweb/yesod