-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
68 lines (59 loc) · 1.72 KB
/
script.js
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
let resultSpan;
let host;
let tenant;
let clientId;
let displayName;
let payload;
window.onload = () => {
resultSpan = document.getElementById('result');
host = document.getElementById('host');
tenant = document.getElementById('tenant');
clientId = document.getElementById('clientId');
displayName = document.getElementById('displayName');
port = document.getElementById('port');
protocol = document.getElementById('protocol');
payload = document.getElementById('payload');
}
function onSubmit() {
resultSpan.textContent = '';
// check form validity
const valid = validateForm();
if(valid !== true) {
resultSpan.append( valid.error);
return;
}
// Create a new Helicon SDK istance
const heliconWriteClient = new Helicon.HeliconWriteClient(host.value, clientId.value, tenant.value, protocol.value, port.value, { trace: true });
try {
// get the payload value
const record = JSON.parse(payload.value);
// and send it to the stream
heliconWriteClient.write(displayName.value, record).then(
() => {
resultSpan.append('Publish completed!');
resultSpan.style.color = "green";
},
(errorMessage) => {
resultSpan.append(errorMessage);
resultSpan.style.color = "red";
}
);
} catch (error) {
resultSpan.append('Record malformed, please enter a valid JSON');
}
}
function validateForm() {
if (!tenant.value) {
return { error: 'Please, fill a valid tenant value' };
}
if (!clientId.value) {
return { error: 'Please, fill a valid clientId value' };
}
if (!displayName.value) {
return { error: 'Please, fill a valid displayName value' };
}
return true;
}
function changeUrl(url) {
window.history.pushState('', '', url);
}