-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_socket_chatserver.html
More file actions
81 lines (73 loc) · 2.17 KB
/
test_socket_chatserver.html
File metadata and controls
81 lines (73 loc) · 2.17 KB
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
<!doctype html>
<html>
<head>
</head>
<body>
<h2>Test send and receive with socket server</h2>
<h3>Type a message and click "Submit".</h3>
<form>
<input autofocus id="input" />
<input type="submit" value="Submit" />
</form>
<p id="received"></p>
<p id="outcome"></p>
<script src="./node_modules/object-hash/dist/object_hash.js"></script>
<script src="./node_modules/socket.io/client-dist/socket.io.js"></script>
<script>
const transports = ['websocket', 'polling'];
const token = objectHash(performance.now());
const path = "/bazsocket/";
// Customize the following as appropriate.
// >>> Update ROOMNAME to a unique value for a fresh agent <<<
const ENDPOINT = 'https://bazaar.lti.cs.cmu.edu';
const AGENTNAME = 'fcdsp3';
// const AGENTNAME = '15619p2';
const CLIENTID = 'ChatServer';
// const ROOMNAME = '31201';
const ROOMNAME = 'ope-learn-domain-ana-ucm5hl6q-room9069';
const USERID = 100;
const USERNAME = 'OPEBot';
const auth = {
token,
agent: {
name: AGENTNAME,
configuration: {
clientID: CLIENTID
}
},
chat: {
id: ROOMNAME
},
user: {
id: USERID,
name: USERNAME
}
};
console.log('token', token);
console.log('endpoint', ENDPOINT);
const socket = io(ENDPOINT, {
transports,
path,
auth
});;
const form = document.querySelector('form');
const input = document.getElementById('input');
const outcome = document.getElementById('outcome');
const submit = document.querySelector('input[type=submit]');
const received = document.getElementById('received');
const onSubmit = () => {
const value = input.value;
socket.emit('sendchat', value);
};
form.onsubmit = event => {
onSubmit();
return false;
};
socket.on('updatechat', function (username, message)
{
// appendMessage(new Date(), username, message);
received.innerHTML = message;
});
</script>
</body>
</html>