mirror of
https://github.com/tanrax/SSE-Fake.git
synced 2024-11-10 01:55:41 +01:00
24 lines
559 B
JavaScript
24 lines
559 B
JavaScript
const notyf = new Notyf({
|
|
position: {
|
|
x: 'right',
|
|
y: 'top',
|
|
}
|
|
});
|
|
const sse = new EventSource("/events/");
|
|
|
|
sse.onmessage = function(event) {
|
|
const data = JSON.parse(event.data);
|
|
console.log(data);
|
|
|
|
switch (data.action) {
|
|
case 'User connected':
|
|
notyf.success(`Connected: ${data.name}`);
|
|
break;
|
|
case 'User disconnected':
|
|
notyf.error(`Disconnected: ${data.name}`);
|
|
break;
|
|
case 'New message':
|
|
notyf.success(`${data.name}: ${data.text.slice(0, 20)}...`);
|
|
break;
|
|
}
|
|
} |