[websockets] correctly pick ws/wss protocol based on window.location

parent 557c4dc5
Pipeline #6258 failed with stages
...@@ -106,7 +106,8 @@ mainAppCpt = here.component "main" cpt where ...@@ -106,7 +106,8 @@ mainAppCpt = here.component "main" cpt where
(Sessions.Sessions { sessions }) <- T.read boxes.sessions (Sessions.Sessions { sessions }) <- T.read boxes.sessions
let session = Seq.head sessions let session = Seq.head sessions
-- here.log2 "[mainApp] sessions" sessions' -- here.log2 "[mainApp] sessions" sessions'
Notifications.connect ws "ws://localhost:8008/ws" session wsProto <- Notifications.wsProtocol
Notifications.connect ws (wsProto <> "://localhost:8008/ws") session
-- T.write_ ws boxes.wsNotification -- T.write_ ws boxes.wsNotification
-- NOTE: Dummy subscription -- NOTE: Dummy subscription
-- let action = NotificationsT.InsertCallback (NotificationsT.UpdateTree (-1)) "some-uuid" (\_ -> here.log "callback!") -- let action = NotificationsT.InsertCallback (NotificationsT.UpdateTree (-1)) "some-uuid" (\_ -> here.log "callback!")
......
...@@ -21,6 +21,7 @@ import Foreign as F ...@@ -21,6 +21,7 @@ import Foreign as F
import Gargantext.Components.Notifications.Types import Gargantext.Components.Notifications.Types
import Gargantext.Sessions.Types (Session(..)) import Gargantext.Sessions.Types (Session(..))
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils (protocol)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Prelude import Prelude
import Reactix as R import Reactix as R
...@@ -143,6 +144,17 @@ performAction (WSNotification ws') (Call notification) = do ...@@ -143,6 +144,17 @@ performAction (WSNotification ws') (Call notification) = do
callNotification state notification callNotification state notification
-- | Correctly choose between "ws" and "wss" protocols based on what
-- | is the current window location
wsProtocol :: Effect String
wsProtocol = do
proto <- protocol
pure (if proto == "http" then "ws" else "wss")
-- | Main WebSockets connect functionality. Handles incoming messages,
-- | authorizes user (if logged in), tries to reconnect when the
-- | connection drops
connect :: WSNotification -> String -> (Maybe Session) -> Effect Unit connect :: WSNotification -> String -> (Maybe Session) -> Effect Unit
connect ws@(WSNotification ws') url session = do connect ws@(WSNotification ws') url session = do
mConn <- Ref.read ws'.connection mConn <- Ref.read ws'.connection
......
...@@ -17,7 +17,7 @@ import Partial.Unsafe (unsafePartial) ...@@ -17,7 +17,7 @@ import Partial.Unsafe (unsafePartial)
import Prelude import Prelude
import Web.HTML as WHTML import Web.HTML as WHTML
import Web.HTML.Location as WHL import Web.HTML.Location as WHL
import Web.HTML.Window (location) import Web.HTML.Window as WHW
-- | TODO (hard coded) -- | TODO (hard coded)
csrfMiddlewareToken :: String csrfMiddlewareToken :: String
...@@ -103,11 +103,14 @@ sortWith :: forall a b f. Functor f => ...@@ -103,11 +103,14 @@ sortWith :: forall a b f. Functor f =>
sortWith f xs = A.toUnfoldable $ A.sortWith f (A.fromFoldable xs) sortWith f xs = A.toUnfoldable $ A.sortWith f (A.fromFoldable xs)
location :: Effect WHL.Location
location = WHTML.window >>= WHW.location
href :: Effect String href :: Effect String
href = do href = location >>= WHL.href
w <- WHTML.window
loc <- location w protocol :: Effect String
WHL.href loc protocol = location >>= WHL.protocol
nbsp :: Int -> String nbsp :: Int -> String
......
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