yesod-websockets 0.2.3 → 0.2.4
raw patch · 2 files changed
+35/−13 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Yesod.WebSockets: webSocketsWith :: (MonadBaseControl IO m, MonadHandler m) => (RequestHead -> m (Maybe AcceptRequest)) -> WebSocketsT m () -> m ()
- Yesod.WebSockets: receiveDataMessageE :: MonadIO m => WebSocketsT m (Either SomeException DataMessage)
+ Yesod.WebSockets: receiveDataMessageE :: (MonadIO m) => WebSocketsT m (Either SomeException DataMessage)
- Yesod.WebSockets: sendDataMessageE :: MonadIO m => DataMessage -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendDataMessageE :: (MonadIO m) => DataMessage -> WebSocketsT m (Either SomeException ())
Files
- Yesod/WebSockets.hs +34/−12
- yesod-websockets.cabal +1/−1
Yesod/WebSockets.hs view
@@ -5,6 +5,7 @@ ( -- * Core API WebSocketsT , webSockets+ , webSocketsWith , receiveData , receiveDataE , receiveDataMessageE@@ -55,19 +56,40 @@ -- -- Since 0.1.0 webSockets :: (Y.MonadBaseControl IO m, Y.MonadHandler m) => WebSocketsT m () -> m ()-webSockets inner = do+webSockets = webSocketsWith $ const $ return $ Just $ WS.AcceptRequest Nothing++-- | 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)+ => (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 ()+webSocketsWith buildAr inner = do req <- Y.waiRequest- when (WaiWS.isWebSocketsReq req) $- Y.sendRawResponseNoConduit- $ \src sink -> control $ \runInIO -> WaiWS.runWebSockets- WS.defaultConnectionOptions- (WaiWS.getRequestHead req)- (\pconn -> do- conn <- WS.acceptRequest pconn- WS.forkPingThread conn 30- runInIO $ runReaderT inner conn)- src- sink+ when (WaiWS.isWebSocketsReq req) $ do+ let rhead = WaiWS.getRequestHead req+ mar <- buildAr rhead+ case mar of+ Nothing -> return ()+ Just ar -> do+ Y.sendRawResponseNoConduit+ $ \src sink -> control $ \runInIO -> WaiWS.runWebSockets+ WS.defaultConnectionOptions+ rhead+ (\pconn -> do+ conn <- WS.acceptRequestWith pconn ar+ WS.forkPingThread conn 30+ runInIO $ runReaderT inner conn)+ src+ sink -- | Wrapper for capturing exceptions wrapWSE :: (MonadIO m, WS.WebSocketsData a) => (WS.Connection -> a -> IO ())-> a -> WebSocketsT m (Either SomeException ())
yesod-websockets.cabal view
@@ -1,5 +1,5 @@ name: yesod-websockets-version: 0.2.3+version: 0.2.4 synopsis: WebSockets support for Yesod description: WebSockets support for Yesod homepage: https://github.com/yesodweb/yesod