blanchon commited on
Commit
b91acfc
·
1 Parent(s): 8344179
demo/README.md CHANGED
@@ -59,6 +59,48 @@ demo/
59
  2. **LeRobot Arena Server** running on port 8000
60
  3. **Built JavaScript Client** (automatically installed as dependency)
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  ## 🚀 Quick Start
63
 
64
  ### 1. Install Dependencies
 
59
  2. **LeRobot Arena Server** running on port 8000
60
  3. **Built JavaScript Client** (automatically installed as dependency)
61
 
62
+ ## ⚙️ Server Configuration
63
+
64
+ The demo automatically detects the correct server URL based on the environment:
65
+
66
+ - **Development mode**: `http://localhost:8000` (when running on localhost)
67
+ - **Production mode**: `https://blanchon-robottransportserver.hf.space/api` (when deployed)
68
+
69
+ ### Environment Variable Override
70
+
71
+ You can override the default server URL by setting the `PUBLIC_SERVER_URL` environment variable:
72
+
73
+ ```bash
74
+ # For development with custom server
75
+ export PUBLIC_SERVER_URL=http://localhost:8000
76
+
77
+ # For production with HuggingFace Space
78
+ export PUBLIC_SERVER_URL=https://blanchon-robottransportserver.hf.space/api
79
+
80
+ # For custom server deployment
81
+ export PUBLIC_SERVER_URL=https://your-custom-server.com/api
82
+ ```
83
+
84
+ ### Setting Environment Variables
85
+
86
+ #### Option 1: Create a `.env` file
87
+ ```bash
88
+ # In demo/.env
89
+ PUBLIC_SERVER_URL=http://localhost:8000
90
+ ```
91
+
92
+ #### Option 2: Runtime environment variable
93
+ ```bash
94
+ # Set via window object (for runtime configuration)
95
+ window.__SERVER_URL__ = 'http://localhost:8000';
96
+ ```
97
+
98
+ #### Option 3: Build-time environment variable
99
+ ```bash
100
+ # When building
101
+ PUBLIC_SERVER_URL=https://your-server.com/api bun run build
102
+ ```
103
+
104
  ## 🚀 Quick Start
105
 
106
  ### 1. Install Dependencies
demo/src/lib/index.ts CHANGED
@@ -1 +1,35 @@
1
  // place files you want to import through the `$lib` alias in this folder.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  // place files you want to import through the `$lib` alias in this folder.
2
+
3
+ /**
4
+ * Get the server URL based on environment variables and dev/prod mode
5
+ * Priority: ENV variable > dev mode (localhost:8000) > prod mode (HF Space)
6
+ */
7
+ export function getServerUrl(): string {
8
+ // Check for environment variable first
9
+ if (typeof window !== 'undefined') {
10
+ // Client-side: check for runtime environment variable
11
+ const envUrl = (window as any).__SERVER_URL__;
12
+ if (envUrl) {
13
+ return envUrl;
14
+ }
15
+ } else {
16
+ // Server-side: check for build-time environment variable
17
+ const envUrl = process.env.PUBLIC_SERVER_URL;
18
+ if (envUrl) {
19
+ return envUrl;
20
+ }
21
+ }
22
+
23
+ // Fall back to dev/prod detection
24
+ if (typeof window !== 'undefined') {
25
+ // Client-side: check if we're in development
26
+ const isDev = window.location.hostname === 'localhost' ||
27
+ window.location.hostname === '127.0.0.1' ||
28
+ window.location.hostname.startsWith('192.168.');
29
+
30
+ return isDev ? 'http://localhost:8000' : 'https://blanchon-robottransportserver.hf.space/api';
31
+ }
32
+
33
+ // Server-side fallback
34
+ return 'http://localhost:8000';
35
+ }
demo/src/lib/settings.svelte.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import { getServerUrl } from './index.js';
2
+
3
+ interface Settings {
4
+ transportServerUrl: string;
5
+ }
6
+
7
+ export const settings: Settings = $state({
8
+ transportServerUrl: getServerUrl()
9
+ });
demo/src/routes/+page.svelte CHANGED
@@ -3,6 +3,8 @@
3
  import { robotics } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
5
  import { goto } from '$app/navigation';
 
 
6
 
7
  // Server status
8
  let serverStatus = $state<'checking' | 'connected' | 'error'>('checking');
@@ -29,10 +31,8 @@
29
  debugInfo.connectionAttempts++;
30
 
31
  try {
32
- // Use relative URL so it works in both development and production
33
- const baseUrl = typeof window !== 'undefined' ? window.location.origin : 'http://localhost:7860';
34
- const apiUrl = `${baseUrl}/api`;
35
- const client = new robotics.RoboticsClientCore(apiUrl);
36
  const roomList = await client.listRooms('');
37
  rooms = roomList;
38
  serverInfo = { rooms: roomList.length, version: '1.0.0' };
 
3
  import { robotics } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
5
  import { goto } from '$app/navigation';
6
+ import { settings } from '$lib/settings.svelte.js';
7
+
8
 
9
  // Server status
10
  let serverStatus = $state<'checking' | 'connected' | 'error'>('checking');
 
31
  debugInfo.connectionAttempts++;
32
 
33
  try {
34
+ // Use the configured server URL
35
+ const client = new robotics.RoboticsClientCore(settings.transportServerUrl);
 
 
36
  const roomList = await client.listRooms('');
37
  rooms = roomList;
38
  serverInfo = { rooms: roomList.length, version: '1.0.0' };
demo/src/routes/[workspaceId]/+page.svelte CHANGED
@@ -1,7 +1,9 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { robotics, video } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes, video as videoTypes } from '@robothub/transport-server-client';
 
5
 
6
  // Get data from load function
7
  let { data } = $props();
@@ -41,7 +43,7 @@
41
 
42
  // Load robotics rooms
43
  try {
44
- roboticsClient = new robotics.RoboticsClientCore('http://localhost:8000');
45
  roboticsRooms = await roboticsClient.listRooms(workspaceId);
46
  } catch (err) {
47
  roboticsError = 'Failed to load robotics rooms';
@@ -50,7 +52,7 @@
50
 
51
  // Load video rooms
52
  try {
53
- videoClient = new video.VideoClientCore('http://localhost:8000');
54
  videoRooms = await videoClient.listRooms(workspaceId);
55
  } catch (err) {
56
  videoError = 'Failed to load video rooms';
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { robotics, video } from '@robothub/transport-server-client';
5
  import type { robotics as roboticsTypes, video as videoTypes } from '@robothub/transport-server-client';
6
+
7
 
8
  // Get data from load function
9
  let { data } = $props();
 
43
 
44
  // Load robotics rooms
45
  try {
46
+ roboticsClient = new robotics.RoboticsClientCore(settings.transportServerUrl);
47
  roboticsRooms = await roboticsClient.listRooms(workspaceId);
48
  } catch (err) {
49
  roboticsError = 'Failed to load robotics rooms';
 
52
 
53
  // Load video rooms
54
  try {
55
+ videoClient = new video.VideoClientCore(settings.transportServerUrl);
56
  videoRooms = await videoClient.listRooms(workspaceId);
57
  } catch (err) {
58
  videoError = 'Failed to load video rooms';
demo/src/routes/[workspaceId]/robotics/+page.svelte CHANGED
@@ -2,6 +2,7 @@
2
  import { onMount } from 'svelte';
3
  import { robotics } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
 
5
 
6
  // Get data from load function
7
  let { data } = $props();
@@ -42,7 +43,7 @@
42
  try {
43
  loading = true;
44
  error = '';
45
- client = new robotics.RoboticsClientCore('http://localhost:8000');
46
  rooms = await client.listRooms(workspaceId);
47
  debugInfo.responseTime = Date.now() - startTime;
48
  } catch (err) {
 
2
  import { onMount } from 'svelte';
3
  import { robotics } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
5
+
6
 
7
  // Get data from load function
8
  let { data } = $props();
 
43
  try {
44
  loading = true;
45
  error = '';
46
+ client = new robotics.RoboticsClientCore(settings.transportServerUrl);
47
  rooms = await client.listRooms(workspaceId);
48
  debugInfo.responseTime = Date.now() - startTime;
49
  } catch (err) {
demo/src/routes/[workspaceId]/robotics/consumer/+page.svelte CHANGED
@@ -1,7 +1,9 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { robotics } from '@robothub/transport-server-client';
4
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
 
5
 
6
  // Get data from load function
7
  let { data } = $props();
@@ -70,7 +72,7 @@
70
  connecting = true;
71
  error = '';
72
 
73
- consumer = new robotics.RoboticsConsumer('http://localhost:8000');
74
 
75
  // Set up event handlers
76
  consumer.onConnected(() => {
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { robotics } from '@robothub/transport-server-client';
5
  import type { robotics as roboticsTypes } from '@robothub/transport-server-client';
6
+
7
 
8
  // Get data from load function
9
  let { data } = $props();
 
72
  connecting = true;
73
  error = '';
74
 
75
+ consumer = new robotics.RoboticsConsumer(settings.transportServerUrl);
76
 
77
  // Set up event handlers
78
  consumer.onConnected(() => {
demo/src/routes/[workspaceId]/robotics/producer/+page.svelte CHANGED
@@ -1,6 +1,8 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { robotics } from '@robothub/transport-server-client';
 
4
 
5
  // Get data from load function
6
  let { data } = $props();
@@ -98,7 +100,7 @@
98
  connecting = true;
99
  error = '';
100
 
101
- producer = new robotics.RoboticsProducer('http://localhost:8000');
102
 
103
  producer.onConnected(() => {
104
  connected = true;
@@ -138,7 +140,7 @@
138
  connecting = true;
139
  error = '';
140
 
141
- producer = new robotics.RoboticsProducer('http://localhost:8000');
142
 
143
  producer.onConnected(() => {
144
  connected = true;
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { robotics } from '@robothub/transport-server-client';
5
+
6
 
7
  // Get data from load function
8
  let { data } = $props();
 
100
  connecting = true;
101
  error = '';
102
 
103
+ producer = new robotics.RoboticsProducer(settings.transportServerUrl);
104
 
105
  producer.onConnected(() => {
106
  connected = true;
 
140
  connecting = true;
141
  error = '';
142
 
143
+ producer = new robotics.RoboticsProducer(settings.transportServerUrl);
144
 
145
  producer.onConnected(() => {
146
  connected = true;
demo/src/routes/[workspaceId]/video/+page.svelte CHANGED
@@ -1,7 +1,9 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { video } from '@robothub/transport-server-client';
4
  import type { video as videoTypes } from '@robothub/transport-server-client';
 
5
 
6
  // Get data from load function
7
  let { data } = $props();
@@ -42,7 +44,7 @@
42
  try {
43
  loading = true;
44
  error = '';
45
- client = new video.VideoClientCore('http://localhost:8000');
46
  rooms = await client.listRooms(workspaceId);
47
  debugInfo.responseTime = Date.now() - startTime;
48
  } catch (err) {
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { video } from '@robothub/transport-server-client';
5
  import type { video as videoTypes } from '@robothub/transport-server-client';
6
+
7
 
8
  // Get data from load function
9
  let { data } = $props();
 
44
  try {
45
  loading = true;
46
  error = '';
47
+ client = new video.VideoClientCore(settings.transportServerUrl);
48
  rooms = await client.listRooms(workspaceId);
49
  debugInfo.responseTime = Date.now() - startTime;
50
  } catch (err) {
demo/src/routes/[workspaceId]/video/consumer/+page.svelte CHANGED
@@ -1,6 +1,8 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { video } from '@robothub/transport-server-client';
 
4
 
5
  // Get data from load function
6
  let { data } = $props();
@@ -78,7 +80,7 @@
78
  connecting = true;
79
  error = '';
80
 
81
- consumer = new video.VideoConsumer('http://localhost:8000');
82
 
83
  // Set up event handlers
84
  consumer.onConnected(() => {
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { video } from '@robothub/transport-server-client';
5
+
6
 
7
  // Get data from load function
8
  let { data } = $props();
 
80
  connecting = true;
81
  error = '';
82
 
83
+ consumer = new video.VideoConsumer(settings.transportServerUrl);
84
 
85
  // Set up event handlers
86
  consumer.onConnected(() => {
demo/src/routes/[workspaceId]/video/producer/+page.svelte CHANGED
@@ -1,6 +1,8 @@
1
  <script lang="ts">
 
2
  import { onMount } from 'svelte';
3
  import { video } from '@robothub/transport-server-client';
 
4
 
5
  // Get data from load function
6
  let { data } = $props();
@@ -129,7 +131,7 @@
129
  connecting = true;
130
  error = '';
131
 
132
- producer = new video.VideoProducer('http://localhost:8000');
133
 
134
  producer.onConnected(() => {
135
  connected = true;
@@ -193,7 +195,7 @@
193
  connecting = true;
194
  error = '';
195
 
196
- producer = new video.VideoProducer('http://localhost:8000');
197
 
198
  producer.onConnected(() => {
199
  connected = true;
 
1
  <script lang="ts">
2
+ import { settings } from '$lib/settings.svelte.js';
3
  import { onMount } from 'svelte';
4
  import { video } from '@robothub/transport-server-client';
5
+
6
 
7
  // Get data from load function
8
  let { data } = $props();
 
131
  connecting = true;
132
  error = '';
133
 
134
+ producer = new video.VideoProducer(settings.transportServerUrl);
135
 
136
  producer.onConnected(() => {
137
  connected = true;
 
195
  connecting = true;
196
  error = '';
197
 
198
+ producer = new video.VideoProducer(settings.transportServerUrl);
199
 
200
  producer.onConnected(() => {
201
  connected = true;