packages feed

miso 0.7.6.0 → 0.7.7.0

raw patch · 3 files changed

+23/−13 lines, 3 files

Files

ghcjs-src/Miso/Subscription/WebSocket.hs view
@@ -57,6 +57,10 @@ {-# NOINLINE websocket #-} websocket = unsafePerformIO (newIORef Nothing) +closedCode :: IORef (Maybe CloseCode)+{-# NOINLINE closedCode #-}+closedCode = unsafePerformIO (newIORef Nothing)+ secs :: Int -> Int secs = (*1000000) @@ -67,20 +71,13 @@   -> Protocols   -> (WebSocket m -> action)   -> Sub action model-websocketSub (URL u) (Protocols ps) f _ sink = do+websocketSub (URL u) (Protocols ps) f getModel sink = do   socket <- createWebSocket u ps   writeIORef websocket (Just socket)-  --  Handle Reconnects-  void . forkIO . forever $ do-    threadDelay (secs 3)-    Just s <- readIORef websocket-    status <- getSocketState' s-    when (status == 3) $ do-      atomicWriteIORef websocket-        =<< Just <$> createWebSocket u ps+  void . forkIO $ handleReconnect   onOpen socket =<< do-    asyncCallback $ do-      sink (f WebSocketOpen)+    writeIORef closedCode Nothing+    asyncCallback $ sink (f WebSocketOpen)   onMessage socket =<< do     asyncCallback1 $ \v -> do       d <- parse =<< getData v@@ -88,13 +85,26 @@   onClose socket =<< do     asyncCallback1 $ \e -> do       code <- codeToCloseCode <$> getCode e+      writeIORef closedCode (Just code)       reason <- getReason e       clean <- wasClean e       sink $ f (WebSocketClose code clean reason)   onError socket =<< do     asyncCallback1 $ \v -> do+      writeIORef closedCode Nothing       d <- parse =<< getData v       sink $ f (WebSocketError d)+  where+    handleReconnect = do+      threadDelay (secs 3)+      Just s <- readIORef websocket+      status <- getSocketState' s+      code <- readIORef closedCode+      if status == 3+        then do+          unless (code == Just CLOSE_NORMAL) $+            websocketSub (URL u) (Protocols ps) f getModel sink+        else handleReconnect  -- | Sends message to a websocket server send :: ToJSON a => a -> IO ()
miso.cabal view
@@ -1,5 +1,5 @@ name:                miso-version:             0.7.6.0+version:             0.7.7.0 category:            Web, Miso, Data Structures license:             BSD3 license-file:        LICENSE
src/Miso/Event/Types.hs view
@@ -15,7 +15,7 @@ import qualified Data.Map as M import           GHC.Generics import           Miso.String-import           Data.Aeson+import           Data.Aeson (FromJSON)  -- | Type used for Keyboard events. --