-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Provide a bridge between WAI and the websockets package.
--   
--   API docs and the README are available at
--   <a>http://www.stackage.org/package/wai-websockets</a>.
@package wai-websockets
@version 3.0.1.1

module Network.Wai.Handler.WebSockets

-- | Upgrade a <tt>websockets</tt> <a>ServerApp</a> to a <tt>wai</tt>
--   <a>Application</a>. Uses the given backup <a>Application</a> to handle
--   <a>Request</a>s that are not WebSocket requests.
--   
--   <pre>
--   websocketsOr opts ws_app backup_app = \req respond -&gt;
--       <b>case</b> <a>websocketsApp</a> opts ws_app req <b>of</b>
--           <a>Nothing</a>  -&gt; backup_app req send_response
--           <a>Just</a> res -&gt; respond res
--   </pre>
--   
--   For example, below is an <a>Application</a> that sends <tt>"Hello,
--   client!"</tt> to each connected client.
--   
--   <pre>
--   app :: <a>Application</a>
--   app = <a>websocketsOr</a> <a>defaultConnectionOptions</a> wsApp backupApp
--     <b>where</b>
--       wsApp :: <a>ServerApp</a>
--       wsApp pending_conn = do
--           conn &lt;- <a>acceptRequest</a> pending_conn
--           <a>sendTextData</a> conn ("Hello, client!" :: <a>Text</a>)
--   
--       backupApp :: <a>Application</a>
--       backupApp _ respond = respond $ <a>responseLBS</a> <a>status400</a> [] "Not a WebSocket request"
--   </pre>
websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application

-- | Handle a single <tt>wai</tt> <a>Request</a> with the given
--   <tt>websockets</tt> <a>ServerApp</a>. Returns <a>Nothing</a> if the
--   <a>Request</a> is not a WebSocket request, <a>Just</a> otherwise.
--   
--   Usually, <a>websocketsOr</a> is more convenient.
websocketsApp :: ConnectionOptions -> ServerApp -> Request -> Maybe Response

-- | Returns whether or not the given <a>Request</a> is a WebSocket
--   request.
isWebSocketsReq :: Request -> Bool
getRequestHead :: Request -> RequestHead

-- | Internal function to run the WebSocket io-streams using the conduit
--   library.
runWebSockets :: ConnectionOptions -> RequestHead -> (PendingConnection -> IO a) -> IO ByteString -> (ByteString -> IO ()) -> IO a
