From 1420f627e34eb1dd00c855e92b67a166f976c1d0 Mon Sep 17 00:00:00 2001 From: Marcin Tolysz Date: Sun, 19 Jul 2015 23:49:35 +0100 Subject: [PATCH] Update WebSockets.hs Add `send and receive` `DataMessageE` so the whole WS API is mirrored --- yesod-websockets/Yesod/WebSockets.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/yesod-websockets/Yesod/WebSockets.hs b/yesod-websockets/Yesod/WebSockets.hs index d5a00958..eda45884 100644 --- a/yesod-websockets/Yesod/WebSockets.hs +++ b/yesod-websockets/Yesod/WebSockets.hs @@ -7,6 +7,7 @@ module Yesod.WebSockets , webSockets , receiveData , receiveDataE + , sendDataMessageE , sendPing , sendPingE , sendClose @@ -15,6 +16,7 @@ module Yesod.WebSockets , sendTextDataE , sendBinaryData , sendBinaryDataE + , sendDataMessageE -- * Conduit API , sourceWS , sinkWSText @@ -87,6 +89,12 @@ receiveData = ReaderT $ liftIO . WS.receiveData receiveDataE :: (MonadIO m, WS.WebSocketsData a) => WebSocketsT m (Either SomeException a) receiveDataE = ReaderT $ liftIO . tryAny . WS.receiveData +-- | Receive an application message. +-- Capture SomeException as the result or operation +-- Since 0.2.2 +receiveDataMessageE :: (MonadIO m) => WebSocketsT m (Either SomeException WS.DataMessage) +receiveDataMessageE = ReaderT $ liftIO . tryAny . WS.receiveDataMessage + -- | Send a textual message to the client. -- -- Since 0.1.0 @@ -125,6 +133,12 @@ sendPing = wrapWS WS.sendPing sendPingE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ()) sendPingE = wrapWSE WS.sendPing +-- | Send a DataMessage to the client. +-- Capture SomeException as the result of operation +-- Since 0.2.2 +sendDataMessageE :: (MonadIO m) => WS.DataMessage -> WebSocketsT m (Either SomeException ()) +sendDataMessageE x = ReaderT $ liftIO . tryAny . (`WS.sendDataMessage` x) + -- | Send a close request to the client. -- -- Since 0.2.2