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:

One-Line Setup

bash
cd /opt/seaclip
./scripts/setup-spacetimedb.sh

This script will:

  1. Install SpacetimeDB CLI
  2. Install Rust (if needed)
  3. Build the SpacetimeDB module
  4. Publish to SpacetimeDB cloud
  5. 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!

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

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

Hub-Spoke

Agent Calls

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:

Verify Integration

  1. Open Pixel Office

    Navigate to http://localhost:5173/pixel-office

  2. Check connection status

    Look for the green "Real-time sync active" indicator

  3. Open SpacetimeDB dashboard

    Check that pixel_agent table has 9 rows

  4. 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)

Next Steps