This commit is contained in:
Miki 2023-12-20 13:17:43 +01:00
parent 1f96ed0930
commit e23ad2cbf2
11 changed files with 49 additions and 18 deletions

BIN
sse/be/be

Binary file not shown.

View file

@ -1 +1 @@
{"version":"1703070251152"} {"version":"1703074552121"}

Binary file not shown.

Binary file not shown.

View file

@ -5,17 +5,17 @@
<link rel="icon" href="/favicon.png" /> <link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="modulepreload" href="/_app/immutable/entry/start.tfT6_LLF.js"> <link rel="modulepreload" href="/_app/immutable/entry/start.T-L7090x.js">
<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.k-kUyWhY.js"> <link rel="modulepreload" href="/_app/immutable/chunks/scheduler.k-kUyWhY.js">
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.y0J0ZVZx.js"> <link rel="modulepreload" href="/_app/immutable/chunks/singletons.j1PGATaQ.js">
<link rel="modulepreload" href="/_app/immutable/entry/app.ck5GlgzY.js"> <link rel="modulepreload" href="/_app/immutable/entry/app.uCGb8Gwq.js">
<link rel="modulepreload" href="/_app/immutable/chunks/index.PctGSwCt.js"> <link rel="modulepreload" href="/_app/immutable/chunks/index.PctGSwCt.js">
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">
<div style="display: contents"> <div style="display: contents">
<script> <script>
{ {
__sveltekit_lfjj3r = { __sveltekit_gr3k9f = {
base: "", base: "",
env: null env: null
}; };
@ -23,8 +23,8 @@
const element = document.currentScript.parentElement; const element = document.currentScript.parentElement;
Promise.all([ Promise.all([
import("/_app/immutable/entry/start.tfT6_LLF.js"), import("/_app/immutable/entry/start.T-L7090x.js"),
import("/_app/immutable/entry/app.ck5GlgzY.js") import("/_app/immutable/entry/app.uCGb8Gwq.js")
]).then(([kit, app]) => { ]).then(([kit, app]) => {
kit.start(app, element); kit.start(app, element);
}); });

Binary file not shown.

Binary file not shown.

View file

@ -5,17 +5,17 @@
<link rel="icon" href="../favicon.png" /> <link rel="icon" href="../favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="modulepreload" href="../_app/immutable/entry/start.tfT6_LLF.js"> <link rel="modulepreload" href="../_app/immutable/entry/start.T-L7090x.js">
<link rel="modulepreload" href="../_app/immutable/chunks/scheduler.k-kUyWhY.js"> <link rel="modulepreload" href="../_app/immutable/chunks/scheduler.k-kUyWhY.js">
<link rel="modulepreload" href="../_app/immutable/chunks/singletons.y0J0ZVZx.js"> <link rel="modulepreload" href="../_app/immutable/chunks/singletons.j1PGATaQ.js">
<link rel="modulepreload" href="../_app/immutable/entry/app.ck5GlgzY.js"> <link rel="modulepreload" href="../_app/immutable/entry/app.uCGb8Gwq.js">
<link rel="modulepreload" href="../_app/immutable/chunks/index.PctGSwCt.js"> <link rel="modulepreload" href="../_app/immutable/chunks/index.PctGSwCt.js">
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">
<div style="display: contents"> <div style="display: contents">
<script> <script>
{ {
__sveltekit_lfjj3r = { __sveltekit_gr3k9f = {
base: new URL("..", location).pathname.slice(0, -1), base: new URL("..", location).pathname.slice(0, -1),
env: null env: null
}; };
@ -23,8 +23,8 @@
const element = document.currentScript.parentElement; const element = document.currentScript.parentElement;
Promise.all([ Promise.all([
import("../_app/immutable/entry/start.tfT6_LLF.js"), import("../_app/immutable/entry/start.T-L7090x.js"),
import("../_app/immutable/entry/app.ck5GlgzY.js") import("../_app/immutable/entry/app.uCGb8Gwq.js")
]).then(([kit, app]) => { ]).then(([kit, app]) => {
kit.start(app, element); kit.start(app, element);
}); });

Binary file not shown.

Binary file not shown.

View file

@ -12,6 +12,35 @@
return now.toISOString(); return now.toISOString();
} }
function SSEMsg() {
const sse = new EventSource(`/api/sse?event=ping&event=pong`);
console.log('subscribe ping pong');
sse.onopen = () => {
console.log(`sse open ${now()}`);
msg = `sse open ${now()}`;
};
sse.addEventListener('ping', (e) => {
let Msg = JSON.parse(e.data);
msg = `ping: ${Msg.id} ${Msg.data} ${now()}`;
console.log(msg);
dping = Msg.id;
});
sse.addEventListener('pong', (e) => {
let Msg = JSON.parse(e.data);
msg = `pong: ${Msg.id} ${Msg.data} ${now()}`;
console.log(msg);
dpong = Msg.id;
});
return () => {
sse.close();
console.log(`sse closing ${Date.now()}`);
};
}
function Subscribe() { function Subscribe() {
const sse = new EventSource(`/api/sse`); const sse = new EventSource(`/api/sse`);
console.log('subscribe'); console.log('subscribe');
@ -64,10 +93,10 @@
}; };
} }
onMount(() => { // onMount(() => {
const unsub = Subscribe(); // const unsub = Subscribe();
return unsub; // return unsub;
}); // });
async function newmsg() { async function newmsg() {
await fetch('/api/msg'); await fetch('/api/msg');
@ -103,4 +132,6 @@
<hr> <hr>
<button on:click={Subscribe}>SSE Msg</button> <button on:click={SSEMsg}>SSE PingPong</button>
<br>
<button on:click={Subscribe}>SSE ALL</button>