=sse register with events
This commit is contained in:
parent
b08a18d60b
commit
55dc87af43
2 changed files with 6 additions and 2 deletions
|
@ -56,6 +56,8 @@ func (sse *SseStream) Stream(c *gin.Context) {
|
||||||
Events: c.QueryArray("events"),
|
Events: c.QueryArray("events"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("events: %+v", client.Events)
|
||||||
|
|
||||||
client.Id = generateClientId(client.Ip, client.Events, 8)
|
client.Id = generateClientId(client.Ip, client.Events, 8)
|
||||||
|
|
||||||
sse.AddClient(*client)
|
sse.AddClient(*client)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import { priority } from '$lib/stores/priority.js';
|
import { priority } from '$lib/stores/priority.js';
|
||||||
import Select from '$lib/select.svelte';
|
import Select from '$lib/select.svelte';
|
||||||
import Button from '../../lib/button.svelte';
|
import Button from '$lib/button.svelte';
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
console.log('Dev mode');
|
console.log('Dev mode');
|
||||||
|
@ -12,6 +12,8 @@
|
||||||
console.log('Not dev mode');
|
console.log('Not dev mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const events = 'priority,time';
|
||||||
|
|
||||||
let saved = false;
|
let saved = false;
|
||||||
|
|
||||||
$: if (saved && $priority) {
|
$: if (saved && $priority) {
|
||||||
|
@ -69,7 +71,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function Subscribe() {
|
function Subscribe() {
|
||||||
const sse = new EventSource(`/api/sse`);
|
const sse = new EventSource(`/api/sse?events=${events}`);
|
||||||
console.log('subscribe');
|
console.log('subscribe');
|
||||||
sse.onmessage = (e) => {
|
sse.onmessage = (e) => {
|
||||||
let Msg = JSON.parse(e.data);
|
let Msg = JSON.parse(e.data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue