WIP: CAN'T BE COMPILED. WILL BE SOON FIXED.
This commit is contained in:
parent
c2569bc959
commit
07008d9038
@ -34,7 +34,11 @@ data Output
|
|||||||
| SystemMessage String
|
| SystemMessage String
|
||||||
| UnableToSend String
|
| UnableToSend String
|
||||||
|
|
||||||
data Query a = MessageReceived ArrayBuffer a
|
data Query a
|
||||||
|
= MessageReceived ArrayBuffer a
|
||||||
|
| ConnectionIsDown a
|
||||||
|
| ConnectionIsUp a
|
||||||
|
|
||||||
type Slot = H.Slot Query Output
|
type Slot = H.Slot Query Output
|
||||||
|
|
||||||
type Input = Unit
|
type Input = Unit
|
||||||
@ -193,6 +197,15 @@ handleQuery = case _ of
|
|||||||
H.raise $ AppendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
H.raise $ AppendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
||||||
pure (Just a)
|
pure (Just a)
|
||||||
|
|
||||||
|
ConnectionIsDown a -> do
|
||||||
|
H.modify_ _ { wsUp = false }
|
||||||
|
pure (Just a)
|
||||||
|
|
||||||
|
ConnectionIsUp a -> do
|
||||||
|
H.modify_ _ { wsUp = true }
|
||||||
|
pure (Just a)
|
||||||
|
|
||||||
|
|
||||||
----print_json_string :: forall m. MonadEffect m => MonadState State m => ArrayBuffer -> m Unit
|
----print_json_string :: forall m. MonadEffect m => MonadState State m => ArrayBuffer -> m Unit
|
||||||
--print_json_string arraybuffer = do
|
--print_json_string arraybuffer = do
|
||||||
-- -- fromTypedIPC :: ArrayBuffer -> Effect (Either ParseError (Tuple UInt String))
|
-- -- fromTypedIPC :: ArrayBuffer -> Effect (Either ParseError (Tuple UInt String))
|
||||||
|
@ -34,7 +34,10 @@ data Output
|
|||||||
| SystemMessage String
|
| SystemMessage String
|
||||||
| UnableToSend String
|
| UnableToSend String
|
||||||
|
|
||||||
data Query a = MessageReceived ArrayBuffer a
|
data Query a
|
||||||
|
= MessageReceived ArrayBuffer a
|
||||||
|
| ConnectionIsDown a
|
||||||
|
| ConnectionIsUp a
|
||||||
|
|
||||||
type Slot = H.Slot Query Output
|
type Slot = H.Slot Query Output
|
||||||
|
|
||||||
@ -50,17 +53,11 @@ data RegisterInput
|
|||||||
| REG_INP_pass String
|
| REG_INP_pass String
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= Initialize
|
= HandleAuthenticationInput AuthenticationInput
|
||||||
-- | WebSocketParseError String
|
|
||||||
-- | ConnectWebSocket
|
|
||||||
|
|
||||||
| HandleAuthenticationInput AuthenticationInput
|
|
||||||
| HandleRegisterInput RegisterInput
|
| HandleRegisterInput RegisterInput
|
||||||
|
--
|
||||||
| AuthenticationAttempt Event
|
| AuthenticationAttempt Event
|
||||||
| RegisterAttempt Event
|
| RegisterAttempt Event
|
||||||
| Finalize
|
|
||||||
--| HandleWebSocket (WebSocketEvent WebSocketMessageType)
|
|
||||||
|
|
||||||
type StateAuthenticationForm = { login :: String, pass :: String }
|
type StateAuthenticationForm = { login :: String, pass :: String }
|
||||||
type StateRegistrationForm = { login :: String, email :: String, pass :: String }
|
type StateRegistrationForm = { login :: String, email :: String, pass :: String }
|
||||||
@ -68,7 +65,6 @@ type StateRegistrationForm = { login :: String, email :: String, pass :: String
|
|||||||
type State =
|
type State =
|
||||||
{ authenticationForm :: StateAuthenticationForm
|
{ authenticationForm :: StateAuthenticationForm
|
||||||
, registrationForm :: StateRegistrationForm
|
, registrationForm :: StateRegistrationForm
|
||||||
|
|
||||||
, wsUp :: Boolean
|
, wsUp :: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,10 +74,8 @@ component =
|
|||||||
{ initialState
|
{ initialState
|
||||||
, render
|
, render
|
||||||
, eval: H.mkEval $ H.defaultEval
|
, eval: H.mkEval $ H.defaultEval
|
||||||
{ initialize = Just Initialize
|
{ handleAction = handleAction
|
||||||
, handleAction = handleAction
|
|
||||||
, handleQuery = handleQuery
|
, handleQuery = handleQuery
|
||||||
, finalize = Just Finalize
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,12 +157,6 @@ render { wsUp,
|
|||||||
|
|
||||||
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
||||||
handleAction = case _ of
|
handleAction = case _ of
|
||||||
Initialize ->
|
|
||||||
H.raise $ SystemMessage "Authentication form initialized."
|
|
||||||
|
|
||||||
Finalize ->
|
|
||||||
H.raise $ SystemMessage "Removing the authentication form."
|
|
||||||
|
|
||||||
HandleAuthenticationInput authinp -> do
|
HandleAuthenticationInput authinp -> do
|
||||||
case authinp of
|
case authinp of
|
||||||
AUTH_INP_login v -> H.modify_ _ { authenticationForm { login = v } }
|
AUTH_INP_login v -> H.modify_ _ { authenticationForm { login = v } }
|
||||||
@ -204,7 +192,7 @@ handleAction = case _ of
|
|||||||
, email: Just (Email.Email email)
|
, email: Just (Email.Email email)
|
||||||
, password: pass }
|
, password: pass }
|
||||||
H.raise $ MessageToSend message
|
H.raise $ MessageToSend message
|
||||||
H.raise $ AppendMessage "[😇] Trying to register"
|
H.raise $ AppendMessage $ "[😇] Trying to register (login: " <> login <> ")"
|
||||||
|
|
||||||
AuthenticationAttempt ev -> do
|
AuthenticationAttempt ev -> do
|
||||||
H.liftEffect $ Event.preventDefault ev
|
H.liftEffect $ Event.preventDefault ev
|
||||||
@ -221,8 +209,7 @@ handleAction = case _ of
|
|||||||
login, pass -> do
|
login, pass -> do
|
||||||
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkLogin { login: login, password: pass }
|
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkLogin { login: login, password: pass }
|
||||||
H.raise $ MessageToSend message
|
H.raise $ MessageToSend message
|
||||||
H.raise $ AppendMessage $ "[😇] Trying to connect with login: " <> login
|
H.raise $ AppendMessage $ "[😇] Trying to authenticate (login: " <> login <> ")"
|
||||||
|
|
||||||
|
|
||||||
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
|
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
|
||||||
handleQuery = case _ of
|
handleQuery = case _ of
|
||||||
@ -247,7 +234,7 @@ handleQuery = case _ of
|
|||||||
pure (Just a)
|
pure (Just a)
|
||||||
-- The authentication was a success!
|
-- The authentication was a success!
|
||||||
(AuthD.GotToken msg) -> do
|
(AuthD.GotToken msg) -> do
|
||||||
H.raise $ AppendMessage $ "[😈] Success! user " <> (show msg.uid) <> " has token: " <> msg.token
|
H.raise $ AppendMessage $ "[🎉] Authenticated!"
|
||||||
H.raise $ AuthToken (Tuple msg.uid msg.token)
|
H.raise $ AuthToken (Tuple msg.uid msg.token)
|
||||||
pure (Just a)
|
pure (Just a)
|
||||||
-- WTH?!
|
-- WTH?!
|
||||||
@ -255,10 +242,18 @@ handleQuery = case _ of
|
|||||||
H.raise $ AppendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
H.raise $ AppendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
||||||
pure Nothing
|
pure Nothing
|
||||||
|
|
||||||
|
ConnectionIsDown a -> do
|
||||||
|
H.modify_ _ { wsUp = false }
|
||||||
|
pure (Just a)
|
||||||
|
|
||||||
|
ConnectionIsUp a -> do
|
||||||
|
H.modify_ _ { wsUp = true }
|
||||||
|
pure (Just a)
|
||||||
|
|
||||||
--print_json_string :: forall m. MonadEffect m => MonadState State m => ArrayBuffer -> m Unit
|
--print_json_string :: forall m. MonadEffect m => MonadState State m => ArrayBuffer -> m Unit
|
||||||
print_json_string arraybuffer = do
|
--print_json_string arraybuffer = do
|
||||||
-- fromTypedIPC :: ArrayBuffer -> Effect (Either ParseError (Tuple UInt String))
|
-- -- fromTypedIPC :: ArrayBuffer -> Effect (Either ParseError (Tuple UInt String))
|
||||||
value <- H.liftEffect $ IPC.fromTypedIPC arraybuffer
|
-- value <- H.liftEffect $ IPC.fromTypedIPC arraybuffer
|
||||||
H.raise $ AppendMessage $ case (value) of
|
-- H.raise $ AppendMessage $ case (value) of
|
||||||
Left _ -> "Cannot even fromTypedIPC the message."
|
-- Left _ -> "Cannot even fromTypedIPC the message."
|
||||||
Right (Tuple messageTypeNumber string) -> "Number is: " <> show messageTypeNumber <> ", received string: " <> string
|
-- Right (Tuple messageTypeNumber string) -> "Number is: " <> show messageTypeNumber <> ", received string: " <> string
|
||||||
|
@ -24,8 +24,6 @@ data Action
|
|||||||
|
|
||||||
type State = { token :: Maybe String
|
type State = { token :: Maybe String
|
||||||
, uid :: Maybe Int
|
, uid :: Maybe Int
|
||||||
, auth_ws_connected :: Boolean
|
|
||||||
, dns_ws_connected :: Boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChildSlots =
|
type ChildSlots =
|
||||||
@ -55,8 +53,6 @@ component =
|
|||||||
initialState :: forall i. i -> State
|
initialState :: forall i. i -> State
|
||||||
initialState _ = { token: Nothing
|
initialState _ = { token: Nothing
|
||||||
, uid: Nothing
|
, uid: Nothing
|
||||||
, auth_ws_connected: false
|
|
||||||
, dns_ws_connected: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
||||||
@ -119,13 +115,16 @@ handleAction = case _ of
|
|||||||
AAI.SystemMessage message -> H.tell _log unit (Log.SystemLog message)
|
AAI.SystemMessage message -> H.tell _log unit (Log.SystemLog message)
|
||||||
AAI.UnableToSend message -> H.tell _log unit (Log.UnableToSend message)
|
AAI.UnableToSend message -> H.tell _log unit (Log.UnableToSend message)
|
||||||
|
|
||||||
-- TODO: depending on the current page, we should provide the received message to
|
-- TODO: depending on the current page, we should provide the received message to different components.
|
||||||
-- different components.
|
|
||||||
AuthDEvent ev -> case ev of
|
AuthDEvent ev -> case ev of
|
||||||
WS.MessageReceived (Tuple _ message) ->
|
WS.MessageReceived (Tuple _ message) ->
|
||||||
H.tell _af unit (AF.MessageReceived message)
|
H.tell _af unit (AF.MessageReceived message)
|
||||||
WS.WSJustConnected -> H.modify_ _ { auth_ws_connected = true }
|
WS.WSJustConnected -> do
|
||||||
WS.WSJustClosed -> H.modify_ _ { auth_ws_connected = false }
|
H.tell _af unit AF.ConnectionIsUp
|
||||||
|
H.tell _aai unit AAI.ConnectionIsUp
|
||||||
|
WS.WSJustClosed -> do
|
||||||
|
H.tell _af unit AF.ConnectionIsDown
|
||||||
|
H.tell _aai unit AAI.ConnectionIsDown
|
||||||
WS.AppendMessage msg -> H.tell _log unit (Log.SimpleLog msg)
|
WS.AppendMessage msg -> H.tell _log unit (Log.SimpleLog msg)
|
||||||
WS.AppendSystemMessage msg -> H.tell _log unit (Log.SystemLog msg)
|
WS.AppendSystemMessage msg -> H.tell _log unit (Log.SystemLog msg)
|
||||||
WS.UnableToSend msg -> H.tell _log unit (Log.UnableToSend msg)
|
WS.UnableToSend msg -> H.tell _log unit (Log.UnableToSend msg)
|
||||||
@ -133,8 +132,10 @@ handleAction = case _ of
|
|||||||
DNSManagerDEvent ev -> case ev of
|
DNSManagerDEvent ev -> case ev of
|
||||||
WS.MessageReceived (Tuple _ _) -> pure unit
|
WS.MessageReceived (Tuple _ _) -> pure unit
|
||||||
-- TODO: H.tell _ndi unit (NewDomainInterface.MessageReceived message)
|
-- TODO: H.tell _ndi unit (NewDomainInterface.MessageReceived message)
|
||||||
WS.WSJustConnected -> H.modify_ _ { dns_ws_connected = true }
|
WS.WSJustConnected -> do
|
||||||
WS.WSJustClosed -> H.modify_ _ { dns_ws_connected = false }
|
H.tell _ndi unit NewDomainInterface.ConnectionIsUp
|
||||||
|
WS.WSJustClosed -> do
|
||||||
|
H.tell _ndi unit NewDomainInterface.ConnectionIsDown
|
||||||
WS.AppendMessage msg -> H.tell _log unit (Log.SimpleLog msg)
|
WS.AppendMessage msg -> H.tell _log unit (Log.SimpleLog msg)
|
||||||
WS.AppendSystemMessage msg -> H.tell _log unit (Log.SystemLog msg)
|
WS.AppendSystemMessage msg -> H.tell _log unit (Log.SystemLog msg)
|
||||||
WS.UnableToSend msg -> H.tell _log unit (Log.UnableToSend msg)
|
WS.UnableToSend msg -> H.tell _log unit (Log.UnableToSend msg)
|
||||||
|
@ -32,7 +32,6 @@ import Halogen.HTML.Events as HE
|
|||||||
import Halogen.HTML.Properties as HP
|
import Halogen.HTML.Properties as HP
|
||||||
import Web.Event.Event (Event)
|
import Web.Event.Event (Event)
|
||||||
import Web.Event.Event as Event
|
import Web.Event.Event as Event
|
||||||
import Web.Socket.ReadyState (ReadyState(Connecting, Open, Closing, Closed))
|
|
||||||
import Web.Socket.WebSocket as WS
|
import Web.Socket.WebSocket as WS
|
||||||
|
|
||||||
import Effect.Class (class MonadEffect)
|
import Effect.Class (class MonadEffect)
|
||||||
@ -49,11 +48,19 @@ import Web.Socket.BinaryType (BinaryType(ArrayBuffer))
|
|||||||
-- Root component module
|
-- Root component module
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
data Output = Void
|
data Output
|
||||||
|
= MessageToSend ArrayBuffer
|
||||||
|
| AppendMessage String
|
||||||
|
| SystemMessage String
|
||||||
|
| UnableToSend String
|
||||||
|
|
||||||
|
data Query a
|
||||||
|
= MessageReceived ArrayBuffer a
|
||||||
|
| ConnectionIsDown a
|
||||||
|
| ConnectionIsUp a
|
||||||
|
|
||||||
type Slot = H.Slot Query Output
|
type Slot = H.Slot Query Output
|
||||||
|
|
||||||
type Query :: forall k. k -> Type
|
|
||||||
type Query = Const Void
|
|
||||||
-- Input = url token
|
-- Input = url token
|
||||||
type Input = Tuple String String
|
type Input = Tuple String String
|
||||||
|
|
||||||
@ -62,11 +69,7 @@ data NewDomainFormAction
|
|||||||
| UpdateSelectedDomain String
|
| UpdateSelectedDomain String
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= Initialize
|
= UpdateAcceptedDomains (Array String)
|
||||||
| WebSocketParseError String
|
|
||||||
| ConnectWebSocket
|
|
||||||
|
|
||||||
| UpdateAcceptedDomains (Array String)
|
|
||||||
| UpdateMyDomains (Array String)
|
| UpdateMyDomains (Array String)
|
||||||
|
|
||||||
| AuthenticateToDNSManager
|
| AuthenticateToDNSManager
|
||||||
@ -76,7 +79,6 @@ data Action
|
|||||||
| NewDomainAttempt Event
|
| NewDomainAttempt Event
|
||||||
| RemoveDomain String
|
| RemoveDomain String
|
||||||
| EnterDomain String
|
| EnterDomain String
|
||||||
| Finalize
|
|
||||||
| HandleWebSocket (WebSocketEvent WebSocketMessageType)
|
| HandleWebSocket (WebSocketEvent WebSocketMessageType)
|
||||||
|
|
||||||
type NewDomainFormState
|
type NewDomainFormState
|
||||||
@ -84,22 +86,12 @@ type NewDomainFormState
|
|||||||
, selected_domain :: String
|
, selected_domain :: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type WSInfo
|
|
||||||
= { url :: String
|
|
||||||
, connection :: Maybe WS.WebSocket
|
|
||||||
, reconnect :: Boolean
|
|
||||||
, token :: String
|
|
||||||
}
|
|
||||||
|
|
||||||
type State =
|
type State =
|
||||||
{ messages :: Array String
|
{ newDomainForm :: NewDomainFormState
|
||||||
, messageHistoryLength :: Int
|
|
||||||
|
|
||||||
, newDomainForm :: NewDomainFormState
|
|
||||||
, accepted_domains :: Array String
|
, accepted_domains :: Array String
|
||||||
, my_domains :: Array String
|
, my_domains :: Array String
|
||||||
|
|
||||||
, wsInfo :: WSInfo
|
, wsUp :: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
component :: forall m. MonadAff m => H.Component Query Input Output m
|
component :: forall m. MonadAff m => H.Component Query Input Output m
|
||||||
@ -110,7 +102,7 @@ component =
|
|||||||
, eval: H.mkEval $ H.defaultEval
|
, eval: H.mkEval $ H.defaultEval
|
||||||
{ initialize = Just Initialize
|
{ initialize = Just Initialize
|
||||||
, handleAction = handleAction
|
, handleAction = handleAction
|
||||||
, finalize = Just Finalize
|
, handleQuery = handleQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,27 +220,6 @@ render {
|
|||||||
|
|
||||||
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
||||||
handleAction = case _ of
|
handleAction = case _ of
|
||||||
Initialize ->
|
|
||||||
handleAction ConnectWebSocket
|
|
||||||
|
|
||||||
Finalize -> do
|
|
||||||
{ wsInfo } <- H.get
|
|
||||||
systemMessage "Finalize"
|
|
||||||
case wsInfo.connection of
|
|
||||||
Nothing -> systemMessage "No socket? How is that even possible?"
|
|
||||||
Just socket -> H.liftEffect $ WS.close socket
|
|
||||||
|
|
||||||
WebSocketParseError error ->
|
|
||||||
systemMessage $ renderError (UnknownError error)
|
|
||||||
|
|
||||||
ConnectWebSocket -> do
|
|
||||||
{ wsInfo } <- H.get
|
|
||||||
systemMessage ("Connecting to \"" <> wsInfo.url <> "\"...")
|
|
||||||
webSocket <- H.liftEffect $ WS.create wsInfo.url []
|
|
||||||
H.liftEffect $ WS.setBinaryType webSocket ArrayBuffer
|
|
||||||
H.modify_ _ { wsInfo { connection = Just webSocket } }
|
|
||||||
void $ H.subscribe (HandleWebSocket <$> webSocketEmitter webSocket)
|
|
||||||
|
|
||||||
UpdateAcceptedDomains domains -> do
|
UpdateAcceptedDomains domains -> do
|
||||||
H.modify_ _ { accepted_domains = domains }
|
H.modify_ _ { accepted_domains = domains }
|
||||||
|
|
||||||
@ -256,13 +227,9 @@ handleAction = case _ of
|
|||||||
H.modify_ _ { my_domains = domains }
|
H.modify_ _ { my_domains = domains }
|
||||||
|
|
||||||
AuthenticateToDNSManager -> do
|
AuthenticateToDNSManager -> do
|
||||||
{ wsInfo } <- H.get
|
|
||||||
appendMessage $ "[🤖] Trying to authenticate..."
|
appendMessage $ "[🤖] Trying to authenticate..."
|
||||||
case wsInfo.connection of
|
message <- H.liftEffect $ DNSManager.serialize $ DNSManager.MkLogin { token: wsInfo.token }
|
||||||
Nothing -> appendMessage $ "[🤖] Can't authenticate, websocket is down!"
|
H.raise $ MessageToSend message
|
||||||
Just webSocket -> H.liftEffect $ do
|
|
||||||
ab <- DNSManager.serialize $ DNSManager.MkLogin { token: wsInfo.token }
|
|
||||||
sendArrayBuffer webSocket ab
|
|
||||||
|
|
||||||
HandleNewDomainInput adduserinp -> do
|
HandleNewDomainInput adduserinp -> do
|
||||||
case adduserinp of
|
case adduserinp of
|
||||||
@ -304,37 +271,21 @@ handleAction = case _ of
|
|||||||
{ wsInfo, newDomainForm } <- H.get
|
{ wsInfo, newDomainForm } <- H.get
|
||||||
let new_domain = build_new_domain newDomainForm.new_domain newDomainForm.selected_domain
|
let new_domain = build_new_domain newDomainForm.new_domain newDomainForm.selected_domain
|
||||||
|
|
||||||
case wsInfo.connection, new_domain of
|
case new_domain of
|
||||||
Nothing, _ ->
|
"" ->
|
||||||
unableToSend "Not connected to server."
|
|
||||||
|
|
||||||
Just _, "" ->
|
|
||||||
unableToSend "You didn't enter the new domain!"
|
unableToSend "You didn't enter the new domain!"
|
||||||
|
_ -> do
|
||||||
Just webSocket, _ -> do
|
message <- H.liftEffect
|
||||||
H.liftEffect (WS.readyState webSocket) >>= case _ of
|
$ DNSManager.serialize
|
||||||
Connecting ->
|
$ DNSManager.MkNewDomain { domain: new_domain }
|
||||||
unableToSend "Still connecting to server."
|
H.raise $ MessageToSend message
|
||||||
|
|
||||||
Closing ->
|
|
||||||
unableToSend "Connection to server is closing."
|
|
||||||
|
|
||||||
Closed -> do
|
|
||||||
unableToSend "Connection to server has been closed."
|
|
||||||
maybeCurrentConnection <- H.gets _.wsInfo.connection
|
|
||||||
when (isJust maybeCurrentConnection) do
|
|
||||||
H.modify_ _ { wsInfo { connection = Nothing, reconnect = true } }
|
|
||||||
|
|
||||||
Open -> do
|
|
||||||
H.liftEffect $ do
|
|
||||||
ab <- DNSManager.serialize $ DNSManager.MkNewDomain { domain: new_domain }
|
|
||||||
sendArrayBuffer webSocket ab
|
|
||||||
appendMessage "[😇] Trying to add a new domain"
|
appendMessage "[😇] Trying to add a new domain"
|
||||||
handleAction $ HandleNewDomainInput $ INP_newdomain ""
|
handleAction $ HandleNewDomainInput $ INP_newdomain ""
|
||||||
|
|
||||||
HandleWebSocket wsEvent ->
|
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
|
||||||
case wsEvent of
|
handleQuery = case _ of
|
||||||
WebSocketMessage messageEvent -> do
|
|
||||||
|
MessageReceived message a -> do
|
||||||
receivedMessage <- H.liftEffect $ DNSManager.deserialize messageEvent.message
|
receivedMessage <- H.liftEffect $ DNSManager.deserialize messageEvent.message
|
||||||
case receivedMessage of
|
case receivedMessage of
|
||||||
-- Cases where we didn't understand the message.
|
-- Cases where we didn't understand the message.
|
||||||
@ -345,6 +296,7 @@ handleAction = case _ of
|
|||||||
handleAction $ WebSocketParseError ("JSON parsing error: " <> jerr)
|
handleAction $ WebSocketParseError ("JSON parsing error: " <> jerr)
|
||||||
(DNSManager.UnknownError unerr) -> handleAction $ WebSocketParseError ("Parsing error: DNSManager.UnknownError" <> (show unerr))
|
(DNSManager.UnknownError unerr) -> handleAction $ WebSocketParseError ("Parsing error: DNSManager.UnknownError" <> (show unerr))
|
||||||
(DNSManager.UnknownNumber ) -> handleAction $ WebSocketParseError ("Parsing error: DNSManager.UnknownNumber")
|
(DNSManager.UnknownNumber ) -> handleAction $ WebSocketParseError ("Parsing error: DNSManager.UnknownNumber")
|
||||||
|
pure Nothing
|
||||||
|
|
||||||
-- Cases where we understood the message.
|
-- Cases where we understood the message.
|
||||||
Right received_msg -> do
|
Right received_msg -> do
|
||||||
@ -389,41 +341,15 @@ handleAction = case _ of
|
|||||||
-- WTH?!
|
-- WTH?!
|
||||||
_ -> do
|
_ -> do
|
||||||
appendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
appendMessage $ "[😈] Failed! Authentication server didn't send a valid message."
|
||||||
|
pure (Just a)
|
||||||
|
|
||||||
WebSocketOpen -> do
|
ConnectionIsDown a -> do
|
||||||
{ wsInfo } <- H.get
|
H.modify_ _ { wsUp = false }
|
||||||
systemMessage ("Successfully connected to WebSocket at \"" <> wsInfo.url <> "\"!🎉")
|
pure (Just a)
|
||||||
handleAction AuthenticateToDNSManager
|
|
||||||
|
|
||||||
WebSocketClose { code, reason, wasClean } -> do
|
ConnectionIsUp a -> do
|
||||||
systemMessage $ renderCloseMessage code wasClean reason
|
H.modify_ _ { wsUp = true }
|
||||||
maybeCurrentConnection <- H.gets _.wsInfo.connection
|
pure (Just a)
|
||||||
when (isJust maybeCurrentConnection) do
|
|
||||||
H.modify_ _ { wsInfo { connection = Nothing, reconnect = true } }
|
|
||||||
|
|
||||||
WebSocketError errorType ->
|
|
||||||
systemMessage $ renderError errorType
|
|
||||||
|
|
||||||
where
|
|
||||||
renderCloseMessage
|
|
||||||
:: Int
|
|
||||||
-> Boolean
|
|
||||||
-> String
|
|
||||||
-> String
|
|
||||||
renderCloseMessage code wasClean = case _ of
|
|
||||||
"" -> baseCloseMessage
|
|
||||||
reason -> baseCloseMessage <> "Reason: " <> reason
|
|
||||||
where
|
|
||||||
baseCloseMessage :: String
|
|
||||||
baseCloseMessage =
|
|
||||||
String.joinWith " "
|
|
||||||
[ "Connection to WebSocket closed"
|
|
||||||
, "[ CODE:"
|
|
||||||
, show code
|
|
||||||
, "|"
|
|
||||||
, if wasClean then "CLEAN" else "DIRTY"
|
|
||||||
, "]"
|
|
||||||
]
|
|
||||||
|
|
||||||
build_new_domain :: String -> String -> String
|
build_new_domain :: String -> String -> String
|
||||||
build_new_domain sub tld
|
build_new_domain sub tld
|
||||||
|
Loading…
Reference in New Issue
Block a user