-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
68 lines (68 loc) · 2.35 KB
/
sample.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
<html>
<head>
<script src='dist/freehackquest-libclient-web-js.js'></script>
<script>
function log(n) {
console.log(n);
var log = document.getElementById('log');
log.innerHTML += '[' + new Date() + '] ' + n + '\r\n';
};
document.addEventListener('DOMContentLoaded', function() {
fhq.bind('notify', function(data) {
log('notify: ' + JSON.stringify(data))
});
fhq.bind('connected', function(data) {
log('connected: ' + JSON.stringify(data))
connecting_form.style.display = 'none';
login_form.style.display = '';
logout_form.style.display = 'none';
});
fhq.bind('disconnected', function(data) {
log('disconnected: ' + JSON.stringify(data))
connecting_form.style.display = '';
login_form.style.display = 'none';
logout_form.style.display = 'none';
});
fhq.bind('userdata', function(data) {
log('userdata: ' + JSON.stringify(data))
login_form.style.display = 'none';
logout_form.style.display = '';
});
});
</script>
</head>
<body>
<div id='connecting_form'>
<h1>Connect to Server</h1>
<input type='text' id='server_url'><br>
<button id='btn_connect'>Connect</button>
</div>
<div id='login_form' style='display: none'>
<h1>Login</h1>
<input type='text' id='login'><br>
<input type='password' id='password'><br>
<button id='btn_login'>Login</button>
</div>
<div id='logout_form' style='display: none'>
<h1>Connected</h1>
<button id='btn_logout'>Logout</button>
</div>
<script>
server_url.value = 'ws://' + window.location.hostname + ':1234/api-ws/'
btn_login.onclick = function() {
fhq.login({email: login.value, password: password.value}).done(function(r) {
log('Login success, token = ' + r.token);
}).fail(function(e) {
log('Login failed, error = ' + e.error);
})
}
btn_logout.onclick = function() {
fhq.deinit();
}
btn_connect.onclick = function() {
fhq.init({'baseUrl': server_url.value});
}
</script>
<pre id='log'></pre>
</body>
</html>