-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
97 lines (81 loc) · 2.32 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
<!doctype html>
<html>
<head>
</head>
<body>
<h2>Use this to demonstrate send and receive to socket server</h2>
<h3>Type in the input and click "Analyze".</h3>
<form style="display:inline">
<input autofocus id="input" />
<input type="submit" value="Analyze" />
</form>
<button id="end">End</button>
<p id="interjection"></p>
<p id="outcome"></p>
<script src="/socket.io/socket.io.js"></script>
<script>
const port = /***PORT***/; // this is replaced by the server
const endpoint = location.origin.replace(/:\d.*/, `:${port}`);
const transports = ['websocket', 'polling'];
const agent = {
id: 1,
name: 'Satire Analysis Agent',
configuration: {
}
};
const chat = {
id: 2
};
const user = {
id: 3,
name: 'Web Page User'
};
const auth = {
agent,
chat,
user,
};
const options = {
transports,
auth
};
console.log('endpoint', endpoint);
console.log('options', options);
const socket = io(endpoint, options);
const end = document.getElementById('end');
const form = document.querySelector('form');
const input = document.getElementById('input');
const outcome = document.getElementById('outcome');
const submit = document.querySelector('input[type=submit]');
const interjection = document.getElementById('interjection');
const key = 'userInput';
const annotations = [];
const onSubmit = () => {
const value = input.value;
socket.emit('request', {
value
});
};
end.onclick = () => {
socket.emit('end', auth);
};
form.onsubmit = event => {
onSubmit();
return false;
};
let timeout;
socket.on('interjection', ({ message }) => {
interjection.innerHTML = message;
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
timeout = setTimeout(() => interjection.innerHTML = '', 5000);
});
socket.on('response', ({ value, result, ...misc }) => {
outcome.innerHTML = `"${value}" ${result ? 'is' : 'is not'} satire.`;
console.log(misc);
});
</script>
</body>
</html>