.
This commit is contained in:
parent
1f96ed0930
commit
e23ad2cbf2
11 changed files with 49 additions and 18 deletions
BIN
sse/be/be
BIN
sse/be/be
Binary file not shown.
|
@ -1 +1 @@
|
|||
{"version":"1703070251152"}
|
||||
{"version":"1703074552121"}
|
Binary file not shown.
Binary file not shown.
|
@ -5,17 +5,17 @@
|
|||
<link rel="icon" href="/favicon.png" />
|
||||
<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/singletons.y0J0ZVZx.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/app.ck5GlgzY.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.j1PGATaQ.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/app.uCGb8Gwq.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/index.PctGSwCt.js">
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">
|
||||
<script>
|
||||
{
|
||||
__sveltekit_lfjj3r = {
|
||||
__sveltekit_gr3k9f = {
|
||||
base: "",
|
||||
env: null
|
||||
};
|
||||
|
@ -23,8 +23,8 @@
|
|||
const element = document.currentScript.parentElement;
|
||||
|
||||
Promise.all([
|
||||
import("/_app/immutable/entry/start.tfT6_LLF.js"),
|
||||
import("/_app/immutable/entry/app.ck5GlgzY.js")
|
||||
import("/_app/immutable/entry/start.T-L7090x.js"),
|
||||
import("/_app/immutable/entry/app.uCGb8Gwq.js")
|
||||
]).then(([kit, app]) => {
|
||||
kit.start(app, element);
|
||||
});
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -5,17 +5,17 @@
|
|||
<link rel="icon" href="../favicon.png" />
|
||||
<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/singletons.y0J0ZVZx.js">
|
||||
<link rel="modulepreload" href="../_app/immutable/entry/app.ck5GlgzY.js">
|
||||
<link rel="modulepreload" href="../_app/immutable/chunks/singletons.j1PGATaQ.js">
|
||||
<link rel="modulepreload" href="../_app/immutable/entry/app.uCGb8Gwq.js">
|
||||
<link rel="modulepreload" href="../_app/immutable/chunks/index.PctGSwCt.js">
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">
|
||||
<script>
|
||||
{
|
||||
__sveltekit_lfjj3r = {
|
||||
__sveltekit_gr3k9f = {
|
||||
base: new URL("..", location).pathname.slice(0, -1),
|
||||
env: null
|
||||
};
|
||||
|
@ -23,8 +23,8 @@
|
|||
const element = document.currentScript.parentElement;
|
||||
|
||||
Promise.all([
|
||||
import("../_app/immutable/entry/start.tfT6_LLF.js"),
|
||||
import("../_app/immutable/entry/app.ck5GlgzY.js")
|
||||
import("../_app/immutable/entry/start.T-L7090x.js"),
|
||||
import("../_app/immutable/entry/app.uCGb8Gwq.js")
|
||||
]).then(([kit, app]) => {
|
||||
kit.start(app, element);
|
||||
});
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -12,6 +12,35 @@
|
|||
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() {
|
||||
const sse = new EventSource(`/api/sse`);
|
||||
console.log('subscribe');
|
||||
|
@ -64,10 +93,10 @@
|
|||
};
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const unsub = Subscribe();
|
||||
return unsub;
|
||||
});
|
||||
// onMount(() => {
|
||||
// const unsub = Subscribe();
|
||||
// return unsub;
|
||||
// });
|
||||
|
||||
async function newmsg() {
|
||||
await fetch('/api/msg');
|
||||
|
@ -103,4 +132,6 @@
|
|||
|
||||
<hr>
|
||||
|
||||
<button on:click={Subscribe}>SSE Msg</button>
|
||||
<button on:click={SSEMsg}>SSE PingPong</button>
|
||||
<br>
|
||||
<button on:click={Subscribe}>SSE ALL</button>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue