Spaces:
Sleeping
Sleeping
File size: 3,735 Bytes
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 |
# RobotHub TransportServer JavaScript/TypeScript Client
A TypeScript/JavaScript client library for real-time robotics control and video streaming via the RobotHub TransportServer platform. Supports both browser and Node.js environments.
## π― Purpose
This client library provides **easy access** to the RobotHub TransportServer from JavaScript/TypeScript applications:
- **Robotics Control**: Send joint commands and receive robot state updates
- **Video Streaming**: Stream and receive video feeds via WebRTC
- **Multi-Workspace**: Organize connections across isolated workspaces
- **Real-time Communication**: WebSocket-based bidirectional messaging
## π¦ Installation
```bash
bun add @robothub/transport-server-client
```
## π Quick Start
### Robotics Control
```typescript
import { robotics } from '@robothub/transport-server-client';
// Producer - Send commands to robot
const producer = new robotics.RoboticsProducer('http://localhost:8000');
await producer.connect(workspaceId, roomId);
await producer.sendJointUpdate([
{ name: 'shoulder', value: 45.0 },
{ name: 'elbow', value: -30.0 }
]);
// Consumer - Receive robot state
const consumer = new robotics.RoboticsConsumer('http://localhost:8000');
await consumer.connect(workspaceId, roomId);
consumer.onJointUpdate((joints) => {
console.log('Robot moving:', joints);
});
```
### Video Streaming
```typescript
import { video } from '@robothub/transport-server-client';
// Producer - Stream video
const videoProducer = new video.VideoProducer('http://localhost:8000');
await videoProducer.connect(workspaceId, roomId);
await videoProducer.startCamera();
// Consumer - Receive video
const videoConsumer = new video.VideoConsumer('http://localhost:8000');
await videoConsumer.connect(workspaceId, roomId);
const videoElement = document.getElementById('video');
videoConsumer.attachToVideoElement(videoElement);
```
## π API Reference
### Robotics Producer
```typescript
// Connection
await producer.connect(workspaceId, roomId)
await producer.createRoom() // Auto-generates IDs
await producer.disconnect()
// Control
await producer.sendJointUpdate(joints)
await producer.sendStateSync(state)
await producer.sendEmergencyStop(reason)
```
### Robotics Consumer
```typescript
// Connection
await consumer.connect(workspaceId, roomId)
// Events
consumer.onJointUpdate(callback)
consumer.onStateSync(callback)
consumer.onError(callback)
// State
const state = await consumer.getStateSyncAsync()
```
### Video Producer
```typescript
// Streaming
await producer.startCamera(constraints)
await producer.startScreenShare()
await producer.stopStreaming()
await producer.updateVideoConfig(config)
```
### Video Consumer
```typescript
// Receiving
await consumer.startReceiving()
consumer.attachToVideoElement(videoElement)
// Events
consumer.onStreamStarted(callback)
consumer.onStreamStopped(callback)
```
## π§ Room Management
```typescript
// Create rooms and workspaces
const { workspaceId, roomId } = await producer.createRoom();
// List and manage rooms
const rooms = await producer.listRooms(workspaceId);
const roomInfo = await producer.getRoomInfo(workspaceId, roomId);
const success = await producer.deleteRoom(workspaceId, roomId);
```
## β‘ Factory Functions
Quick setup helpers:
```typescript
// Quick producer setup
const producer = await robotics.createProducerClient('http://localhost:8000');
// Quick consumer setup
const consumer = await robotics.createConsumerClient(workspaceId, roomId, 'http://localhost:8000');
```
## π οΈ Development
```bash
# Install dependencies
bun install
# Build library
bun run build
# Type checking
bun run typecheck
```
---
**Start controlling robots with JavaScript!** π€β¨
|