aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-08-03 17:26:45 +0200
committerJasper Van der Jeugt2020-08-03 17:26:45 +0200
commit7e646e1676e08331598ae2b9518f2b1b5f999ba2 (patch)
treef2d25239230cfb711fbd26828e5698b94b876988 /client
parent9ce21e70492ca82c5554e3fa523108755fa721e8 (diff)
Make it deployable
Diffstat (limited to 'client')
-rw-r--r--client/index.html21
-rw-r--r--client/src/Client.elm16
2 files changed, 14 insertions, 23 deletions
diff --git a/client/index.html b/client/index.html
index adc2ac8..8e1333d 100644
--- a/client/index.html
+++ b/client/index.html
@@ -1,19 +1,22 @@
<!DOCTYPE HTML>
<html>
-<head>
- <meta charset="UTF-8">
- <title>Client</title>
- <link rel="stylesheet" type="text/css" href="/assets/style.css">
-</head>
+ <head>
+ <meta charset="UTF-8">
+ <title>Client</title>
+ <link rel="stylesheet" type="text/css" href="$CAFP_BASE/assets/style.css">
+ </head>
<body>
<div id="main"></div>
- <script type="text/JavaScript" src="/assets/client.js"></script>
+ <script type="text/JavaScript" src="$CAFP_BASE/assets/client.js"></script>
<script>
var app = Elm.Client.init({node: document.querySelector("main")});
-
- var roomId = document.location.pathname.split("/")[2];
+ var path = document.location.pathname;
+ if(path.startsWith("$CAFP_BASE")) {
+ path = path.substr("$CAFP_BASE".length);
+ }
+ var roomId = path.split("/")[2];
var url = "ws://" + document.location.host +
- "/rooms/" + roomId + "/events";
+ "$CAFP_BASE/rooms/" + roomId + "/events";
var socket = new WebSocket(url);
app.ports.webSocketOut.subscribe(function(message) {
socket.send(message);
diff --git a/client/src/Client.elm b/client/src/Client.elm
index 7cac663..6b65091 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -42,15 +42,8 @@ type alias GameState =
type Model
= Error String
| Connecting
- { roomId : String
- }
| Game GameState
-parseRoomId : Url -> Result String String
-parseRoomId url = case String.split "/" url.path of
- _ :: "rooms" :: roomId :: _ -> Ok roomId
- _ -> Err <| "Invalid path: " ++ url.path
-
viewPlayer : Messages.PlayerView -> Html msg
viewPlayer player = Html.div [] <|
[ Html.text player.name
@@ -64,10 +57,7 @@ view model = case model of
[ Html.h1 [] [Html.text "Error"]
, Html.p [] [Html.text str]
]
- Connecting state ->
- [ Html.h1 []
- [Html.text <| "Connecting to room " ++ state.roomId ++ "..."]
- ]
+ Connecting -> [Html.h1 [] [Html.text "Connecting to room..."]]
Game game ->
[ Html.h1 [] [Html.text "Players"]
, Html.ul [] <| List.map
@@ -305,9 +295,7 @@ update msg model = case msg of
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 -> (Connecting {roomId = roomId}, Cmd.none)
+ { init = \() url key -> (Connecting, Cmd.none)
, update = update
, subscriptions = subscriptions
, view = \model -> {title = "Client", body = view model}