-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.html
More file actions
32 lines (30 loc) · 1.12 KB
/
chat.html
File metadata and controls
32 lines (30 loc) · 1.12 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
<h1>Live Chat with Server sent events in PHP!</h1>
<div class="row g-2">
<!-- Chat messages -->
<div class="col-8 text-center bg-secondary text-white">
<div class="p-3 border">Messages</div>
</div>
<!-- users list -->
<div class="col-4 text-center">
<div class="p-2 border">
<div class="card-body">
<h5 class="card-title">Users</h5>
</div>
<div class="card w-100">
<ul class="list-group list-group-flush">
<li class="list-group-item">An item</li>
<li class="list-group-item">A second item</li>
<li class="list-group-item">A third item</li>
</ul>
</div>
</div>
</div>
<script>
// withCredentials=true: pass the cross-domain cookies to server-side
const source = new EventSource('http://localhost:8080/sse.php', {withCredentials: true});
source.addEventListener('news', function (event) {
console.log(event.data);
// source.close(); // disconnect stream
}, false);
</script>
</div>