-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
38 lines (34 loc) · 1.16 KB
/
Copy pathtest.html
File metadata and controls
38 lines (34 loc) · 1.16 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
<!DOCTYPE html>
<html>
<head>
<title>OpenNotify Test</title>
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>
<style>
body { font-family: sans-serif; padding: 40px; max-width: 500px; }
.notif { background: #f0f0f0; padding: 12px 16px; border-radius: 8px; margin-bottom: 10px; }
.notif strong { display: block; margin-bottom: 4px; }
#status { color: gray; margin-bottom: 24px; font-size: 14px; }
</style>
</head>
<body>
<h2>OpenNotify — live test</h2>
<p id="status">Connecting...</p>
<div id="feed"></div>
<script>
const socket = io('http://localhost:3000')
socket.on('connect', () => {
document.getElementById('status').textContent = 'Connected as user_123. Waiting for notifications...'
socket.emit('join', 'user_123')
})
socket.on('notification', (data) => {
const div = document.createElement('div')
div.className = 'notif'
div.innerHTML = `<strong>${data.title}</strong>${data.body}`
document.getElementById('feed').prepend(div)
})
socket.on('disconnect', () => {
document.getElementById('status').textContent = 'Disconnected'
})
</script>
</body>
</html>