packages feed

pipes-websockets 0.0.0.0 → 0.1.0.0

raw patch · 13 files changed

+190/−68 lines, 13 filesdep +pipesdep +pipes-concurrencydep +textdep −QuickCheckdep −test-frameworkdep −test-framework-hunitdep ~basenew-component:exe:pipes-websockets-examplenew-uploader

Dependencies added: pipes, pipes-concurrency, text, transformers, websockets

Dependencies removed: QuickCheck, test-framework, test-framework-hunit, test-framework-quickcheck2

Dependency ranges changed: base

Files

− CHANGELOG
@@ -1,1 +0,0 @@--*- mode: org -*-
+ CHANGELOG.md view
@@ -0,0 +1,4 @@+0.1.0.0 - Jan 15, 2016+==++ - Initial version: Producer and Consumer for WebSocket connections; example of usage to read/write responses to an echoing websocket.
− DEBT.org
LICENSE view
@@ -1,27 +1,30 @@-Copyright (c) 2013, Parnell Springmeyer+Copyright Noon van der Silk (c) 2015+ All rights reserved. -Redistribution and use in source and binary forms, with or without modification,-are permitted provided that the following conditions are met:+Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met: -  Redistributions of source code must retain the above copyright notice, this-  list of conditions and the following disclaimer.+    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer. -  Redistributions in binary form must reproduce the above copyright notice, this-  list of conditions and the following disclaimer in the documentation and/or-  other materials provided with the distribution.+    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution. -  Neither the name of the {organization} nor the names of its-  contributors may be used to endorse or promote products derived from-  this software without specific prior written permission.+    * Neither the name of Noon van der Silk nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,10 @@+pipes-websockets+==++Providers Consumer/Producer from the [pipes](https://hackage.haskell.org/package/pipes) library for the [websockets](https://hackage.haskell.org/package/websockets) library.++Usage+--++Example of a pipes channel that reads from `stdin` and writes to a websocket, reads the result and writes to `stdout` can be found in the [Hackage Documentation](https://hackage.haskell.org/package/pipes-websockets).+
− README.org
@@ -1,4 +0,0 @@-pipes-websockets-================--A pipes helper library on-top of pipes-network for receiving and responding to websocket connections.
+ example/Main.hs view
@@ -0,0 +1,6 @@+module Main where++import Pipes.WebSockets.Examples++main :: IO ()+main = echoStdInOut "echo.websocket.org" 80 "/"
pipes-websockets.cabal view
@@ -1,52 +1,51 @@ name:                pipes-websockets-version:             0.0.0.0-synopsis:            Library for using websockets ontop of pipes-network.-description:         A pipes helper library on-top of pipes-network for receiving and responding to websocket connections.-homepage:            https://github.com/ixmatus/pipes-websockets+version:             0.1.0.0+synopsis:            WebSockets in the Pipes framework.+homepage:            https://github.com/silky/pipes-websockets#readme+bug-reports:         https://github.com/silky/pipes-websockets/issues license:             BSD3 license-file:        LICENSE-author:              Parnell Springmeyer-maintainer:          parnell@ixmat.us-copyright:           (c) 2013 Parnell Springmeyer <parnell@ixmat.us>-category:            Concurrency+author:              Noon van der Silk+maintainer:          noonsilk@gmail.com+copyright:           2016, Noon van der Silk+category:            Web build-type:          Simple-stability:           Alpha-Bug-reports:         https://github.com/ixmatus/pipes-websockets/issues-Package-url:         http://hackage.haskell.org/package/pipes-websockets+extra-source-files:  README.md, CHANGELOG.md, stack.yaml cabal-version:       >=1.10--extra-source-files:-    CHANGELOG-    README.org-    LICENSE-    DEBT.org--source-repository head-  type:     git-  location: https://github.com/ixmatus/pipes-websockets+description:+  This library provides Producers and Consumers of data+  to/from WebSocket connections.+  .+  Example usage can be found in "Pipes.WebSockets.Examples". The executable+  produced by this package simple runs one of the examples.+  .+  Import "Pipes.WebSockets" to use the library.+  .+  See @CHANGELOG.md@ for changes.  library-  hs-source-dirs:      src+  ghc-options:         -Wall   default-language:    Haskell2010-  exposed-modules:-    Pipes.Network.Websockets+  hs-source-dirs:      src+  exposed-modules:     Pipes.WebSockets+  exposed-modules:     Pipes.WebSockets.Examples+  build-depends:       base >= 4.7 && < 5+                     , websockets+                     , pipes+                     , pipes-concurrency+                     , text+                     , transformers -  ghc-options:         -Wall- -  build-depends:       base  >= 4.6     && < 4.7 -test-suite tests-  type:           exitcode-stdio-1.0-  hs-source-dirs: test-  main-is:        Websockets.hs+executable pipes-websockets-example+  default-language:    Haskell2010+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall+  hs-source-dirs:      example+  main-is:             Main.hs+  build-depends:       base >= 4.7 && < 5+                     , pipes-websockets -  ghc-options:-    -Wall -threaded -rtsopts -  build-depends:-    pipes-websockets,-    base >= 4.6,-    QuickCheck >= 2.6,-    test-framework >= 0.8,-    test-framework-quickcheck2 >= 0.3.0,-    test-framework-hunit >= 0.3.0+source-repository head+  type:     git+  location: https://github.com/silky/pipes-websockets
− src/Pipes/Network/Websockets.hs
@@ -1,1 +0,0 @@-module Pipes.Network.Websockets where
+ src/Pipes/WebSockets.hs view
@@ -0,0 +1,39 @@+module Pipes.WebSockets where++import           Pipes+import qualified Network.WebSockets             as WS+import           Control.Monad.Trans.Reader     (ReaderT+                                                , ask)+++-- TODO: Make some kind of 'runClientEffect' thing to wrap these things.+++-- | Transformer so that we can pass a connection to the output+--   of these consumers/producers.+type WebSocketsT = ReaderT WS.Connection++++-- | WebSockets Producer. Given some WebSocket connection, it will yield+--   a single message that comes through.+wsInOnce :: (MonadIO m, WS.WebSocketsData a) => Producer a (WebSocketsT m) ()+wsInOnce = do+    conn <- lift ask+    x    <- liftIO (WS.receiveData conn)+    yield x+++-- | WebSockets Producer. Given some WebSocket connection, it will yield+--   the messages that come through.+wsIn :: (MonadIO m, WS.WebSocketsData a) => Producer a (WebSocketsT m) ()+wsIn = wsInOnce >> wsIn+++-- | WebSockets Consumer. Given some connection, it will send messages that+--   are passed into it.+wsOut :: (MonadIO m, WS.WebSocketsData a) => Consumer a (WebSocketsT m) ()+wsOut = do+    conn <- lift ask+    m    <- await+    liftIO $ WS.sendTextData conn m
+ src/Pipes/WebSockets/Examples.hs view
@@ -0,0 +1,58 @@+{-| Examples of usage. In this module we implement a few standard ways+    one may wish to use this library.+-}+module Pipes.WebSockets.Examples (+    echoStdInOut+  )+  where++import           Data.Text+import           Pipes+import           Pipes.Concurrent+import qualified Pipes.Prelude                  as P+import           Pipes.WebSockets+import qualified Network.WebSockets             as WS+import           Control.Monad.Trans.Reader     (ReaderT (runReaderT))++-- | Uses [Pipes.Concurrent](https://hackage.haskell.org/package/pipes-concurrency) +--   to start up threads for reading from and writing to a single +--   [WebSocket](https://hackage.haskell.org/package/websockets) connection.+--   Input to send is read from `stdin` and response are written to `stdout`.+--+--   Try it out on [echo.websocket.org](http://www.websocket.org) with:+--+--   > -- wsTest.hs+--   > module Main where +--   >+--   > import Pipes.WebSockets.Examples+--   >+--   > main :: IO ()+--   > main = echoStdInOut "echo.websocket.org" 80 "/"+echoStdInOut :: String  -- ^ Server to connect to+             -> Int     -- ^ Port+             -> String  -- ^ Path from the server, i.e. "/".+             -> IO ()+echoStdInOut host port path = do+    -- Setup a "mailbox" for getting messages from and placing them in.+    (output, input) <- spawn unbounded+    +                 -- Take messages from the socket and put them in the output.+    let msgsFrom = runEffect $ wsIn >-> toOutput output+                 -- Read from stdin and send msgs to the server.+        msgsTo   = runEffect $ for P.stdinLn+                                   (\s -> yield (pack s) >-> wsOut)+        --+        --  Read messages from the socket (which have been placed on the+        --  mailbox) and print to stdout.+        msgsOut  = runEffect $ for (fromInput input) +                                   (\s -> lift $ putStrLn ("Received: " ++ unpack s))++    lvf $ msgsOut++    WS.runClient host port path (\c -> do+                                lvf $ runReaderT msgsFrom c+                                runReaderT msgsTo c+                                )+    where+        lvf = liftIO . void . forkIO+
+ stack.yaml view
@@ -0,0 +1,10 @@+resolver: lts-4.0++packages:+- '.'++extra-deps: []++flags: {}++extra-package-dbs: []
− test/Websockets.hs
@@ -1,1 +0,0 @@-module Websockets where