SpacetimeDB Setup
Enable real-time synchronization for Pixel Office and live telemetry
What is SpacetimeDB?
SpacetimeDB is a real-time database that enables instant synchronization between clients. SeaClip uses it for live visualization features like Pixel Office and real-time telemetry streaming.
Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Pixel Office ββββββΆβ SpacetimeDB βββββββ SeaClip Hub β
β (React UI) β β (Real-time) β β (Express API) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
β useTable() hooks β Reducers β Telemetry
β Auto-sync β WebSocket β Agent updates
βΌ βΌ βΌ
Live visualization Persistent state Edge devices
SeaClip uses a hybrid database architecture:
- PostgreSQL β Core business data (companies, agents, tickets, costs, audit)
- SpacetimeDB β Real-time visualization and telemetry streaming
One-Line Setup
bash
cd /opt/seaclip
./scripts/setup-spacetimedb.sh
This script will:
- Install SpacetimeDB CLI
- Install Rust (if needed)
- Build the SpacetimeDB module
- Publish to SpacetimeDB cloud
- Generate TypeScript bindings
Manual Setup
Step 1: Install SpacetimeDB CLI
bash
curl -sSf https://install.spacetimedb.com | sh
Step 2: Install Rust
bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
rustup target add wasm32-unknown-unknown
Step 3: Build the Module
bash
cd /opt/seaclip/spacetimedb
spacetime build
$ spacetime build
Compiling seaclip-realtime v0.1.0
Finished release [optimized] target(s) in 12.34s
Build successful!
Compiling seaclip-realtime v0.1.0
Finished release [optimized] target(s) in 12.34s
Build successful!
Step 4: Login to SpacetimeDB
bash
spacetime login
This opens a browser for authentication. After login, you'll receive a token.
Step 5: Publish the Module
bash
spacetime publish seaclip-realtime
$ spacetime publish seaclip-realtime
Publishing module 'seaclip-realtime'...
β Module published successfully!
Dashboard: https://spacetimedb.com/seaclip-realtime
WebSocket: wss://maincloud.spacetimedb.com
Publishing module 'seaclip-realtime'...
β Module published successfully!
Dashboard: https://spacetimedb.com/seaclip-realtime
WebSocket: wss://maincloud.spacetimedb.com
Step 6: Generate TypeScript Bindings
bash
spacetime generate seaclip-realtime --lang typescript --out-dir ../ui/src/lib/spacetimedb/generated
SpacetimeDB Tables
Pixel Office Tables
| Table | Description |
|---|---|
pixel_agent |
Agent visualization state (position, activity, appearance) |
agent_path |
Movement paths for animation |
Hub-Spoke Tables
| Table | Description |
|---|---|
edge_device |
Registered edge devices/spokes |
device_telemetry |
Real-time telemetry metrics |
Agent Call Tables
| Table | Description |
|---|---|
agent_call |
Active/ended calls |
call_participant |
Participants in calls |
call_message |
Messages in calls |
Reducers (Server Functions)
SpacetimeDB reducers are server-side functions that modify the database:
Pixel Office
upsert_pixel_agentβ Register/update agentmove_agentβ Update agent positionupdate_agent_activityβ Update agent state/activityremove_pixel_agentβ Remove agent
Hub-Spoke
upsert_edge_deviceβ Register/update devicerecord_telemetryβ Record telemetry dataset_device_offlineβ Mark device offline
Agent Calls
start_callβ Start a new calljoin_callβ Join an existing callsend_call_messageβ Send a messageend_callβ End a call
Using in React
Import the hook in your React components:
typescript
import { usePixelOfficeDB } from '@/lib/spacetimedb';
function PixelOffice() {
const {
connected,
agents,
upsertAgent,
moveAgent,
updateActivity,
} = usePixelOfficeDB();
// Agents sync in real-time automatically
return (
<div>
{connected ? 'π’ Connected' : 'π‘ Connecting...'}
{agents.map(agent => (
<AgentSprite key={agent.id} agent={agent} />
))}
</div>
);
}
SpacetimeDB Dashboard
View your data at:
url
https://spacetimedb.com/seaclip-realtime
The dashboard shows:
- All tables and their data
- Real-time updates as they happen
- Query interface for debugging
- Connection statistics
Verify Integration
-
Open Pixel Office
Navigate to
http://localhost:5173/pixel-office -
Check connection status
Look for the green "Real-time sync active" indicator
-
Open SpacetimeDB dashboard
Check that
pixel_agenttable has 9 rows -
Check browser console
Look for
[SpacetimeDB] Connected with identity:message
Troubleshooting
| Issue | Solution |
|---|---|
| Build fails with "wasm32 not found" | Run rustup target add wasm32-unknown-unknown |
| "Not logged in" error | Run spacetime login |
| Connection shows "Connecting..." | Check browser console for errors, verify module is published |
| Data not syncing | Ensure reducers are being called (check console logs) |