-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (39 loc) · 1.16 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
<!DOCTYPE HTML>
<html>
<head>
<!--
<link rel="shortcut icon" href="img/8puzzle.ico">
-->
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Nunito">
<link rel="stylesheet" type="text/css" href="css/Main.css">
<meta charset="UTF-8">
<title>250</title>
<script type="text/javascript" src="Main.min.js"></script>
</head>
<body>
<div id="elm"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('elm')
});
// Create your WebSocket.
var socket = new WebSocket('ws://localhost:8080/game');
// When a command goes to the `messageSender` port, we pass the message
// along to the WebSocket.
app.ports.messageSender.subscribe(function(message) {
if (socket.readyState == WebSocket.OPEN) {
socket.send(message);
}
else {
app.ports.messageReceiver.send("\{\"tag\":\"WebsocketFailed\"\}");
}
});
// When a message comes into our WebSocket, we pass the message along
// to the `messageReceiver` port.
socket.addEventListener("message", function(event) {
app.ports.messageReceiver.send(event.data);
});
</script>
</body>
</html>