-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
48 lines (43 loc) · 1.56 KB
/
index.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="google-site-verification" content="z1-SMuAt1leKac6D98K8UMccTF2ffflFPhGbI--nZ9k" />
<title>Ultimate Tic-Tac-Toe!</title>
<link rel="stylesheet" type="text/css" href="/style.css?v=$CSS_HASH">
<script type="text/javascript" src="/main.js"></script>
</head>
<body>
<script>
var app = Elm.Main.init({
flags: {
remotePlayServerUrl: "https://ultimate-tictactoe-server.osc-fr1.scalingo.io"
}});
var socket = null;
app.ports.joinRemoteGame.subscribe(function(gameUrl) {
console.log("Creating new websocket to url: " + gameUrl);
try {
socket = new WebSocket(gameUrl);
} catch(err) {
app.ports.gameMessageReceiver.send("E " + err);
}
// When a message comes into our WebSocket, we pass the message along
// to the `messageReceiver` port.
socket.addEventListener("error", function(error) {
console.error("Error! " + error);
app.ports.gameMessageReceiver.send("E " + error);
});
// When a message comes into our WebSocket, we pass the message along
// to the `messageReceiver` port.
socket.addEventListener("message", function(event) {
app.ports.gameMessageReceiver.send(event.data);
});
// When a command goes to the `sendMessage` port, we pass the message
// along to the WebSocket.
app.ports.sendGameMessage.subscribe(function(message) {
socket.send(message);
});
});
</script>
</body>
</html>