-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
88 lines (73 loc) · 3.32 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<head>
<title>Controller Demo</title>
<!-- Include jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script>
function safeCapture(data,property){
if (data.hasOwnProperty(property)){
return data[property];
}
return "";
}
$(document).ready(function(){
var socket = io.connect('http://us-ch01.upadvisor.com:9000');
$("#connectionStatus").removeClass("red").addClass("yellow");
//The server immediately responds to connections with an IDENTIFY.
socket.on('IDENTIFY', function (data) {
socket.emit('IAM', { "IAM":"gameclient" });
$("#connectionStatus").removeClass("yellow").addClass("green");
});
socket.on("YOURCODE",function (data){
if ((pairCode=safeCapture(data,"code")) != ""){
var url = encodeURIComponent(document.URL.replace("index.html", "") + "controller.html?id=" + pairCode);
console.log(url);
var img = 'http://chart.apis.google.com/chart?chs=250x250&cht=qr&chl=' + url;
$("#pairCode").text(pairCode);
$("#qrCode").attr("src", img);
}
});
socket.on("PAIRED",function (data){
$("#pairStatus").removeClass("red").addClass("green");
//Signalled to be paired.
console.log("Paired with device!");
});
socket.on("ORIENTATION", function (data){
//console.log("Received orientation");
// Apply the transform to the image
var tiltLR = safeCapture(data, "tiltLR");
var tiltFB = safeCapture(data, "tiltFB");
$("#imgLogo").css("webkit-transform", "rotate(" + tiltLR + "deg) rotate3d(1,0,0, " + ((tiltFB -90)* -1) + "deg)");
});
socket.on("KEYPRESS", function (data){
console.log(data.key);
$("#keypresses").html($("#keypresses").html()+"<br />"+data.key);
});
});
</script>
<style>
.box{
width: 100px;
height: 100px;
}
.red{
background-color: red;
}
.yellow{
background-color: yellow;
}
.green{
background-color: green;
}
</style>
</head>
<body>
Pair Code: <span id="pairCode"></span>
<div class="box red" id="connectionStatus">Connection</div>
<div class="box red" id="pairStatus">Pair Status</div>
QR Code: <img id="qrCode" src="" alt="QR code for this URL" width="150" height="150"/>
<img src="html5_logo.png" id="imgLogo" class="logo">
<span id="keypresses"> </span>
</body>
</html