-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.html
72 lines (67 loc) · 2.93 KB
/
repl.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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="dist/wdws-client.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/3.2.0/yeti/bootstrap.min.css" type="text/css" />
</head>
<body class="container" style="padding-top: 50px;">
<section class="row">
<aside class="col-md-4">
<form id="connect_form" role="form" class="well">
<div class="form-group">
<label for="url">WDWS Server URL</label>
<input type="url" class="form-control" id="wdws_url" placeholder="http://localhost:8080/">
</div>
<button class="btn btn-sm btn-primary btn-block">Connect</button>
</form>
</aside>
<section class="col-md-8">
<form id="command_form" role="form">
<div class="form-group">
<label for="command">Command</label>
<input type="text" class="form-control" id="command" name="command" placeholder="http://localhost:8080/">
</div>
<div class="form-group">
<label for="url">Params</label>
<textarea name="params" id="params" class="form-control" placeholder='{"path":"/index.html", "data":"Hello, World!}'></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success btn-block">Submit Command</button>
</div>
</form>
<hr>
<h3>Responses</h3>
<pre class="well" id="responses">
</pre>
</section>
</section>
<script type="text/javascript" charset="utf-8">
var _pre = document.querySelector('#responses')
var logResponse = function() {
var args = Array.prototype.slice.call(arguments, 0);
_pre.innerText = args.map(JSON.stringify).join(', ') + "\n\n" + _pre.innerText;
}
var logError = function(err) {
_pre.innerHTML = "<span style='color: #c00;'>" + JSON.stringify(err) + "</span>\n" + _pre.innerHTML;
}
document.querySelector("#connect_form").addEventListener('submit', function(e) {
e.preventDefault();
var url = document.querySelector('#wdws_url').value;
wdws = new window.WDWSClient(url);
wdws.connect();
['connect', 'connect_error', 'connect_timeout', 'reconnect_attempt', 'reconnecting', 'reconnect_error', 'reconnect_failed'].forEach(function(evt) {
wdws.on(evt, function() {
logResponse.apply(null, ["[EVENT]", evt].concat(Array.prototype.slice.call(arguments, 0)));;
});
});
console.log(window.wdws);
});
document.querySelector('#command_form').addEventListener('submit', function(e) {
e.preventDefault();
var command = document.querySelector('#command').value;
var params = JSON.parse(document.querySelector('#params').value);
wdws.run(command, params).then(logResponse, logError);
});
</script>
</body>
</html>