-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
118 lines (106 loc) · 3.87 KB
/
test.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
117
118
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
textarea { vertical-align: bottom; }
#output { overflow: auto; }
#output > p { overflow-wrap: break-word; }
#output span { color: blue; }
#output span.error { color: red; }
</style>
<title>Desktop Agent Tests</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>DesktopAgent2 Test</h1>
<p class="lead">
This sample page connects to a DesktopAgent2 and allows the execution of some tests
</p>
</div>
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary" onclick="doConnect()"> Connect </button>
<button type="button" class="btn btn-primary" onclick="doGetComputerName()"> Get Computer Name </button>
<button type="button" class="btn btn-primary" onclick="doStartWord()"> Start Word </button>
<button type="button" class="btn btn-primary" onclick="doStartExcel()"> Start Excel </button>
<button type="button" class="btn btn-primary" onclick="doStartExcel()"> Run Program </button>
</div>
<p>STATUS: <div class="badge badge-info" id=output>NOT CONNECTED</div></p>
<script>
function DesktopAgent2Client()
{
this.wsUri = "wss://localhost:996/";
this.websocket = undefined;
this.OnConnected = function(e) {};
this.OnClosed = function(e) {};
this.Close = function(code, reason) {
websocket.close(code, reason);
};
this.Send = function(data)
{
var that = this;
return new Promise(function(resolve, reject)
{
that.websocket.onmessage = function(e) {
resolve(e);
};
that.websocket.send(data);
that.websocket.onerror = function(err) {
reject(err);
};
});
};
this.Start = function(uri)
{
var that = this;
this.wsUri = uri || this.wsUri;
this.websocket = new WebSocket(this.wsUri);
this.websocket.onclose = function(e) {
if (that.OnClosed) that.OnClosed(e);
}
this.websocket.onmessage = function(e) {
this.ProcessMessage(e);
}
return new Promise(function(resolve, reject)
{
that.websocket.onopen = function(e) {
resolve(this);
};
that.websocket.onerror = function(err) {
reject(err);
}
});
}
}
var agent = new DesktopAgent2Client();
function doConnect() {
agent.OnClosed = function() {
document.getElementById('output').innerText = "NOT CONNECTED";
}
agent.Start().then(function() {
document.getElementById('output').innerText = "CONNECTED";
})
}
function doGetComputerName() {
var msg = {'action':'WSH','command':'ComputerName'};
agent.Send(JSON.stringify(msg)).then(function(e) {
var data = JSON.parse(e.data);
alert("Computer Name is " + data.result);
});
}
function doStartExcel() {
var msg = {'action':'Excel','command':'open'};
agent.Send(JSON.stringify(msg)).then(function() {
alert('excel was opened');
});
}
function doStartWord() {
var msg = {'action':'Word','command':'open'};
agent.Send(JSON.stringify(msg)).then(function() {
alert('word was opened');
});
}
</script>
</div>
</body>
</html>