on develop help sign in
Accept both text and binary data from WebSocket messages

Still only send binary

commiteb61be8a2c7372df6b243bed7c37fbdb4d04938a authorRyan Trinkle <ryan.trinkle@gmail.com> dateSat 23 Jan 2016, 03:17 (11 years ago) parent2dde12e
1 file changed+7−2
src-ghcjs/Reflex/Dom/WebSocket/Foreign.hs+7−2
src-ghcjs/Reflex/Dom/WebSocket/Foreign.hs+7−2
@@ -17,6 +17,8 @@ import Control.Monad.Reader
1717import GHCJS.Buffer
1818import JavaScript.TypedArray.ArrayBuffer as JS
1919import GHCJS.Marshal.Pure
20+import GHCJS.Foreign.Internal
21+import Data.Text.Encoding
2022
2123data JSWebSocket = JSWebSocket { unWebSocket :: WebSocket }
2224
@@ -28,8 +30,11 @@ newWebSocket _ url onMessage onOpen onClose = do
2830 _ <- on ws message $ do
2931 e <- ask
3032 d <- getData e
31− ab <- liftIO $ unsafeFreeze $ pFromJSVal d
32− liftIO $ onMessage $ toByteString 0 Nothing $ createFromArrayBuffer ab
33+ liftIO $ case jsTypeOf d of
34+ String -> onMessage $ encodeUtf8 $ pFromJSVal d
35+ _ -> do
36+ ab <- unsafeFreeze $ pFromJSVal d
37+ onMessage $ toByteString 0 Nothing $ createFromArrayBuffer ab
3338 _ <- on ws closeEvent $ liftIO onClose
3439 return $ JSWebSocket ws
3540