forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
247 lines (213 loc) · 9.03 KB
/
index.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!--
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!--
This is a test page for developers to test WASM integration.
-->
<html>
<head>
<meta charset="utf-8"/>
<script src="dist/web/aries.js"></script>
<script>
var aries
var stopNotifier
async function startAries() {
if (aries) {
console.error("aries is already initialized")
document.querySelector("#output").value = "aries is already initialized"
return
}
const request = document.querySelector("#opts").value
aries = await new Aries.Framework(JSON.parse(request))
document.querySelector("#output").value = "aries started"
}
function destroyAries() {
if (!aries) {
console.error("aries not initialized")
document.querySelector("#output").value = "aries not initialized"
return
}
const response = aries.destroy()
aries = null
document.querySelector("#output").value = JSON.stringify(response)
}
async function handleOperationInput() {
if (!aries) {
console.error("aries not initialized")
document.querySelector("#output").value = "aries not initialized"
return
}
const request = document.querySelector("#input").value
const operation = document.querySelector("#operation").value
const method = document.querySelector("#method").value
const response = await aries[operation][method](request)
document.querySelector("#output").value = JSON.stringify(response)
}
function startTopicNotifier() {
var topics
if (document.querySelector("#notifier").value) {
topics = document.querySelector("#notifier").value.split(",")
} else {
topics = []
}
stopNotifier = aries.startNotifier(pushToMsgPanel, topics)
document.querySelector("#output").value = "notifier started"
}
function pushToMsgPanel(val) {
console.log("incoming msg :", val.id, val.topic, val.payload)
var table = document.getElementById("msg-table");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = val.id;
cell2.innerHTML = val.topic;
cell3.innerHTML = JSON.stringify(val.payload);
}
function stopTopicNotifier() {
if (stopNotifier) {
stopNotifier()
}
}
function changeSource(src) {
//stop existing worker before switching
if (aries) {
destroyAries()
}
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.src= `dist/${src}/aries.js`;
head.appendChild(script);
const mode = (src == "rest") ? "REST" : "WASM"
document.getElementById("mode-label").innerHTML = `Running in ${mode} mode`
if (src == "rest"){
document.getElementById("opts").innerHTML = `{"assetsPath": "/dist/assets", "agent-rest-url": "http://localhost:8082", "agent-rest-wshook":"ws://localhost:8082/ws", "agent-rest-token":"arjswrkr001"}`
} else {
document.getElementById("opts").innerHTML = `{"assetsPath": "/dist/assets", "agent-default-label":"dem-js-agent","http-resolver-url":[],"auto-accept":true,"outbound-transport":["ws","http"],"transport-return-route":"all","log-level":"debug", "db-namespace":"demoagent"}`
}
}
</script>
</head>
<body>
<div>
<fieldset>
<legend id="mode-label" style="font-size: medium;font-weight: bold">Running in WASM Mode...</legend>
<button onClick="changeSource('rest')" style="font-size: large">Switch to REST version</button>
<button onClick="changeSource('web')" style="font-size: large">Switch to WASM version</button>
</fieldset>
</div>
<div>
<table>
<tr>
<td width="50%" valign="top">
<fieldset>
<legend style="font-size: x-large;font-weight: bold">Aries Agent</legend>
<table>
<tr>
<td colspan="2">
<div>Start Options :</div>
<textarea id="opts" rows="5" cols="100">{"assetsPath": "/dist/assets", "agent-default-label":"dem-js-agent","http-resolver-url":[],"auto-accept":true,"outbound-transport":["ws","http"],"transport-return-route":"all","log-level":"debug", "db-namespace":"demoagent"}
</textarea>
</td>
</tr>
<tr>
<td>
<button id="start-button" onClick="startAries()">StartAgent</button>
<button id="stop-button" onClick="destroyAries()">StopAgent</button>
</td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
<tr>
<td>
<div style="font-size: small;">(Enter comma separated topics below, leave it empty to
subscribe to all topics.)
</div>
<input type="text" id="notifier" value="" size="50"></input>
<button onClick="startTopicNotifier()">Start Notifier</button>
<button onClick="stopTopicNotifier()">Stop Notifier</button>
</td>
</tr>
</table>
</fieldset>
</td>
<td rowspan="2" valign="top">
<fieldset style="width: 100%;height: 100%;">
<legend style="font-size: x-large;font-weight: bold">Message Center</legend>
<div style="overflow:scroll; height:600px">
<table width="100%" id="msg-table" cellspacing="5px" style="table-layout: fixed;word-wrap: break-word;text-align:left;">
<tr>
<th>
ID
</th>
<th>
Topic
</th>
<th>
Message
</th>
</tr>
</table>
</div>
</fieldset>
</td>
</tr>
<tr>
<td>
<fieldset>
<legend style="font-size: x-large;font-weight: bold">Aries Agent Command Controller</legend>
<table cellspacing="10px">
<tr>
<td>
<label for="operation">Operation: </label>
</td>
<td>
<input type="text" id="operation" value="didexchange" size="75"></input>
</td>
</tr>
<tr>
<td>
<label for="method">Method: </label>
</td>
<td>
<input type="text" id="method" value="createInvitation" size="50"></input>
</td>
</tr>
<tr>
<td>
<label for="input">Request: </label>
</td>
<td>
<textarea id="input" rows="15" cols="100">{}</textarea>
</td>
</tr>
<tr>
<td>
</td>
<td>
<button onClick="handleOperationInput()">Execute</button>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</div>
<hr/>
<div style="height: 10%">
<label for="output" style="font-size: large;font-weight: bold">Response: </label>
<output id="output" style="color: green;"></output>
</div>
<hr/>
<br>
<div id="error-div" style="visibility: hidden;color:red;font-size: x-large;">
<label for="error">Error: </label>
<output id="error"></output>
</div>
</body>
</html>