-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.socket.html
More file actions
60 lines (45 loc) · 1.43 KB
/
test.socket.html
File metadata and controls
60 lines (45 loc) · 1.43 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
<!doctype html>
<html>
<head>
<title>MedAlert Socket Test</title>
</head>
<body>
<h2>Socket Test</h2>
<input id="token" placeholder="Paste JWT token here" />
<button onclick="connect()">Connect</button>
<br /><br />
<input id="dispatchId" placeholder="Dispatch ID" />
<button onclick="acceptEmergency()">Accept Emergency</button>
<pre id="log"></pre>
<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
<script>
let socket;
function log(message) {
const logBox = document.getElementById('log');
logBox.innerHTML += message + '\n';
}
function connect() {
const token = document.getElementById('token').value;
socket = io('http://localhost:4000', {
auth: { token },
});
socket.on('connect', () => {
console.log('Connected:', socket.id);
log('✅ Connected: ' + socket.id);
});
socket.onAny((event, data) => {
log('📩 Event: ' + event);
log(JSON.stringify(data, null, 2));
});
socket.on('connect_error', (err) => {
log('❌ Error: ' + err.message);
});
}
function acceptEmergency() {
const dispatchId = Number(document.getElementById('dispatchId').value);
socket.emit('accept_emergency', { dispatchId });
log('🚑 Sent accept_emergency');
}
</script>
</body>
</html>