aboutsummaryrefslogtreecommitdiff
path: root/client/index.html
blob: 518b71da1d6fa0cc70d36e9a6aba3dff1b100ea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Client</title>
    <link rel="stylesheet" type="text/css" href="$CAFP_BASE/assets/style.css">
    <meta name="viewport" content="width=device-width">
  </head>
  <body>
    <div id="main"></div>
    <script type="text/JavaScript" src="$CAFP_BASE/assets/client.js"></script>
    <script>
      var app = Elm.Client.init({node: document.querySelector("main")});
      var protocol = "ws:";
      if(document.location.protocol == "https:") {
          protocol = "wss:"
      }
      var path = document.location.pathname;
      if(path.startsWith("$CAFP_BASE")) {
          path = path.substr("$CAFP_BASE".length);
      }
      var roomId = path.split("/")[2];
      var url = protocol + "//" + document.location.host +
        "$CAFP_BASE/rooms/" + roomId + "/events";
      var socket = new WebSocket(url);
      app.ports.webSocketOut.subscribe(function(message) {
        socket.send(message);
      });
      socket.addEventListener("message", function(event) {
        app.ports.webSocketIn.send(event.data);
      });
    </script>
  </body>
</html>