packages feed

apiary-websockets (empty) → 0.4.2.0

raw patch · 4 files changed

+100/−0 lines, 4 filesdep +apiarydep +basedep +wai-websocketssetup-changed

Dependencies added: apiary, base, wai-websockets, websockets

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Hirotomo Moriwaki++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ apiary-websockets.cabal view
@@ -0,0 +1,34 @@+name:                apiary-websockets+version:             0.4.2.0+x-revision:          1+synopsis:            websockets supper for apiary web framework.+description:+  example: <https://github.com/philopon/apiary/blob/master/examples/websockets.hs>+license:             MIT+license-file:        LICENSE+author:              HirotomoMoriwaki<philopon.dependence@gmail.com>+maintainer:          HirotomoMoriwaki<philopon.dependence@gmail.com>+Homepage:            https://github.com/philopon/apiary+Bug-reports:         https://github.com/philopon/apiary/issues+copyright:           (c) 2014 Hirotomo Moriwaki+category:            Web+build-type:          Simple+stability:           experimental+-- extra-source-files:  +cabal-version:       >=1.10++library+  exposed-modules:     Web.Apiary.WebSockets+  other-modules:       +  build-depends:       base               >=4.7   && <4.8+                     , apiary             >=0.4.2 && <0.5+                     , wai-websockets     >=2.1   && <2.2+                     , websockets         >=0.8   && <0.9++  hs-source-dirs:      src+  ghc-options:         -O2 -Wall+  default-language:    Haskell2010++source-repository head+  type:     git+  location: git://github.com/philopon/apiary.git
+ src/Web/Apiary/WebSockets.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE NoMonomorphismRestriction #-}+module Web.Apiary.WebSockets (+      actionWithWebSockets +    , actionWithWebSockets'+    -- * Reexport+    -- | PendingConnection,+    -- pandingRequest, acceptRequest, rejectrequest+    --+    -- receiveData+    --+    -- sendTextData, sendBinaryData, sendClose, sendPing+    , module Network.WebSockets+    ) where++import Web.Apiary+import Data.Apiary.SList+import qualified Network.Wai.Handler.WebSockets as WS+import qualified Network.WebSockets as WS++import Network.WebSockets+    ( PendingConnection+    , pendingRequest, acceptRequest, rejectRequest+    , receiveData+    , sendTextData, sendBinaryData, sendClose, sendPing+    )++actionWithWebSockets' :: Monad m => WS.ConnectionOptions +                      -> Fn xs WS.ServerApp+                      -> Fn xs (ActionT m ())+                      -> ApiaryT xs m ()+actionWithWebSockets' conn srv m = do+    actionWithPreAction pa m+  where+    pa args = do+        req <- getRequest+        case WS.websocketsApp conn (apply srv args) req of+            Nothing   -> return ()+            Just resp -> stopWith resp++actionWithWebSockets :: Monad m +                     => Fn c WS.ServerApp+                     -> Fn c (ActionT m ())+                     -> ApiaryT c m ()+actionWithWebSockets = actionWithWebSockets' WS.defaultConnectionOptions