A SvelteKit demo showcasing real-time WebSocket functionality with the Bun adapter, assuming Bun is used as both the package manager for development and runtime in production.
broadcastToClients
method in the singleton class for live communication across all visitors.This application uses svelte-adapter-bun
, designed for long-running server environments. It is not compatible with serverless platforms.
A Dockerfile is included for customization to suit specific hosting requirements.
To run the project in development mode, set up two servers:
WebSocket Server
Start the WebSocket server:
bun bunServer.ts
SvelteKit Development Server
Start the SvelteKit development server:
bun dev
src/lib/pocketbase.ts
with your PocketBase connection URL and the name of a collection (table) you wish to monitor.src/lib/singletonPocketBase.ts
to define the PocketBase collection to monitor in real time.deploy.sh
script for deployment.From the stock SvelteKit setup, the following files have been updated or added:
src/lib/pocketbase.ts
: Establishes the PocketBase connection.src/lib/singletonPocketBase.ts
: Implements a shared PocketBase instance for efficient resource use and real-time database interaction. src/routes/+page.svelte
: Demonstrates sample usage from the frontend. src/hooks.server.ts
: Middleware handling WebSocket events for the long-running server. vite.config.ts
: Configures a proxy server endpoint for development. svelte.config.ts
: Updates the adapter to use svelte-adapter-bun
.bunServer.ts
: A helper websocket server for use during development.Additionally, the following packages were installed: