-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsse_client.html
More file actions
37 lines (31 loc) · 1.11 KB
/
sse_client.html
File metadata and controls
37 lines (31 loc) · 1.11 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
<!DOCTYPE html>
<html>
<head>
<title>Arcade SSE Example</title>
</head>
<body>
<h1>Arcade SSE Status Stream</h1>
<div id="log"></div>
<script>
const callbackToken = "example-token-123";
const url = `http://localhost:3011/events?callbackToken=${callbackToken}`;
const eventSource = new EventSource(url);
const log = document.getElementById('log');
eventSource.addEventListener('status', (e) => {
const data = JSON.parse(e.data);
const entry = document.createElement('div');
entry.textContent = `[${data.timestamp}] ${data.txid}: ${data.status}`;
log.appendChild(entry);
console.log('Event ID:', e.lastEventId);
console.log('Status:', data);
});
eventSource.onerror = (e) => {
console.error('SSE Error:', e);
log.appendChild(document.createTextNode('Connection error - will auto-reconnect\n'));
};
eventSource.onopen = () => {
log.appendChild(document.createTextNode('Connected to SSE stream\n'));
};
</script>
</body>
</html>