[websockets] implement reconnection when WS closes

parent 97d4977f
......@@ -38,16 +38,12 @@ appCpt = here.component "container" cpt where
-- |
-- load Local Storage cache (if exists)
useFirstEffect' $
useFirstEffect' $ do
R2.loadLocalStorageState R2.appParamsKey cache
-- | Render
-- |
pure $
hydrateStore
{ cacheParams: cache'
}
pure $ hydrateStore { cacheParams: cache' }
--------------------------------------------------------------
......@@ -87,7 +83,6 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
mainApp :: R2.Leaf ()
mainApp = R2.leaf mainAppCpt
mainAppCpt :: R.Component ()
mainAppCpt = here.component "main" cpt where
cpt _ _ = do
......
......@@ -14,6 +14,7 @@ import Data.Traversable (for, traverse)
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Ref as Ref
import Effect.Timer (setTimeout)
import Effect.Var (($=))
import Effect.Var as Var
import Foreign as F
......@@ -292,6 +293,13 @@ connect ws@(WSNotification ws') url session = do
let subscription = WSSubscribe topic
here.log2 "[connect] pending subscription" subscription
send ws subscription)
conn.onclose $= (\_ -> do
Ref.write Nothing ws'.connection
void $ setTimeout 1000 $ do
connect ws url session
)
conn.onmessage $= onmessage
pure unit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment