-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiiu.html
116 lines (108 loc) · 4.08 KB
/
wiiu.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=1280, height=600 user-scalable=no" />
<title>Wii U server</title>
<style>
canvas {
position: absolute;
top: 0px;
left: 0px;
z-index: -1;
}
</style>
<script type="text/javascript">
var MySocket = new WebSocket("ws://192.168.0.117:8080");
var interval;
var previousTouched = 0;
MySocket.onopen = function()
{
document.getElementById("out").innerHTML = "Connected";
if(window.wiiu)
{
interval = setInterval('update()', 1000 / 60);
}
};
MySocket.onmessage = function(evt)
{
// document.getElementById("out").innerHTML = evt.data;
};
MySocket.onclose = function()
{
document.getElementById("out").innerHTML = "Disconnected";
clearInterval(interval);
};
function update()
{
if(MySocket.bufferedAmount > 0) {
return; // There is data in the queue
}
var gamepadState = window.wiiu.gamepad.update();
if(gamepadState.isEnabled && gamepadState.isDataValid)
{
// console.log(gamepadState.tpTouch, previousTouched, gamepadState.tpTouch == previousTouched)
// MySocket.send('{"wiiUGamePad":' + JSON.stringify(gamepadState) + '}');
if (!!gamepadState.tpTouch || gamepadState.tpTouch != previousTouched)
{
MySocket.send('{"wiiUGamePad":' + JSON.stringify({
x: gamepadState.tpX,
y: gamepadState.tpY,
touched: gamepadState.tpTouch,
prevTouched: previousTouched,
valid: gamepadState.tpValidity,
drag: document.getElementById("drag").checked ? 1 : 0,
smooth: document.getElementById("drag").checked ? 1 : 0
}) + '}');
}
previousTouched = gamepadState.tpTouch;
}
}
</script>
</head>
<body>
<p><div id="out"></div></p>
<label for="drag">
<input type="checkbox" name="drag" id="drag">
Drag mouse
</label><br>
<label for="smooth">
<input type="checkbox" name="smooth" id="smooth" checked>
Smooth mouse
</label>
<br>
<canvas id="c" width="854" height="480"></canvas>
<script>
var el = document.body;
var ctx = document.getElementById('c').getContext('2d');
var isDrawing;
/* https://jsfiddle.net/tilwinjoy/5H5N2/ */
ctx.lineWidth = 4;
function onmousedown(e) {
console.log("down");
isDrawing = true;
ctx.beginPath();
ctx.moveTo(e.clientX, e.clientY);
};
function onmousemove(e) {
console.log("move");
if (isDrawing) {
ctx.lineTo(e.clientX, e.clientY);
ctx.stroke();
}
};
function onmouseup() {
console.log("up");
isDrawing = false;
ctx.closePath();
};
document.addEventListener("mousedown", onmousedown)
document.addEventListener("mousemove", onmousemove)
document.addEventListener("mouseup", onmouseup)
ctx.fillStyle = "rgba(255, 255, 255, 0.1)";
setInterval(function a() {
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}, 500);
</script>
</body>
</html>