File size: 10,492 Bytes
8aedc84
51f51c3
8aedc84
 
 
 
1e7b565
8aedc84
 
51f51c3
8aedc84
 
 
 
 
 
 
 
 
51f51c3
8aedc84
 
 
 
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
 
 
8aedc84
51f51c3
 
 
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
8aedc84
51f51c3
 
 
 
 
8aedc84
51f51c3
 
 
 
8aedc84
51f51c3
 
 
 
8aedc84
51f51c3
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
 
51f51c3
 
 
8aedc84
51f51c3
 
 
8aedc84
 
51f51c3
8aedc84
 
51f51c3
 
 
 
 
 
8aedc84
51f51c3
 
8aedc84
51f51c3
 
 
8aedc84
 
51f51c3
 
 
8aedc84
 
 
 
 
 
 
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
 
51f51c3
8aedc84
 
51f51c3
 
 
 
 
8aedc84
 
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
 
51f51c3
8aedc84
51f51c3
8aedc84
 
 
 
 
 
 
51f51c3
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
 
 
 
 
 
 
8aedc84
51f51c3
 
 
 
 
8aedc84
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
 
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
 
 
 
 
 
 
 
8aedc84
51f51c3
8aedc84
51f51c3
 
 
 
8aedc84
51f51c3
 
 
 
8aedc84
51f51c3
 
 
8aedc84
51f51c3
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
---
title: RobotHub TransportServer
emoji: ๐Ÿค–
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 8000
suggested_hardware: cpu-upgrade
suggested_storage: small
short_description: Real-time robotics control and video streaming platform
tags:
  - robotics
  - control
  - websocket
  - fastapi
  - svelte
  - real-time
  - video-streaming
  - transport-server
  - robothub
pinned: true
fullWidth: true
---

# ๐Ÿค– RobotHub TransportServer

A high-performance, real-time communication platform for robotics control and video streaming. Built for multi-tenant environments with WebSocket and WebRTC technologies.

## ๐Ÿš€ Overview

RobotHub TransportServer enables real-time, bidirectional communication between robotics systems, cameras, and control interfaces. It provides a unified platform for:

- **Real-time robot joint control** via WebSocket connections
- **Live video streaming** via WebRTC technology  
- **Multi-workspace isolation** for secure multi-tenant deployments
- **Producer/Consumer architecture** for scalable robotics applications
- **Cross-platform client libraries** (JavaScript/TypeScript and Python)

## ๐Ÿ—๏ธ Architecture

### Core Components

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    RobotHub TransportServer                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐ŸŒ REST API          โ”‚  ๐Ÿ”Œ WebSocket          โ”‚  ๐Ÿ“น WebRTC  โ”‚
โ”‚  - Room management    โ”‚  - Real-time control   โ”‚  - Video    โ”‚
โ”‚  - Workspace control  โ”‚  - Joint updates       โ”‚  - Streamingโ”‚
โ”‚  - Status & health    โ”‚  - State sync          โ”‚  - P2P conn โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚             Multi-Workspace & Room Management               โ”‚
โ”‚  workspace_1/          workspace_2/          workspace_n/   โ”‚
โ”‚  โ”œโ”€โ”€ robotics_room_1  โ”œโ”€โ”€ robotics_room_1   โ”œโ”€โ”€ ...        โ”‚
โ”‚  โ”œโ”€โ”€ robotics_room_2  โ”œโ”€โ”€ video_room_1      โ”‚              โ”‚
โ”‚  โ””โ”€โ”€ video_room_1     โ””โ”€โ”€ video_room_2      โ”‚              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Producer/Consumer Pattern

**Robotics Control:**
- **Producer**: Sends joint commands and control signals
- **Consumer**: Receives commands and executes robot movements

**Video Streaming:**
- **Producer**: Streams camera feeds or screen content
- **Consumer**: Receives and displays video streams

## ๐Ÿ› ๏ธ Key Features

### โœ… Real-time Robotics Control
- Joint-level robot control with normalized values
- Emergency stop mechanisms
- State synchronization between multiple clients
- Support for 6-DOF robotic arms (extensible)

### โœ… WebRTC Video Streaming
- Low-latency video streaming
- Multiple camera support
- Screen sharing capabilities
- Automatic quality adaptation

### โœ… Multi-Workspace Architecture
- Complete isolation between workspaces
- UUID-based workspace identification
- Scalable room management within workspaces

### โœ… Cross-Platform Clients
- **JavaScript/TypeScript**: Browser and Node.js support
- **Python**: AsyncIO-based client for robotics applications
- Consistent API across all platforms

### โœ… Production Ready
- Docker containerization
- Health monitoring endpoints
- Comprehensive logging
- Error handling and recovery

## ๐Ÿš€ Quick Start

### Using Docker (Recommended)

```bash
# Clone the repository
git clone https://github.com/julien-blanchon/RobotHub-TransportServer
cd RobotHub-TransportServer

# Build and run with Docker
docker build -t robothub-transport-server .
docker run -p 8000:8000 robothub-transport-server
```

### Development Setup

```bash
# Install Python dependencies
cd server
uv venv
source .venv/bin/activate
uv sync
uv pip install -e .

# Start the server
uv run launch_with_ui.py

# The server will be available at:
# - API: http://localhost:8000/api
# - Demo UI: http://localhost:8000
```

## ๐Ÿ“š Client Libraries

### JavaScript/TypeScript

```bash
cd client/js
bun install
bun run build
```

```typescript
import { robotics, video } from '@robothub/transport-server-client';

// Robotics control
const producer = new robotics.RoboticsProducer('http://localhost:8000');
await producer.connect(workspaceId, roomId);
await producer.sendJointUpdate([
  { name: 'joint_1', value: 45.0 },
  { name: 'joint_2', value: -30.0 }
]);

// Video streaming
const videoProducer = new video.VideoProducer('http://localhost:8000');
await videoProducer.connect(workspaceId, roomId);
await videoProducer.startCamera();
```

### Python

```bash
cd client/python
uv venv
source .venv/bin/activate
uv sync
uv pip install -e .
```

```python
import asyncio
from transport_server_client import RoboticsProducer
from transport_server_client.video import VideoProducer

async def main():
    # Robotics control
    producer = RoboticsProducer('http://localhost:8000')
    await producer.connect(workspace_id, room_id)
    await producer.send_joint_update([
        {'name': 'joint_1', 'value': 45.0},
        {'name': 'joint_2', 'value': -30.0}
    ])
    
    # Video streaming
    video_producer = VideoProducer('http://localhost:8000')
    await video_producer.connect(workspace_id, room_id)
    await video_producer.start_camera()

asyncio.run(main())
```

## ๐ŸŽฎ Interactive Demo

The included demo application showcases all features:

```bash
cd demo
bun install
bun run dev
```

Visit `http://localhost:5173` to access:
- **Workspace Management**: Create and manage isolated environments
- **Robotics Control**: Real-time robot arm control interface
- **Video Streaming**: Camera and screen sharing demos
- **Multi-room Support**: Manage multiple concurrent sessions

## ๐Ÿ”ง API Reference

### REST Endpoints

#### Workspaces & Rooms
```
GET    /robotics/workspaces/{workspace_id}/rooms
POST   /robotics/workspaces/{workspace_id}/rooms
DELETE /robotics/workspaces/{workspace_id}/rooms/{room_id}
GET    /robotics/workspaces/{workspace_id}/rooms/{room_id}/state

GET    /video/workspaces/{workspace_id}/rooms
POST   /video/workspaces/{workspace_id}/rooms
DELETE /video/workspaces/{workspace_id}/rooms/{room_id}
```

#### WebSocket Connections
```
WS /robotics/workspaces/{workspace_id}/rooms/{room_id}/ws
WS /video/workspaces/{workspace_id}/rooms/{room_id}/ws
```

### Message Types

#### Robotics Messages
- `joint_update`: Send/receive joint position commands
- `state_sync`: Synchronize complete robot state
- `emergency_stop`: Emergency stop signal
- `heartbeat`: Connection health monitoring

#### Video Messages
- `stream_started`: Video stream initiated
- `stream_stopped`: Video stream ended  
- `webrtc_offer/answer/ice`: WebRTC signaling
- `video_config_update`: Stream configuration changes

## ๐Ÿ”Œ Integration Examples

### ML/AI Robotics Pipeline

```python
# Example: AI model controlling robot via TransportServer
import asyncio
from transport_server_client import RoboticsProducer
from transport_server_client.video import VideoConsumer

class AIRobotController:
    def __init__(self, server_url, workspace_id):
        self.robot_producer = RoboticsProducer(server_url)
        self.camera_consumer = VideoConsumer(server_url)
        self.workspace_id = workspace_id
    
    async def start_control_loop(self):
        # Connect to robot control room
        await self.robot_producer.connect(self.workspace_id, 'robot_control')
        
        # Connect to camera feed
        await self.camera_consumer.connect(self.workspace_id, 'camera_feed')
        
        # Set up frame processing
        self.camera_consumer.on_frame_update(self.process_frame)
    
    async def process_frame(self, frame_data):
        # AI inference on camera frame
        joint_commands = await self.ai_model.predict(frame_data)
        
        # Send robot commands
        await self.robot_producer.send_joint_update(joint_commands)
```

### Multi-Robot Coordination

```typescript
// Example: Coordinating multiple robots
import { robotics } from '@robothub/transport-server-client';

class MultiRobotCoordinator {
  private robots: Map<string, robotics.RoboticsProducer> = new Map();
  
  async addRobot(robotId: string, workspaceId: string, roomId: string) {
    const producer = new robotics.RoboticsProducer();
    await producer.connect(workspaceId, roomId);
    this.robots.set(robotId, producer);
  }
  
  async coordinatedMovement(positions: Map<string, JointUpdate[]>) {
    // Send synchronized commands to all robots
    const promises = Array.from(positions.entries()).map(([robotId, joints]) => {
      const producer = this.robots.get(robotId);
      return producer?.sendJointUpdate(joints);
    });
    
    await Promise.all(promises);
  }
}
```

## ๐Ÿ“ Project Structure

```
RobotHub-TransportServer/
โ”œโ”€โ”€ server/                 # FastAPI backend server
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ robotics/      # Robotics control logic
โ”‚   โ”‚   โ”œโ”€โ”€ video/         # Video streaming logic
โ”‚   โ”‚   โ””โ”€โ”€ api.py         # Main API routes
โ”‚   โ””โ”€โ”€ launch_with_ui.py  # Server launcher
โ”œโ”€โ”€ client/
โ”‚   โ”œโ”€โ”€ js/                # JavaScript/TypeScript client
โ”‚   โ””โ”€โ”€ python/            # Python client library
โ”œโ”€โ”€ demo/                  # SvelteKit demo application
โ”œโ”€โ”€ Dockerfile             # Container configuration
โ””โ”€โ”€ README.md
```

## ๐Ÿšข Deployment

### Production Docker Deployment

```bash
# Build production image
docker build -t robothub-transport-server .

# Run with custom configuration
docker run -d \
  --name robothub-transport-server \
  -p 8000:8000 \
  -e LOG_LEVEL=info \
  robothub-transport-server
```

### Development Setup

```bash
# Clone repository
git clone https://github.com/julien-blanchon/RobotHub-TransportServer
cd RobotHub-TransportServer

# Server development
cd server
uv venv && source .venv/bin/activate
uv sync

# Client development
cd client/js
bun install

# Demo development  
cd demo
bun install
```