basic client

This commit is contained in:
mattx 2020-06-21 11:48:47 +02:00
parent 1574b2a6a8
commit df3fd8b109
2 changed files with 25 additions and 0 deletions

12
static/app.coffee Normal file
View File

@ -0,0 +1,12 @@
window.addEventListener "DOMContentLoaded", (event) ->
window.socket = new WebSocket(location.origin.replace(/^http/, "ws") + "/api")
counter = document.getElementById "counter"
socket.addEventListener "message", (event) ->
if event.data == "err"
alert "error occured"
else
counter.innerText = event.data
increment = -> socket.send("inc")
decrement = -> socket.send("dec")

13
static/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>IncDec</title>
<script src="app.js"></script>
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body>
<button onclick="increment()">+</button>
<button onclick="decrement()">-</button>
<p id="counter">loading</p>
</body>
</html>