aboutsummaryrefslogtreecommitdiff
path: root/client/index.html
blob: 75ee56d8649df8fead4f0cd7017b97916d33e06a (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="UTF-8">
  <title>Client</title>
</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>