aboutsummaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/Client.elm26
1 files changed, 20 insertions, 6 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm
index cc144e2..f4247f7 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -1,11 +1,16 @@
-module Client exposing (main)
+port module Client exposing (main)
import Browser
import Html exposing (Html)
import Url exposing (Url)
-type Message
+port webSocketIn : (String -> msg) -> Sub msg
+port webSocketOut : String -> Cmd msg
+
+type Msg
= Ignore
+ | Send
+ | WebSocketIn String
type Model
= Error String
@@ -18,7 +23,7 @@ parseRoomId url = case String.split "/" url.path of
_ :: "rooms" :: roomId :: _ -> Ok roomId
_ -> Err <| "Invalid path: " ++ url.path
-view : Model -> List (Html Message)
+view : Model -> List (Html Msg)
view model = case model of
Error str ->
[ Html.h1 [] [Html.text "Error"]
@@ -28,13 +33,22 @@ view model = case model of
[ Html.h1 [] [Html.text <| "Room " ++ room.id]
]
-main : Program () Model Message
+subscriptions : Model -> Sub Msg
+subscriptions model = webSocketIn WebSocketIn
+
+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)
+
+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)
- , update = \_ model -> (model, Cmd.none)
- , subscriptions = \_ -> Sub.none
+ , update = update
+ , subscriptions = subscriptions
, view = \model -> {title = "Client", body = view model}
, onUrlChange = \url -> Ignore
, onUrlRequest = \urlRequest -> Ignore