packages feed

apiary-websockets 0.17.0 → 1.0.0

raw patch · 2 files changed

+23/−19 lines, 2 filesdep ~apiarydep ~websockets

Dependency ranges changed: apiary, websockets

Files

apiary-websockets.cabal view
@@ -1,5 +1,5 @@ name:                apiary-websockets-version:             0.17.0+version:             1.0.0 synopsis:            websockets support for apiary web framework. description:   example: <https://github.com/philopon/apiary/blob/master/examples/websockets.hs>@@ -20,9 +20,9 @@   exposed-modules:     Web.Apiary.WebSockets   other-modules:          build-depends:       base               >=4.6   && <4.8-                     , apiary             >=0.16  && <0.18+                     , apiary             >=1.0   && <1.1                      , wai-websockets     >=2.1   && <3.1-                     , websockets         >=0.8   && <0.9+                     , websockets         >=0.8   && <0.10    hs-source-dirs:      src   ghc-options:         -O2 -Wall
src/Web/Apiary/WebSockets.hs view
@@ -3,6 +3,7 @@     webSockets, webSockets'     , actionWithWebSockets      , actionWithWebSockets'+    , websocketsToAction     -- * Reexport     -- | PendingConnection,     -- pandingRequest, acceptRequest, rejectrequest@@ -14,7 +15,8 @@     ) where  import Web.Apiary-import Data.Apiary.SList+import Control.Monad.Apiary.Action+import Data.Apiary.Dict import qualified Network.Wai.Handler.WebSockets as WS import qualified Network.WebSockets as WS @@ -25,33 +27,35 @@     , sendTextData, sendBinaryData, sendClose, sendPing     ) -wsToApp :: Monad m => WS.ConnectionOptions -        -> Fn xs WS.ServerApp -> SList xs -> ActionT exts m ()-wsToApp conn srv args = getRequest >>= \req ->-    case WS.websocketsApp conn (apply srv args) req of-        Nothing -> return ()+websocketsToAction :: Monad m => WS.ConnectionOptions +                   -> (Dict prms -> WS.ServerApp) -> ActionT exts prms m ()+websocketsToAction conn srv = do+    req <- getRequest+    d   <- getParams+    case WS.websocketsApp conn (srv d) req of+        Nothing -> mzero         Just r  -> stopWith r  -- | websocket only action. since 0.8.0.0. webSockets' :: (Monad m, Monad actM) => WS.ConnectionOptions-            -> Fn prms WS.ServerApp -> ApiaryT exts prms actM m ()-webSockets' conn srv = action' $ wsToApp conn srv+            -> (Dict prms -> WS.ServerApp) -> ApiaryT exts prms actM m ()+webSockets' conn srv = action $ websocketsToAction conn srv  -- | websocket only action. since 0.8.0.0. webSockets :: (Monad m, Monad n)-           => Fn xs WS.ServerApp -> ApiaryT exts xs n m ()+           => (Dict prms -> WS.ServerApp) -> ApiaryT exts prms n m () webSockets = webSockets' WS.defaultConnectionOptions  actionWithWebSockets' :: (Monad m, Monad actM)                       => WS.ConnectionOptions -                      -> Fn prms WS.ServerApp-                      -> Fn prms (ActionT exts actM ())+                      -> (Dict prms -> WS.ServerApp)+                      -> ActionT exts prms actM ()                       -> ApiaryT exts prms actM m () actionWithWebSockets' conn srv m =-    action' $ \a -> wsToApp conn srv a >> apply m a+    action $ websocketsToAction conn srv >> m -actionWithWebSockets :: (Monad m, Monad n)-                     => Fn c WS.ServerApp-                     -> Fn c (ActionT exts n ())-                     -> ApiaryT exts c n m ()+actionWithWebSockets :: (Monad m, Monad actM)+                     => (Dict prms -> WS.ServerApp)+                     -> ActionT exts prms actM ()+                     -> ApiaryT exts prms actM m () actionWithWebSockets = actionWithWebSockets' WS.defaultConnectionOptions