aboutsummaryrefslogtreecommitdiff
path: root/client/src/Client.elm
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-07-29 21:14:12 +0200
committerJasper Van der Jeugt2020-07-29 21:14:12 +0200
commit49b346b7ebe98051a618d88a39d9b02f13edf33c (patch)
tree41d126d23ed0d3bcc469622b510b67e71d273821 /client/src/Client.elm
parent057d954fe8d3265fc122f4a3066eab15eb7653d3 (diff)
Welcome Bye
Diffstat (limited to 'client/src/Client.elm')
-rw-r--r--client/src/Client.elm19
1 files changed, 13 insertions, 6 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm
index f4247f7..ffb2b0e 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -2,6 +2,8 @@ port module Client exposing (main)
import Browser
import Html exposing (Html)
+import Json.Decode
+import Messages
import Url exposing (Url)
port webSocketIn : (String -> msg) -> Sub msg
@@ -14,8 +16,8 @@ type Msg
type Model
= Error String
- | JoinRoom
- { id : String
+ | Connecting
+ { roomId : String
}
parseRoomId : Url -> Result String String
@@ -29,8 +31,9 @@ view model = case model of
[ Html.h1 [] [Html.text "Error"]
, Html.p [] [Html.text str]
]
- JoinRoom room ->
- [ Html.h1 [] [Html.text <| "Room " ++ room.id]
+ Connecting state ->
+ [ Html.h1 []
+ [Html.text <| "Connecting to room " ++ state.roomId ++ "..."]
]
subscriptions : Model -> Sub Msg
@@ -40,13 +43,17 @@ update : Msg -> Model -> (Model, Cmd Msg)
update msg model = case msg of
Ignore -> (model, Cmd.none)
Send -> (model, webSocketOut "Hi")
- WebSocketIn str -> Debug.log str (model, Cmd.none)
+ WebSocketIn json ->
+ case Json.Decode.decodeString Messages.jsonDecServerMessage json of
+ Err str -> (Error <| Json.Decode.errorToString str, Cmd.none)
+ Ok Messages.Welcome -> Debug.log "Welcome" (model, Cmd.none)
+ Ok Messages.Bye -> Debug.log "Bye" (model, Cmd.none)
main : Program () Model Msg
main = Browser.application
{ init = \() url key -> case parseRoomId url of
Err str -> (Error <| "Could not parse room ID: " ++ str, Cmd.none)
- Ok roomId -> (JoinRoom {id = roomId}, Cmd.none)
+ Ok roomId -> (Connecting {roomId = roomId}, Cmd.none)
, update = update
, subscriptions = subscriptions
, view = \model -> {title = "Client", body = view model}