Skip to content

Commit

Permalink
Step 7 – Receiving inputs from Ably
Browse files Browse the repository at this point in the history
  • Loading branch information
tomczoink committed Mar 20, 2018
1 parent dfb7034 commit 040fbbe
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mqtt-snake/snake.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Snake with Ably</title>
<script src="http://cdn.ably.io/lib/ably.min-1.js"></script>
</head>
<body>
<h1 id="heading">Ably Realtime Snake</h1>
<script type="text/javascript">
var ably = new Ably.Realtime('REPLACE_WITH_YOUR_API_KEY');
var decoder = new TextDecoder();
var channel = ably.channels.get('input');
channel.subscribe(function(message) {
var command = decoder.decode(message.data);
if(command == 'left') {
console.log("Left!")
} else if(command == 'up') {
console.log("Up!")
} else if(command == 'right') {
console.log("Right!")
} else if(command == 'down') {
console.log("Down!")
} else if(command == 'startstop') {
console.log("Pause or Play!")
}
});
</script>
</body>
</html>

0 comments on commit 040fbbe

Please sign in to comment.