-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjavascript.html
More file actions
36 lines (32 loc) · 1.05 KB
/
Copy pathjavascript.html
File metadata and controls
36 lines (32 loc) · 1.05 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSE Client</title>
</head>
<body>
<h1>SSE Messages</h1>
<div id="messages"></div>
<script>
// Create a new EventSource
const source = new EventSource('https://api.thecatdoor.com/sse/v1/events');
// Listen for events when new data arrives
source.onmessage = function(event) {
// Display the message on the page
const messagesDiv = document.getElementById('messages');
const newMessage = document.createElement('p');
newMessage.textContent = event.data;
messagesDiv.appendChild(newMessage);
};
// Listen for errors
source.onerror = function(event) {
console.error("SSE Error:", event);
};
// Listen for the connection opening
source.onopen = function(event) {
console.log("SSE connection opened.");
};
</script>
</body>
</html>