aboutsummaryrefslogtreecommitdiff
path: root/client/index.html
blob: adc2ac8da460dc3c959dd0e355a259c499adf44e (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="UTF-8">
  <title>Client</title>
  <link rel="stylesheet" type="text/css" href="/assets/style.css">
</head>
  <body>
    <div id="main"></div>
    <script type="text/JavaScript" src="/assets/client.js"></script>
    <script>
      var app = Elm.Client.init({node: document.querySelector("main")});

      var roomId = document.location.pathname.split("/")[2];
      var url = "ws://" + document.location.host +
        "/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>