Admin dashboard page
7 | 8 | {#if localStorage.getItem('showStats')} 9 | Cpu usage - {$stats.cpu_usage}10 | Memory - {$stats.memory}
11 | Time - {$stats.time}
12 | {/if} 13 |
You are {data.id}, connection status {$status}
21 | 22 | {#if $status.includes('connecting')} 23 |Connecting...
24 | {:else if $waitingUser?.approved === false} 25 |You have been denied access to the room.
26 | {:else if $status === 'connected'} 27 |Waiting to be let into the room...
28 | {:else} 29 |Disconnected.
30 | {/if} 31 | 32 | {#if $status === 'closed'} 33 | 48 | {:else} 49 | 50 | {/if} 51 | -------------------------------------------------------------------------------- /src/routes/room/waiting-lobby/+server.js: -------------------------------------------------------------------------------- 1 | import { produce } from '$lib' 2 | import { 3 | findMatchingId, 4 | lobby, 5 | removeFromStore, 6 | updateStore, 7 | } from '../mock-db.server' 8 | import { eventStopper } from '../sse-utils.server' 9 | 10 | export async function POST({ route, request }) { 11 | /** @type {string} */ 12 | let id 13 | 14 | if (request.body) { 15 | id = (await request.json()).id 16 | } 17 | 18 | return produce(function start({ emit, lock }) { 19 | const stopper = eventStopper(route.id, emit, lock) 20 | 21 | updateStore(lobby, { id, approved: undefined }) 22 | stopper.push(function leaveLobby() { 23 | removeFromStore(lobby, id) 24 | }) 25 | 26 | const unsub = lobby.subscribe(function notify(guests) { 27 | const guest = findMatchingId(guests, id) 28 | 29 | if (!guest) { 30 | // already disconnected 31 | return lock.set(false) 32 | } 33 | 34 | const { error } = emit('waitingUser', JSON.stringify(guest)) 35 | if (error) { 36 | console.error(error) 37 | lock.set(false) 38 | } else if (guest.approved === true || guest.approved === false) { 39 | stopper.stop() 40 | } 41 | }) 42 | stopper.push(unsub) 43 | 44 | const { error } = emit('waitingUser', JSON.stringify({ id })) 45 | if (error) { 46 | console.error(error) 47 | lock.set(false) 48 | } 49 | 50 | return stopper.onStop 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razshare/sveltekit-sse/3218dce237e71b5130f5deac1dd59aa512573b6b/static/favicon.png -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-auto' 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { 5 | kit: { 6 | // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. 7 | // If your environment is not supported, or you settled on a specific environment, switch out the adapter. 8 | // See https://svelte.dev/docs/kit/adapters for more information about adapters. 9 | adapter: adapter(), 10 | }, 11 | } 12 | 13 | export default config 14 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { sveltekit } from '@sveltejs/kit/vite' 2 | import { defineConfig } from 'vite' 3 | export default defineConfig({ 4 | plugins: [sveltekit()], 5 | }) 6 | --------------------------------------------------------------------------------