-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
158 lines (158 loc) · 6.56 KB
/
index.html
File metadata and controls
158 lines (158 loc) · 6.56 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dolphin WebSocket GameCube Controller Server</title>
<link href="node_modules/bootswatch/dist/pulse/bootstrap.min.css" rel="stylesheet">
<style>
html {
user-select: none;
cursor: default;
padding:50px;
}
iframe {
width:100%;
display:inline;
padding:0;
margin:0;
}
#controllers {
margin-top:10px;
padding: 0;
width:100%;
display:block;
text-align:center;
}
#controllers > div {
width: 300px;
height:169px;
display:inline-block;
}
</style>
</head>
<body>
<div class="container-fluid">
<span id="notstarted">
<form>
<h2>
Install Files
</h2>
<div class="form-group">
<button class="btn btn-lg btn-primary btn-block" id="install" type="submit">
Install
</button>
</div>
<h2>
Start Controller server
</h2>
<div class="form-group">
<label for="port">Port</label>
<input
class="form-control"
id="port"
placeholder="Server port"
required=""
type="number"
value="1889"
>
<div class="alert alert-danger" id="error">
Failed to start server!
</div>
</div>
<button class="btn btn-lg btn-primary btn-block" id="start" type="submit">
Start server
</button>
</form>
</span>
<span id="started">
<h2>Server started on <a href="" id="hoststring"></a></h2>
<input type="button" class="form-control btn-primary" id="stop" value="Stop Server"/>
<div id="controllers">
<div id="controller1">
<a></a>
<iframe frameBorder="0"></iframe>
</div>
<div id="controller2">
<a></a>
<iframe frameBorder="0"></iframe>
</div>
<div id="controller3">
<a></a>
<iframe frameBorder="0"></iframe>
</div>
<div id="controller4">
<a></a>
<iframe frameBorder="0"></iframe>
</div>
</div>
</span>
</div>
<script>
(function() {
var open = require("open");
function openLinkInBrowser(e) {
e.preventDefault();
open(e.target.href)
}
document.getElementById("started").style.display = "none";
document.getElementById("hoststring").onclick = openLinkInBrowser;
document.getElementById("error").style.display = "none";
var _startServer = require('./server.js');
var start_button = document.getElementById("start");
var stop_button = document.getElementById("stop");
var server;
start_button.addEventListener("click", function(e) {
e.preventDefault();
var port = document.getElementById("port").value;
var buttons = Array.from(document.querySelectorAll("#buttons div"));
if(!isNaN(parseInt(port))) {
server = _startServer(port, function(host, port) {
var host_url = "http://" + host + ":" + port;
document.getElementById("notstarted").style.display = "none";
document.getElementById("error").style.display = "none";
document.getElementById("started").style.display = "block";
var hoststring = document.getElementById("hoststring");
hoststring.innerHTML = hoststring.href = host_url;
for(var i=1;i<5;i++) {
var el = document.getElementById("controller" + i).querySelectorAll("a")[0];
var iframe = document.getElementById("controller" + i).querySelectorAll("iframe")[0];
el.href = el.innerHTML = iframe.src = host_url + "/#" + i;
el.onclick = openLinkInBrowser;
}
}, function(e) {
console.log(e)
document.getElementById("error").style.display = "block";
document.getElementById("started").style.display = "none";
document.getElementById("notstarted").style.display = "block";
}, function(ctrl) {
var iframe = document.getElementById(
"controller" + ctrl.controller
).querySelectorAll("iframe")[0];
var el = iframe.contentDocument.getElementById(ctrl.input_name);
if(ctrl.action == 'press') {
el.className = "server-triggered";
} else if(ctrl.action == 'release') {
el.className = "";
} else if(ctrl.action == "set") {
if(ctrl.value !== "0.5 0.5") {
el.className = "server-triggered";
} else {
el.className = "";
}
}
});
console.log(server)
}
});
stop_button.addEventListener("click", function(e) {
e.preventDefault();
if(server) {
server.stop();
document.getElementById("started").style.display = "none";
document.getElementById("notstarted").style.display = "block";
}
});
})();
</script>
</body>
</html>